Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created December 18, 2016 18:39
Show Gist options
  • Select an option

  • Save theburningmonk/7e17124d96c470bcb585abd4ae3b4aa9 to your computer and use it in GitHub Desktop.

Select an option

Save theburningmonk/7e17124d96c470bcb585abd4ae3b4aa9 to your computer and use it in GitHub Desktop.
Advent of Code (Day 17)
let findPaths input =
[| ((0, 0), input) |]
|> Seq.unfold (fun paths ->
paths
|> Array.filter (fun (pos, _) -> pos <> (3, 3))
|> Array.collect (fun (pos, path) ->
let hashVals = hash path |> Seq.take 4
hashVals
|> Seq.zip [| up; down; left; right |]
|> Seq.choose (fun (f, hashVal) ->
if hashVal > 'a' then f pos path else None)
|> Seq.toArray)
|> function
| [||] -> None
| next -> Some(next, next))
|> Seq.collect id
|> Seq.choose (function
| (3, 3), path -> Some <| path.Substring(input.Length)
| _ -> None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment