This commit is contained in:
bluepython508
2023-12-06 08:21:43 +00:00
parent 683522ddc0
commit abbd8a263a
4 changed files with 42 additions and 1 deletions

37
lib/day6.ex Normal file
View File

@@ -0,0 +1,37 @@
defmodule Aoc2023.Day6 do
use Aoc2023
def parse(input) do
input
|> lines
|> Enum.map(pipe(
String.split(":")
|> Enum.at(1)
))
end
def part1(input) do
input
|> Enum.map(pipe(
String.split()
|> Enum.map(&String.to_integer/1)
))
|> Enum.zip()
|> Enum.map(fn {time, dist} ->
1..time
|> Enum.map(&(&1 * (time - &1)))
|> Enum.filter(&(&1 > dist))
|> length
end)
|> Enum.product()
end
def part2(input) do
[time, dist] = input
|> Enum.map(pipe(String.replace(~r(\s+), "") |> String.to_integer()))
1..(time)
|> Stream.map(&(&1 * (time - &1)))
|> Stream.filter(&(&1 > dist))
|> Enum.count
end
end

View File

@@ -7,6 +7,7 @@ defmodule Mix.Tasks.Aoc do
defp module(3), do: Aoc2023.Day3 defp module(3), do: Aoc2023.Day3
defp module(4), do: Aoc2023.Day4 defp module(4), do: Aoc2023.Day4
defp module(5), do: Aoc2023.Day5 defp module(5), do: Aoc2023.Day5
defp module(6), do: Aoc2023.Day6
# [MODULE INSERTION POINT] # [MODULE INSERTION POINT]
defp base_dir(), do: System.get_env("AOC_BASE") defp base_dir(), do: System.get_env("AOC_BASE")

2
tests/day6/1 Normal file
View File

@@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

1
tests/day6/1.1 Normal file
View File

@@ -0,0 +1 @@
288