Last active
December 6, 2017 13:44
-
-
Save shanecharles/f032433a4b07e460f0227080b5413893 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
let part1 location = | |
let rowOffset ringId limit = | |
match (location - limit) % (ringId * 2) with | |
| 0 -> ringId | |
| x when x - ringId < 0 -> (ringId - x) % ringId | |
| x -> x % ringId | |
location |> function | |
| x when x <= 1 -> 0 | |
| x -> | |
let (previousRing,limit) = rings |> Seq.takeWhile (snd >> ((>) x)) |> Seq.last | |
match previousRing + 1 with | |
| 1 -> 1 + (location % 2) | |
| ringId -> ringId + (rowOffset ringId limit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment