Created
December 7, 2015 19:20
-
-
Save plecong/7824ece75e484db76d89 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
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