diff --git a/gleam.toml b/gleam.toml index 0dcc80e..ea628b8 100644 --- a/gleam.toml +++ b/gleam.toml @@ -11,6 +11,7 @@ allow_read = ["gleam.toml", "./src", "./test", "./build"] gleam_stdlib = ">= 0.44.0 and < 1.0.0" argv = ">= 1.0.2 and < 2.0.0" simplifile = ">= 2.3.1 and < 3.0.0" +gleam_yielder = ">= 1.1.0 and < 2.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index 8d061d2..1732e2a 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,12 +5,14 @@ packages = [ { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, { name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" }, + { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, { name = "simplifile", version = "2.3.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "957E0E5B75927659F1D2A1B7B75D7B9BA96FAA8D0C53EA71C4AD9CD0C6B848F6" }, ] [requirements] argv = { version = ">= 1.0.2 and < 2.0.0" } -gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } +gleam_stdlib = { version = ">= 0.44.0 and < 1.0.0" } +gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } simplifile = { version = ">= 2.3.1 and < 3.0.0" } diff --git a/src/gloat.gleam b/src/gloat.gleam index 4fc1873..014949d 100644 --- a/src/gloat.gleam +++ b/src/gloat.gleam @@ -30,7 +30,7 @@ fn display( ) -> Nil { case simplifile.read(filepath) { Ok(content) -> { - io.println("Results for 2024 Day 1:") + io.println("Results for " <> filepath <> ":") io.println("Part one: " <> one(content) |> int.to_string()) io.println("Part two: " <> two(content) |> int.to_string()) } diff --git a/src/solve_2024_02.gleam b/src/solve_2024_02.gleam index 25ee7de..41a048a 100644 --- a/src/solve_2024_02.gleam +++ b/src/solve_2024_02.gleam @@ -2,6 +2,7 @@ import gleam/int import gleam/list import gleam/order import gleam/string +import gleam/yielder pub fn part_one(input: String) -> Int { input @@ -13,13 +14,13 @@ pub fn part_two(input: String) -> Int { input |> parse |> list.count(fn(report) { - [ - report, - ..list.flat_map(report, fn(_) { - list.index_map(report, fn(_, index) { drop_from_list(report, index) }) - }) - ] - |> list.any(safe_report) + yielder.unfold(list.length(report), fn(index) { + case index { + -1 -> yielder.Done + _ -> yielder.Next(drop_from_list(report, index), index - 1) + } + }) + |> yielder.any(safe_report) }) }