Skip to content

Instantly share code, notes, and snippets.

@shanecharles
Last active December 6, 2017 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecharles/f032433a4b07e460f0227080b5413893 to your computer and use it in GitHub Desktop.
Save shanecharles/f032433a4b07e460f0227080b5413893 to your computer and use it in GitHub Desktop.
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