Day 2 Part 1
This commit is contained in:
parent
c50feb2380
commit
87b30e106f
1 changed files with 21 additions and 0 deletions
21
day2/day2part1.exs
Normal file
21
day2/day2part1.exs
Normal file
|
@ -0,0 +1,21 @@
|
|||
defmodule Day2Part1 do
|
||||
def run do
|
||||
regex = ~r/\A(\d+)-(\d+) (\w): (\w+)\z/
|
||||
|
||||
File.read!("input")
|
||||
|> String.trim()
|
||||
|> String.split("\n")
|
||||
|> Enum.map(&Regex.run(regex, &1, capture: :all_but_first))
|
||||
|> Enum.map(fn [least, most, char, password] ->
|
||||
{String.to_integer(least), String.to_integer(most), char, password}
|
||||
end)
|
||||
|> Enum.filter(fn {least, most, char, password} ->
|
||||
count = Enum.count(String.graphemes(password), &(&1 == char))
|
||||
least <= count && count <= most
|
||||
end)
|
||||
|> Enum.count()
|
||||
|> IO.puts()
|
||||
end
|
||||
end
|
||||
|
||||
Day2Part1.run()
|
Loading…
Reference in a new issue