Skip to content

Commit

Permalink
import 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Nov 11, 2024
1 parent 5ef2a45 commit 4570d1d
Show file tree
Hide file tree
Showing 8 changed files with 4,182 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 2021/01/01.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
lines = File.stream!("input.txt")
|> Stream.map(&String.trim/1)
|> Stream.map(&String.to_integer/1)
|> Enum.to_list

# Part 1
count = lines
|> Enum.chunk_every(2, 1, :discard)
|> Enum.count(fn [a, b] -> a < b end)

IO.puts("Part 1: #{count}")

# Part 2
count = lines
|> Enum.chunk_every(3, 1, :discard)
|> Enum.map(&Enum.sum/1)
|> Enum.chunk_every(2, 1, :discard)
|> Enum.count(fn [a, b] -> a < b end)

IO.puts("Part 2: #{count}")
Loading

0 comments on commit 4570d1d

Please sign in to comment.