1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|