Skip to content

Commit a105a7e

Browse files
committed
Day 1
1 parent f8869c4 commit a105a7e

File tree

5 files changed

+230
-28
lines changed

5 files changed

+230
-28
lines changed

aoc-template.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: c048de24b751a122b2e914acaa90bbd5e796a925ef6214118e4891baf487f88f
7+
-- hash: acf86506a195b5ea086ebc221fee6ab2028a75a75148cc50f85bdebd7856b29e
88

99
name: aoc-template
1010
version: 0.1.0.0
@@ -79,7 +79,7 @@ executable aoc-template-exe
7979
hs-source-dirs:
8080
app
8181
default-extensions: EmptyCase FlexibleContexts FlexibleInstances InstanceSigs MultiParamTypeClasses LambdaCase MultiWayIf RecordWildCards TupleSections OverloadedStrings ScopedTypeVariables GADTs NumericUnderscores DeriveFunctor DeriveFoldable
82-
ghc-options: -threaded -rtsopts -with-rtsopts=-N
82+
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
8383
build-depends:
8484
aoc-template
8585
, attoparsec

app/Main.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import qualified Days.Day25 as Day25 (runDay)
3333
import Data.Map (Map)
3434
import qualified Data.Map as Map
3535
import Data.Maybe (fromMaybe)
36-
import Options.Applicative
36+
import Options.Applicative hiding (action)
3737
import Text.Printf (printf)
3838

3939
data Days
@@ -122,8 +122,8 @@ performDay (Options d v) = case d of
122122
AllDays ->
123123
sequence_ $
124124
fmap
125-
( \(d, (a, i)) -> do
126-
putStrLn $ "\n***Day " ++ (printf "%02d" d) ++ "***"
125+
( \(day, (a, i)) -> do
126+
putStrLn $ "\n***Day " ++ (printf "%02d" day) ++ "***"
127127
a v i
128128
)
129129
(Map.toList days)

hie.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cradle:
2+
stack:
3+
- path: "./src"
4+
component: "aoc-template:lib"
5+
6+
- path: "./app/Main.hs"
7+
component: "aoc-template:exe:aoc-template-exe"
8+
9+
- path: "./app/Paths_aoc_template.hs"
10+
component: "aoc-template:exe:aoc-template-exe"
11+

input/Day01.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1833
2+
1949
3+
1745
4+
1863
5+
1422
6+
1980
7+
1695
8+
1233
9+
1407
10+
1971
11+
1486
12+
1922
13+
1802
14+
1689
15+
214
16+
1864
17+
1091
18+
1395
19+
1772
20+
1901
21+
1542
22+
1730
23+
1782
24+
1815
25+
1818
26+
1236
27+
1604
28+
1219
29+
1834
30+
1813
31+
1532
32+
1963
33+
2003
34+
1149
35+
1577
36+
1408
37+
1871
38+
1417
39+
1727
40+
1155
41+
1953
42+
1287
43+
1259
44+
1548
45+
1126
46+
1927
47+
1225
48+
1172
49+
11
50+
1301
51+
1869
52+
1808
53+
1238
54+
1989
55+
1027
56+
321
57+
1564
58+
636
59+
1847
60+
1877
61+
1716
62+
1275
63+
1738
64+
1054
65+
1966
66+
1019
67+
1256
68+
1940
69+
1821
70+
1914
71+
1556
72+
1389
73+
1020
74+
1293
75+
1935
76+
1804
77+
1945
78+
508
79+
1856
80+
1674
81+
1721
82+
1541
83+
1435
84+
1852
85+
1394
86+
2006
87+
1366
88+
1473
89+
1274
90+
623
91+
1701
92+
1842
93+
1954
94+
1999
95+
1195
96+
1246
97+
1967
98+
1153
99+
1851
100+
1294
101+
1152
102+
1812
103+
1732
104+
1030
105+
1956
106+
1132
107+
1948
108+
1865
109+
1835
110+
1231
111+
1975
112+
1759
113+
1843
114+
1379
115+
1657
116+
1267
117+
1062
118+
1850
119+
1817
120+
1543
121+
1805
122+
1252
123+
1974
124+
1161
125+
876
126+
1647
127+
1796
128+
1634
129+
1177
130+
1519
131+
1527
132+
1249
133+
1158
134+
2007
135+
1702
136+
1714
137+
1040
138+
1826
139+
1837
140+
1361
141+
1814
142+
1858
143+
1828
144+
1951
145+
1140
146+
1845
147+
1476
148+
1337
149+
1262
150+
1923
151+
1397
152+
1025
153+
1412
154+
1930
155+
1164
156+
1300
157+
1369
158+
1777
159+
1591
160+
1919
161+
1874
162+
1482
163+
2010
164+
1957
165+
1897
166+
1854
167+
1992
168+
1735
169+
1786
170+
1661
171+
1404
172+
1254
173+
1803
174+
1794
175+
1614
176+
1711
177+
1007
178+
1979
179+
1928
180+
1505
181+
2001
182+
1094
183+
2005
184+
1297
185+
1933
186+
1976
187+
1104
188+
1279
189+
1012
190+
1943
191+
1679
192+
1958
193+
1841
194+
1623
195+
1809
196+
1800
197+
919
198+
1620
199+
1936
200+
1209

src/Days/Day01.hs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
1-
module Days.Day01 (runDay) where
2-
3-
{- ORMOLU_DISABLE -}
4-
import Data.List
5-
import Data.Map.Strict (Map)
6-
import qualified Data.Map.Strict as Map
7-
import Data.Maybe
8-
import Data.Set (Set)
9-
import qualified Data.Set as Set
10-
import Data.Vector (Vector)
11-
import qualified Data.Vector as Vec
12-
import qualified Util.Util as U
13-
14-
import qualified Program.RunDay as R (runDay)
15-
import Data.Attoparsec.Text
16-
import Data.Void
17-
{- ORMOLU_ENABLE -}
1+
module Days.Day01 where
2+
3+
import Control.Applicative ( (<|>) )
4+
import Data.Maybe ( listToMaybe )
5+
import qualified Program.RunDay as R ( runDay )
6+
import Data.Attoparsec.Text
187

198
runDay :: Bool -> String -> IO ()
209
runDay = R.runDay inputParser partA partB
2110

2211
------------ PARSER ------------
2312
inputParser :: Parser Input
24-
inputParser = error "Not implemented yet!"
13+
inputParser = many' (decimal <* (endOfLine <|> endOfInput))
2514

2615
------------ TYPES ------------
27-
type Input = Void
16+
type Input = [Int]
2817

29-
type OutputA = Void
18+
type OutputA = Maybe Int
3019

31-
type OutputB = Void
20+
type OutputB = Maybe Int
3221

3322
------------ PART A ------------
3423
partA :: Input -> OutputA
35-
partA = error "Not implemented yet!"
24+
partA input =
25+
listToMaybe [x*y | x <- input, y <- input, x+y == 2020]
3626

3727
------------ PART B ------------
3828
partB :: Input -> OutputB
39-
partB = error "Not implemented yet!"
29+
partB input =
30+
listToMaybe [x*y*z | x <- input, y <- input, z <- input, x+y+z == 2020]

0 commit comments

Comments
 (0)