From 48e35ad3b0b0c62f936784e4aca70b17c3b0e3f9 Mon Sep 17 00:00:00 2001 From: Hunky Jimpjorps Date: Fri, 2 Feb 2024 17:05:12 -0500 Subject: renaming --- aoc2023/src/day6/.gitignore | 1 - aoc2023/src/day6/solve.gleam | 85 -------------------------------------------- 2 files changed, 86 deletions(-) delete mode 100644 aoc2023/src/day6/.gitignore delete mode 100644 aoc2023/src/day6/solve.gleam (limited to 'aoc2023/src/day6') diff --git a/aoc2023/src/day6/.gitignore b/aoc2023/src/day6/.gitignore deleted file mode 100644 index ae40cea..0000000 --- a/aoc2023/src/day6/.gitignore +++ /dev/null @@ -1 +0,0 @@ -input.txt \ No newline at end of file diff --git a/aoc2023/src/day6/solve.gleam b/aoc2023/src/day6/solve.gleam deleted file mode 100644 index 88044c4..0000000 --- a/aoc2023/src/day6/solve.gleam +++ /dev/null @@ -1,85 +0,0 @@ -import adglent.{First, Second} -import gleam/io -import gleam/string -import gleam/int -import gleam/list -import gleam/result - -type Race { - Race(time: Int, distance: Int) -} - -fn parse_with_bad_kerning(input: String) { - input - |> string.split("\n") - |> list.map(fn(str) { - str - |> string.split(" ") - |> list.map(int.parse) - |> result.values - }) - |> list.transpose - |> list.map(fn(ns) { - let assert [t, d] = ns - Race(t, d) - }) -} - -fn find_bound(race: Race, button_time: Int, step: Int) { - let travel_time = race.time - button_time - case button_time * travel_time > race.distance { - True -> button_time - False -> find_bound(race, button_time + step, step) - } -} - -fn lower_bound(race: Race) { - find_bound(race, 1, 1) -} - -fn upper_bound(race: Race) { - find_bound(race, race.time, -1) -} - -pub fn part1(input: String) { - { - use acc, race <- list.fold(parse_with_bad_kerning(input), 1) - acc * { upper_bound(race) - lower_bound(race) + 1 } - } - |> string.inspect -} - -fn parse_properly(input: String) { - input - |> string.replace(" ", "") - |> string.split("\n") - |> list.flat_map(string.split(_, ":")) - |> list.map(int.parse) - |> result.values -} - -pub fn part2(input: String) { - let assert [time, distance] = - input - |> parse_properly - - let race = Race(time, distance) - - upper_bound(race) - lower_bound(race) + 1 - |> string.inspect -} - -pub fn main() { - let assert Ok(part) = adglent.get_part() - let assert Ok(input) = adglent.get_input("6") - case part { - First -> - part1(input) - |> adglent.inspect - |> io.println - Second -> - part2(input) - |> adglent.inspect - |> io.println - } -} -- cgit v1.2.3 From 96a3c5c179d8d3fff24eb2953e45f8dd15e2714c Mon Sep 17 00:00:00 2001 From: HJ Date: Sat, 3 Feb 2024 15:09:54 -0500 Subject: cleanup --- aoc2023/src/day6/input.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 aoc2023/src/day6/input.txt (limited to 'aoc2023/src/day6') diff --git a/aoc2023/src/day6/input.txt b/aoc2023/src/day6/input.txt new file mode 100644 index 0000000..1026e3a --- /dev/null +++ b/aoc2023/src/day6/input.txt @@ -0,0 +1,2 @@ +Time: 41 66 72 66 +Distance: 244 1047 1228 1040 \ No newline at end of file -- cgit v1.2.3 From 0c869b2782aeecb92dff232b46a499a3821f9f2c Mon Sep 17 00:00:00 2001 From: HJ Date: Sat, 3 Feb 2024 15:10:00 -0500 Subject: cleanup --- aoc2023/src/day6/input.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 aoc2023/src/day6/input.txt (limited to 'aoc2023/src/day6') diff --git a/aoc2023/src/day6/input.txt b/aoc2023/src/day6/input.txt deleted file mode 100644 index 1026e3a..0000000 --- a/aoc2023/src/day6/input.txt +++ /dev/null @@ -1,2 +0,0 @@ -Time: 41 66 72 66 -Distance: 244 1047 1228 1040 \ No newline at end of file -- cgit v1.2.3