···11+<!-- vim:ft=markdown -->
22+33+<!-- livebook:{"persist_outputs":true} -->
44+55+# Day 1
66+77+## Load input
88+99+```elixir
1010+stream =
1111+ File.stream!("day1.txt")
1212+ |> Stream.map(&String.to_integer(String.trim(&1)))
1313+```
1414+1515+```output
1616+#Stream<[
1717+ enum: %File.Stream{
1818+ line_or_bytes: :line,
1919+ modes: [:raw, :read_ahead, :binary],
2020+ path: "day1.txt",
2121+ raw: true
2222+ },
2323+ funs: [#Function<47.58486609/1 in Stream.map/2>]
2424+]>
2525+```
2626+2727+## Task 1
2828+2929+Compute count of consecutive increases
3030+3131+```elixir
3232+stream
3333+|> Stream.chunk_every(2, 1, :discard)
3434+|> Enum.count(fn [a, b] -> a < b end)
3535+```
3636+3737+```output
3838+1688
3939+```
4040+4141+## Task 2
4242+4343+Compute count of consecutive increases of sums of trigrams.
4444+4545+However we can notice, that if we have list like:
4646+4747+$$
4848+[a, b, c, d]
4949+$$
5050+5151+Then when we want to compare consecutive trigrams then we compare:
5252+5353+$$
5454+a + b + c < b + c + d \\
5555+a < d
5656+$$
5757+5858+So we can traverse each 4 elements and then just compare first and last one
5959+instead of summing and then traversing it again.
6060+6161+```elixir
6262+stream
6363+|> Stream.chunk_every(4, 1, :discard)
6464+|> Enum.count(fn [a, _, _, b] -> a < b end)
6565+```
6666+6767+```output
6868+1728
6969+```