Algorithm which resolves square tiling problem