summaryrefslogtreecommitdiff
path: root/2017
diff options
context:
space:
mode:
Diffstat (limited to '2017')
-rw-r--r--2017/1.hs12
-rw-r--r--2017/1.in1
-rw-r--r--2017/2.hs13
-rw-r--r--2017/2.in16
4 files changed, 42 insertions, 0 deletions
diff --git a/2017/1.hs b/2017/1.hs
new file mode 100644
index 0000000..884e00e
--- /dev/null
+++ b/2017/1.hs
@@ -0,0 +1,12 @@
+import Control.Monad
+import Data.Char
+
+main :: IO ()
+main = do
+ input <- liftM (filter isDigit) $ readFile "1.in"
+
+ print $ sum $ map (\(a,b) -> read [a] * fromEnum (a == b)) $
+ zip input (tail (cycle input))
+
+ print $ sum $ map (\(a,b) -> read [a] * fromEnum (a == b)) $
+ zip input (drop (length input `div` 2) (cycle input))
diff --git a/2017/1.in b/2017/1.in
new file mode 100644
index 0000000..9081efc
--- /dev/null
+++ b/2017/1.in
@@ -0,0 +1 @@
+7385764686251444473997915123782972536343732657517834671759462795461213782428342931896181695578996274321317419242359534783957372932953774336338118488967172727651862498838195317654289797558683458511126996217953322817229372373455862177844478443391835484591525235651863464891177927244954925827786799436536592561374269299474738321293575385899438446558569241236278779779983587912431395475244796538888373287186921647426866237756737342731976763959499149996315591584716122199183295277439872911371313924594486766479438544417416529743495114819825984524437367225234184772617942525954961136976875325182725754768372684531972614455134523596338355374444273522115362238734383164778129376628621497662965456761631796178353599629887665939521892447361219479646483978798392716119793282717739524897385958273726776318154977675546287789874265339688753977185129334929715486381875286278528247696464162297691698154712775589541945263574897266575996455547625537947927972497979333932115165151462742216327321116291372396585618664475715321298122335789262942284571328414569375464386446824882551918843185195829547373915482687534432942778312542752798313434628498295216692646713137244198123219531693559848915834623825919191532658735422176965451741869666714874158492556445954852299161868651448123825821775363219246244515946392686275545561989355573946924767442253465342753995764791927951158771231944177692469531494559697911176613943396258141822244578457498361352381518166587583342233816989329544415621127397996723997397219676486966684729653763525768655324443991129862129181215339947555257279592921258246646215764736698583211625887436176149251356452358211458343439374688341116529726972434697324734525114192229641464227986582845477741747787673588848439713619326889624326944553386782821633538775371915973899959295232927996742218926514374168947582441892731462993481877277714436887597223871881149693228928442427611664655772333471893735932419937832937953495929514837663883938416644387342825836673733778119481514427512453357628396666791547531814844176342696362416842993761919369994779897357348334197721735231299249116477
diff --git a/2017/2.hs b/2017/2.hs
new file mode 100644
index 0000000..47ff161
--- /dev/null
+++ b/2017/2.hs
@@ -0,0 +1,13 @@
+import Control.Monad
+
+main :: IO ()
+main = do
+ input <- liftM (map (map read . words) . lines) (readFile "2.in") :: IO [[Int]]
+
+ print $ sum [maximum l - minimum l | l <- input]
+
+ let f = fst . head .
+ filter ((/=1) . fst) . filter ((==0) . snd) .
+ concat . concatMap (\(a,b) -> [map (a `divMod`) b, map (`divMod` a) b]) .
+ (\l -> zip l (repeat l))
+ print $ sum $ map f input
diff --git a/2017/2.in b/2017/2.in
new file mode 100644
index 0000000..ae1a5ca
--- /dev/null
+++ b/2017/2.in
@@ -0,0 +1,16 @@
+414 382 1515 319 83 1327 116 391 101 749 1388 1046 1427 105 1341 1590
+960 930 192 147 932 621 1139 198 865 820 597 165 232 417 19 183
+3379 987 190 3844 1245 1503 3151 3349 2844 4033 175 3625 3565 179 3938 184
+116 51 32 155 102 92 65 42 48 91 74 69 52 89 20 143
+221 781 819 121 821 839 95 117 626 127 559 803 779 543 44 369
+199 2556 93 1101 122 124 2714 625 2432 1839 2700 2636 118 2306 1616 2799
+56 804 52 881 1409 47 246 1368 1371 583 49 1352 976 400 1276 1240
+1189 73 148 1089 93 76 3205 3440 3627 92 853 95 3314 3551 2929 3626
+702 169 492 167 712 488 357 414 187 278 87 150 19 818 178 686
+140 2220 1961 1014 2204 2173 1513 2225 443 123 148 580 833 1473 137 245
+662 213 1234 199 1353 1358 1408 235 917 1395 1347 194 565 179 768 650
+119 137 1908 1324 1085 661 1557 1661 1828 1865 432 110 658 821 1740 145
+1594 222 4140 963 209 2782 180 2591 4390 244 4328 3748 4535 192 157 3817
+334 275 395 128 347 118 353 281 430 156 312 386 160 194 63 141
+146 1116 153 815 2212 2070 599 3018 2640 47 125 2292 165 2348 2694 184
+1704 2194 1753 146 2063 1668 1280 615 163 190 2269 1856 150 158 2250 2459