set up stuff; do day 1 of year 2025

nnuuvv 6430171c

+6
.gitignore
··· 1 + *.beam 2 + *.ez 3 + /build 4 + erl_crash.dump 5 + .envrc 6 + /input/
+13
README.md
··· 1 + # advent_of_code 2 + My aoc code 3 + Using gladvent 4 + 5 + 6 + 7 + ## General Workflow 8 + 9 + 1. run `gleam run -- new <target-day> --fetch=true --year=<target-year>` 10 + 2. add example data to `inputs/<target-year>/<target-day>.example.txt` 11 + 3. work on solution 12 + 4. test solution using `gleam run -- run <target-day> --example=true` 13 + 5. once it works run `gleam run -- run X`
+20
gleam.toml
··· 1 + name = "advent_of_code" 2 + version = "1.0.0" 3 + 4 + # Fill out these fields if you intend to generate HTML documentation or publish 5 + # your project to the Hex package manager. 6 + # 7 + # description = "" 8 + # licences = ["Apache-2.0"] 9 + # repository = { type = "github", user = "", repo = "" } 10 + # links = [{ title = "Website", href = "" }] 11 + # 12 + # For a full reference of all the available options, you can have a look at 13 + # https://gleam.run/writing-gleam/gleam-toml/. 14 + 15 + [dependencies] 16 + gleam_stdlib = ">= 0.44.0 and < 2.0.0" 17 + gladvent = ">= 2.2.1 and < 3.0.0" 18 + 19 + [dev-dependencies] 20 + gleeunit = ">= 1.0.0 and < 2.0.0"
+35
manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 + { name = "envoy", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "850DA9D29D2E5987735872A2B5C81035146D7FE19EFC486129E44440D03FD832" }, 7 + { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 8 + { name = "gladvent", version = "2.2.1", build_tools = ["gleam"], requirements = ["argv", "envoy", "filepath", "gleam_erlang", "gleam_http", "gleam_httpc", "gleam_json", "gleam_otp", "gleam_package_interface", "gleam_stdlib", "glint", "parallel_map", "shellout", "simplifile", "snag", "spinner", "tom"], otp_app = "gladvent", source = "hex", outer_checksum = "82DCA16931B5950EEAEFB192524E52BC16D9BDDFCEB501ADAC5094430684440F" }, 9 + { name = "gleam_community_ansi", version = "1.4.3", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_regexp", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8A62AE9CC6EA65BEA630D95016D6C07E4F9973565FA3D0DE68DC4200D8E0DD27" }, 10 + { name = "gleam_community_colour", version = "2.0.2", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "E34DD2C896AC3792151EDA939DA435FF3B69922F33415ED3C4406C932FBE9634" }, 11 + { name = "gleam_erlang", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "1124AD3AA21143E5AF0FC5CF3D9529F6DB8CA03E43A55711B60B6B7B3874375C" }, 12 + { name = "gleam_http", version = "4.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "82EA6A717C842456188C190AFB372665EA56CE13D8559BF3B1DD9E40F619EE0C" }, 13 + { name = "gleam_httpc", version = "4.1.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "C670EBD46FC1472AD5F1F74F1D3938D1D0AC1C7531895ED1D4DDCB6F07279F43" }, 14 + { name = "gleam_json", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "44FDAA8847BE8FC48CA7A1C089706BD54BADCC4C45B237A992EDDF9F2CDB2836" }, 15 + { name = "gleam_otp", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BA6A294E295E428EC1562DC1C11EA7530DCB981E8359134BEABC8493B7B2258E" }, 16 + { name = "gleam_package_interface", version = "3.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_package_interface", source = "hex", outer_checksum = "8F2D19DE9876D9401BB0626260958A6B1580BB233489C32831FE74CE0ACAE8B4" }, 17 + { name = "gleam_regexp", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "9C215C6CA84A5B35BB934A9B61A9A306EC743153BE2B0425A0D032E477B062A9" }, 18 + { name = "gleam_stdlib", version = "0.67.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "6368313DB35963DC02F677A513BB0D95D58A34ED0A9436C8116820BF94BE3511" }, 19 + { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, 20 + { name = "glearray", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "5E272F7CB278CC05A929C58DEB58F5D5AC6DB5B879A681E71138658D0061C38A" }, 21 + { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 22 + { name = "glint", version = "1.2.1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "2214C7CEFDE457CEE62140C3D4899B964E05236DA74E4243DFADF4AF29C382BB" }, 23 + { name = "parallel_map", version = "3.0.2", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib", "gleam_yielder"], otp_app = "parallel_map", source = "hex", outer_checksum = "20E8EFFECA25D6061EE81A6E7C96C05783994D9E4191482B86DB13AA5618EEFA" }, 24 + { name = "repeatedly", version = "2.1.2", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "93AE1938DDE0DC0F7034F32C1BF0D4E89ACEBA82198A1FE21F604E849DA5F589" }, 25 + { name = "shellout", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "1BDC03438FEB97A6AF3E396F4ABEB32BECF20DF2452EC9A8C0ACEB7BDDF70B14" }, 26 + { name = "simplifile", version = "2.3.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "957E0E5B75927659F1D2A1B7B75D7B9BA96FAA8D0C53EA71C4AD9CD0C6B848F6" }, 27 + { name = "snag", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "274F41D6C3ECF99F7686FDCE54183333E41D2C1CA5A3A673F9A8B2C7A4401077" }, 28 + { name = "spinner", version = "1.3.1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib", "glearray", "repeatedly"], otp_app = "spinner", source = "hex", outer_checksum = "21BDE7FF9D7D9ACBB4086C0D5C86F0A90CE6B0F3CB593B41D03384AE7724B5B4" }, 29 + { name = "tom", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0910EE688A713994515ACAF1F486A4F05752E585B9E3209D8F35A85B234C2719" }, 30 + ] 31 + 32 + [requirements] 33 + gladvent = { version = ">= 2.2.1 and < 3.0.0" } 34 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 35 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+5
src/advent_of_code.gleam
··· 1 + import gladvent 2 + 3 + pub fn main() -> Nil { 4 + gladvent.run() 5 + }
+108
src/aoc_2025/day_1.gleam
··· 1 + import gleam/int 2 + import gleam/list 3 + import gleam/string 4 + 5 + pub fn parse(input: String) -> List(Rotation) { 6 + let lines = string.split(input, "\n") 7 + list.map(lines, fn(line) { 8 + case line { 9 + "L" <> amount -> { 10 + let assert Ok(amount) = int.parse(amount) 11 + Left(amount) 12 + } 13 + "R" <> amount -> { 14 + let assert Ok(amount) = int.parse(amount) 15 + Right(amount) 16 + } 17 + _ -> { 18 + echo line 19 + panic as "Invalid input o.o" 20 + } 21 + } 22 + }) 23 + } 24 + 25 + pub type Rotation { 26 + Left(amount: Int) 27 + Right(amount: Int) 28 + } 29 + 30 + pub fn pt_1(input: List(Rotation)) { 31 + pt_1_loop(input, 50, 0) 32 + } 33 + 34 + fn pt_1_loop(input: List(Rotation), position: Int, zero_count: Int) -> Int { 35 + case input { 36 + [] -> zero_count 37 + [rotation, ..rest] -> 38 + case do_rotation_pt_1(position, rotation) { 39 + 0 -> pt_1_loop(rest, 0, zero_count + 1) 40 + otherwise -> pt_1_loop(rest, otherwise, zero_count) 41 + } 42 + } 43 + } 44 + 45 + fn do_rotation_pt_1(position: Int, rotation: Rotation) { 46 + case rotation { 47 + Left(amount:) -> position - amount 48 + Right(amount:) -> position + amount 49 + } 50 + |> handle_overflow_pt_1 51 + } 52 + 53 + fn handle_overflow_pt_1(position) { 54 + case position { 55 + _ if position > 99 -> handle_overflow_pt_1(position - 100) 56 + _ if position < 0 -> handle_overflow_pt_1(position + 100) 57 + _ -> position 58 + } 59 + } 60 + 61 + pub fn pt_2(input: List(Rotation)) { 62 + list.fold(input, #(50, 0), fn(acc, rotation) { 63 + let #(position, zeros) = acc 64 + rotate(position, rotation, zeros) 65 + }).1 66 + } 67 + 68 + fn pt_2_loop(input: List(Rotation), position: Int, zero_count: Int) -> Int { 69 + case input { 70 + [] -> zero_count 71 + [rotation, ..rest] -> { 72 + let #(position, zeros) = do_rotation_pt_2(position, rotation) 73 + pt_2_loop(rest, position, zero_count + zeros) 74 + } 75 + } 76 + } 77 + 78 + fn rotate(from position: Int, by rotation: Rotation, zeros zeros: Int) { 79 + case rotation { 80 + Left(0) -> #(position, zeros) 81 + // we're at 0; roll over to 99 82 + Left(amount:) if position == 0 -> rotate(99, Left(amount - 1), zeros) 83 + // we're at 1; next one is 0 84 + Left(amount:) if position == 1 -> rotate(0, Left(amount - 1), zeros + 1) 85 + Left(amount:) -> rotate(position - 1, Left(amount - 1), zeros) 86 + 87 + Right(0) -> #(position, zeros) 88 + // we're at 99; roll over to 0 89 + Right(amount:) if position == 99 -> rotate(0, Right(amount - 1), zeros + 1) 90 + Right(amount:) -> rotate(position + 1, Right(amount - 1), zeros) 91 + } 92 + } 93 + 94 + fn do_rotation_pt_2(position: Int, rotation: Rotation) { 95 + case rotation { 96 + Left(amount:) -> position - amount 97 + Right(amount:) -> position + amount 98 + } 99 + |> handle_overflow_pt_2(0) 100 + } 101 + 102 + fn handle_overflow_pt_2(position, zero_count) { 103 + case position { 104 + _ if position > 99 -> handle_overflow_pt_2(position - 100, zero_count + 1) 105 + _ if position < 0 -> handle_overflow_pt_2(position + 100, zero_count + 1) 106 + _ -> #(position, zero_count) 107 + } 108 + }
+13
test/advent_of_code_test.gleam
··· 1 + import gleeunit 2 + 3 + pub fn main() -> Nil { 4 + gleeunit.main() 5 + } 6 + 7 + // gleeunit test functions end in `_test` 8 + pub fn hello_world_test() { 9 + let name = "Joe" 10 + let greeting = "Hello, " <> name <> "!" 11 + 12 + assert greeting == "Hello, Joe!" 13 + }