Last active
December 6, 2023 21:37
-
-
Save rugyoga/48cc9c5622f208a44b909188b4c81b18 to your computer and use it in GitHub Desktop.
Advent of code 2023 Day 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AOC | |
aoc 2023, 6 do | |
def p1(input) do | |
input | |
|> parse() | |
|> Enum.map(fn l -> Enum.map(l , &String.to_integer/1) end) | |
|> Enum.zip() | |
|> Enum.map(&possibilities/1) | |
|> Enum.product() | |
end | |
def possibilities({time, record}), do: Enum.count(0..time, &(&1 * (time-&1) > record)) | |
def parse(input) do | |
input | |
|> String.split("\n") | |
|> Enum.map(&(&1 |> String.split(":") |> Enum.at(1) |> String.split(" ", trim: true))) | |
end | |
def p2(input) do | |
input | |
|> parse() | |
|> Enum.map(&(&1 |> Enum.join("") |> String.to_integer())) | |
|> then(fn [a, b] -> possibilities({a, b}) end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment