Skip to content

Commit fb0117e

Browse files
committed
more notes on day 1
1 parent d5d7ca3 commit fb0117e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
## Day 1:
44

55
The `windows` function from last year (day 9) ended up being useful already!
6+
It bothers me a little that I have two very similar functions, though, `pairs`
7+
differing from `windows 2` only in its result being a list of tuples instead of
8+
a list of lists:
9+
10+
```haskell
11+
pairs :: [a] -> [(a,a)]
12+
pairs xs@(_:xs') = zip xs xs'
13+
14+
windows :: Int -> [a] -> [[a]]
15+
windows m = foldr (zipWith (:)) (repeat []) . take m . tails
16+
```
17+
18+
I could write a filtering function to work on the first two list items, but
19+
tuples' ability to use `uncurry :: (a -> b -> c) -> (a, b) -> c` is cool, and
20+
sticking with a 2-element data structure seems like the better thing to do.
621

722

823
## Day 2:

0 commit comments

Comments
 (0)