diff options
author | Brian Chu <brianmchu42@gmail.com> | 2022-12-01 21:47:36 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2022-12-01 21:47:36 -0800 |
commit | 399d44ddfd2c5050959fcdb6e88e1cfecf55f2b6 (patch) | |
tree | 8a441882eaa29e250ce6b7425703c77779612426 /solutions | |
parent | 217582a34d4c47c5b0bc6e137e6019f2485b741f (diff) | |
download | AdventOfCode2022-399d44ddfd2c5050959fcdb6e88e1cfecf55f2b6.tar.gz |
solution for day 2
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 |