diff options
Diffstat (limited to 'solutions')
-rw-r--r-- | solutions/day2.fs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/solutions/day2.fs b/solutions/day2.fs new file mode 100644 index 0000000..5822d00 --- /dev/null +++ b/solutions/day2.fs @@ -0,0 +1,31 @@ +namespace Solutions + +module Day2 = + open System.IO + let lines = File.ReadLines("inputs/day2.txt") |> Seq.map (fun x -> x[0], x[2]) + + let outcomes1 = Map.empty + .Add(('A', 'X'), 4) // rock: 1 + tie: 3 + .Add(('A', 'Y'), 8) // paper: 2 + rock win: 6 + .Add(('A', 'Z'), 3) // scissors: 3 + rock lose: 0 + .Add(('B', 'X'), 1) // rock: 1 + paper lose: 0 + .Add(('B', 'Y'), 5) // paper: 2 + tie: 3 + .Add(('B', 'Z'), 9) // scissors: 3 + paper win: 6 + .Add(('C', 'X'), 7) // rock: 1 + scissors win: 6 + .Add(('C', 'Y'), 2) // paper: 2 + scissors lose: 0 + .Add(('C', 'Z'), 6) // scissors: 3 + tie: 3 + + let part1 () = lines |> Seq.map outcomes1.TryFind |> Seq.map (function | Some value -> value | None -> 0) |> Seq.sum + + let outcomes2 = Map.empty + .Add(('A', 'X'), 3) // lose to rock: 0 pts + 3 for scissors + .Add(('A', 'Y'), 4) // draw to rock: 3 pts + 1 for rock + .Add(('A', 'Z'), 8) // win to rock: 6 pts + 2 for paper + .Add(('B', 'X'), 1) // lose to paper: 0 pts + 1 for rock + .Add(('B', 'Y'), 5) // draw to paper: 3 pts + 2 for paper + .Add(('B', 'Z'), 9) // win to paper: 6 pts + 3 for scissors + .Add(('C', 'X'), 2) // lose to scissors: 0 pts + 2 for paper + .Add(('C', 'Y'), 6) // draw to scissors: 3 pts + 3 for scissors + .Add(('C', 'Z'), 7) // win to scissors: 6 pts + 1 for rock + + let part2 () = lines |> Seq.map outcomes2.TryFind |> Seq.map (function | Some value -> value | None -> 0) |> Seq.sum |