This commit is contained in:
Misaka Mikoto 2020-12-02 14:06:06 +02:00
commit 5b353b68a8
4 changed files with 1221 additions and 0 deletions

200
2020/1 Normal file
View File

@ -0,0 +1,200 @@
1975
1600
113
1773
1782
1680
1386
1682
1991
1640
1760
1236
1159
1259
1279
1739
1826
1888
1072
416
1632
1656
1273
1631
1079
1807
1292
1128
1841
1915
1619
1230
1950
1627
1966
774
1425
1983
1616
1633
1559
1925
960
1407
1708
1211
1666
1910
1960
1125
1242
1884
1829
1881
1585
1731
1753
1784
1095
1267
1756
1226
1107
1664
1710
2000
1181
1997
1607
1889
1613
1859
1479
1763
1692
1967
522
1719
1816
1714
1331
1976
1160
1899
1906
1783
1061
2006
1993
1717
2009
1563
1733
1866
1651
1437
1517
1113
1743
1240
1629
1868
1912
1296
1873
1673
1996
1814
1215
1927
1956
1970
1887
1702
1495
1754
1621
1055
1538
1693
1840
1685
1752
1933
1727
1648
1792
1734
1305
1446
1764
1890
1904
1560
1698
1645
1214
1516
1064
1729
1835
1642
1932
1683
962
1081
1943
1502
1622
196
1972
1916
1850
1205
1971
1937
1575
1401
1351
2005
1917
1670
1388
1051
1941
1751
1169
510
217
1948
1120
1635
1636
1511
1691
1589
1410
1902
1572
1871
1423
1114
1806
1282
1193
1974
388
1398
1992
1263
1786
1723
1206
1363
1177
1646
1231
1140
1088
1322

5
2020/1.hs Normal file
View File

@ -0,0 +1,5 @@
main = readFile "1" >>= putStrLn . show . f . g . map (\x -> read x :: Integer) . lines
where f (x:_, y:_) | x + y == 2020 = x * y
f (x:xs, _:ys) = f (x:xs, ys)
f (_:xs, []) = f $ g xs
g (x:xs) = (x:xs, xs)

1000
2020/2 Normal file

File diff suppressed because it is too large Load Diff

16
2020/2.hs Normal file
View File

@ -0,0 +1,16 @@
import Data.Char
data Entry = MkEntry { min :: Integer
, max :: Integer
, chr :: Char
, pass :: String
}
count x = length . filter ((==) x)
main = readFile "2" >>= putStrLn . show . length . filter (parse 0 0) . lines
where valid min max chr pass = let x = count chr pass
in
x >= min && x <= max
parse min tmpnum ('-':xs) = parse tmpnum 0 xs
parse min tmpnum (' ':x:':':' ':xs) = valid min tmpnum x xs
parse min tmpnum (x:xs) = parse min (tmpnum * 10 + digitToInt x) xs