Skip to content

Commit 8aaf8f2

Browse files
committed
Add the AZ entry
1 parent 53932f6 commit 8aaf8f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

05.eli5.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- An ELI5-ish (for 5 year old Haskell programmers, though if they are five year
2+
-- old and programming in Haskell, they might be able to explain me a thing or
3+
-- two) explanation of the most interesting, and the scariest, part of the
4+
-- solution to Day 5 Part 2 - calculating the splits.
5+
6+
type Range = (Int, Int)
7+
8+
splits :: Range -> Range -> [Range]
9+
splits (s, e) (s', e')
10+
| s > e' = [(s, e)]
11+
| e < s' = [(s, e)]
12+
| s < s' = (s, s' - 1) : if e <= e' then [(s', e)] else [(s', e'), (e' + 1, e)]
13+
| s <= e' = if e <= e' then [(s, e)] else [(s, e'), (e' + 1, e)]
14+
15+
main :: IO ()
16+
main = do
17+
print $ splits (1, 9) (10, 20)
18+
print $ splits (1, 9) (7, 20)
19+
print $ splits (1, 7) (7, 20)

0 commit comments

Comments
 (0)