Browse Source

first day

Getty Ritter 1 year ago
commit
6a669a0dda
5 changed files with 259 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 4 0
      01/dune
  3. 1 0
      01/dune-project
  4. 200 0
      01/input
  5. 52 0
      01/main.ml

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+*.merlin
+_build

+ 4 - 0
01/dune

@@ -0,0 +1,4 @@
+;; This declares the hello_world executable implemented by hello_world.ml
+(executable
+ (name main)
+ (libraries base))

+ 1 - 0
01/dune-project

@@ -0,0 +1 @@
+(lang dune 2.6)

+ 200 - 0
01/input

@@ -0,0 +1,200 @@
+1293
+1207
+1623
+1675
+1842
+1410
+85
+1108
+557
+1217
+1506
+1956
+1579
+1614
+1360
+1544
+1946
+1666
+1972
+1814
+1699
+1778
+1529
+2002
+1768
+1173
+1407
+1201
+1264
+1739
+1774
+1951
+1980
+1428
+1381
+1714
+884
+1939
+1295
+1694
+1168
+1971
+1352
+1462
+1828
+1402
+1433
+1542
+1144
+1331
+1427
+1261
+1663
+1820
+1570
+1874
+1486
+1613
+1769
+1721
+1753
+1142
+1677
+2010
+1640
+1465
+1171
+534
+1790
+2005
+1604
+1891
+1247
+1281
+1867
+1403
+2004
+1668
+1416
+2001
+1359
+686
+1965
+1728
+1551
+1565
+1128
+1832
+1757
+1350
+1808
+1711
+1799
+1590
+1989
+1547
+1140
+1905
+1368
+1179
+1902
+1473
+1908
+1859
+1257
+1394
+1244
+1800
+1695
+1731
+1474
+1781
+1885
+1154
+1990
+1929
+1193
+1302
+1831
+1226
+1418
+1400
+1435
+1645
+1655
+1843
+1227
+1481
+1754
+1290
+1685
+1498
+71
+1286
+1137
+1288
+1758
+1987
+1471
+1839
+1545
+1682
+1615
+1475
+1849
+1985
+1568
+1795
+1184
+1863
+1362
+1271
+1802
+1944
+1821
+1880
+1788
+1733
+1150
+1314
+1727
+1434
+1833
+1312
+1457
+160
+1629
+1967
+1505
+1239
+1266
+1838
+1687
+1630
+1591
+1893
+1450
+1234
+1755
+1523
+1533
+1499
+1865
+1725
+1444
+1517
+1167
+1738
+1519
+1263
+1901
+1627
+1644
+1771
+1812
+1270
+1497
+1707
+1708
+1396

+ 52 - 0
01/main.ml

@@ -0,0 +1,52 @@
+let sample_list = [
+    1721;
+    979;
+    366;
+    299;
+    675;
+    1456;
+]
+
+let load_list filename =
+  let lines = ref [] in
+  let f = open_in filename in
+  try
+    while true
+    do
+      lines := int_of_string (input_line f) :: !lines
+    done; !lines
+  with End_of_file ->
+        close_in f;
+        List.rev !lines
+
+
+let (>>=) list fn = let _ = List.map fn list in None
+
+let part_one source =
+  let res = Base.With_return.with_return (fun r ->
+    source >>= fun a ->
+    source >>= fun b ->
+      if a != b && a + b == 2020 then r.return (Some (a, b))
+    ) in
+  match res with
+  | None -> Printf.printf "Unable to find result\n"
+  | Some (x, y) -> Printf.printf "Got (%d * %d) = %d\n" x y (x * y)
+
+let part_two source =
+  let res = Base.With_return.with_return (fun r ->
+    source >>= fun a ->
+    source >>= fun b ->
+    source >>= fun c ->
+      if a != b && b != c && a != c && a + b + c == 2020 then r.return (Some (a, b, c))
+    ) in
+  match res with
+  | None -> Printf.printf "Unable to find result\n"
+  | Some (x, y, z) ->
+     Printf.printf "Got (%d * %d * %d) = %d\n" x y z (x * y * z)
+
+let main() =
+  let source = load_list "input" in
+  part_one source;
+  part_two source
+
+let () = main()