summary refs log tree commit diff stats
path: root/solutions/day2.fs
diff options
context:
space:
mode:
Diffstat (limited to 'solutions/day2.fs')
-rw-r--r--solutions/day2.fs31
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
'n163' href='#n163'>163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263