Last active
April 8, 2018 01:34
-
-
Save calebporzio/1e8c442a72e79a488f4d049c8dddab5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$number = 361527; | |
$bottomRoot = floor(sqrt($number)); | |
// Skip even numbers because they aren't corners. | |
if ($bottomRoot % 2 == 0) { | |
$bottomRoot = $bottomRoot-1; | |
} | |
$bottomSquare = $bottomRoot * $bottomRoot; | |
$topSquare = ($bottomRoot + 2) * ($bottomRoot + 2); | |
$topRoot = sqrt($topSquare); | |
$verticalOffset = (($bottomRoot - 1) / 2) + 1; | |
$pointer = ($number - $bottomSquare); | |
$height = $topRoot - 1; | |
$middle = $height / 2; | |
$horizontalOffset = ($pointer % $height) - $middle; | |
return $horizontalOffset + $verticalOffset; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment