File tree Expand file tree Collapse file tree 4 files changed +40
-8
lines changed Expand file tree Collapse file tree 4 files changed +40
-8
lines changed Original file line number Diff line number Diff line change
1
+ * .sh eol =lf
Original file line number Diff line number Diff line change 1
- # 2024
2
-
3
- ## Day 1 – Awk
4
-
5
- ``` console
6
- $ awk -f day01-01.awk < input1
7
- $ awk -f day01-02.awk < input1
8
- ```
1
+ # 2024
2
+
3
+ ## Day 1 – Awk
4
+
5
+ ``` console
6
+ $ awk -f day01-01.awk < input1
7
+ $ awk -f day01-02.awk < input1
8
+ ```
9
+
10
+ ## Day 2 – Haskell
11
+
12
+ ``` console
13
+ $ runhaskell day02-01.hs < input2
14
+ $ runhaskell day02-02.hs < input2
15
+ ```
Original file line number Diff line number Diff line change
1
+ isValid :: [Int ] -> Bool
2
+ isValid levels = safe levels || safe (reverse levels)
3
+ where
4
+ safe = all (\ x -> x >= 1 && x <= 3 ) . deltas
5
+ deltas l = zipWith (-) l (tail l)
6
+
7
+ main = do
8
+ reports <- map (map read ) . map words . lines <$> getContents
9
+ let validReports = filter isValid reports
10
+ print (length validReports)
Original file line number Diff line number Diff line change
1
+ isValid :: [Int ] -> Bool
2
+ isValid levels = safe levels || safe (reverse levels)
3
+ where
4
+ safe = all (\ x -> x >= 1 && x <= 3 ) . deltas
5
+ deltas l = zipWith (-) l (tail l)
6
+
7
+ drop1 :: [a ] -> [[a ]]
8
+ drop1 [] = []
9
+ drop1 (x: xs) = xs : map (x: ) (drop1 xs)
10
+
11
+ main = do
12
+ reports <- map (map read ) . map words . lines <$> getContents
13
+ let validReports = filter (any isValid . drop1) reports
14
+ print (length validReports)
You can’t perform that action at this time.
0 commit comments