Skip to content

Instantly share code, notes, and snippets.

@plecong
Created December 7, 2015 19:20
Show Gist options
  • Save plecong/7824ece75e484db76d89 to your computer and use it in GitHub Desktop.
Save plecong/7824ece75e484db76d89 to your computer and use it in GitHub Desktop.
open System
open System.IO
let getHouses directions =
directions
|> Seq.map (fun x ->
match x with
| '>' -> (fun (x: int, y: int) -> (x + 1, y))
| '<' -> (fun (x: int, y: int) -> (x - 1, y))
| '^' -> (fun (x: int, y: int) -> (x, y + 1))
| 'v' -> (fun (x: int, y: int) -> (x, y - 1))
| _ -> (fun (x: int, y: int) -> (x, y))
)
|> Seq.fold (fun l move -> move(l.Head) :: l) [(0, 0)]
let splitList list = Array.foldBack (fun x (l,r) -> x::r, l) list ([],[])
let input = File.ReadAllText("AdventOfCode_Day3_input.txt").ToCharArray()
let part1 =
input
|> getHouses
|> Seq.distinct
|> Seq.length
let part2 =
input
|> splitList
|> (fun t ->
let l, r = t
[ l; r ]
)
|> Seq.map getHouses
|> Seq.concat
|> Seq.distinct
|> Seq.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment