this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Init 2025

+211
+5
.gitignore
··· 1 + *.beam 2 + *.ez 3 + /build 4 + erl_crash.dump 5 + inputs/
+23
README.md
··· 1 + # Advent of Code 2024 - Gleam 2 + 3 + My take at the 2024 advent of code in the [Gleam](https://github.com/gleam-lang/gleam) programming language 4 + 5 + ## Requirements 6 + - Gleam 7 + 8 + ## Usage 9 + 10 + Put your AOC inputs into an `inputs` folder at the `pwd` of the program. 11 + 12 + The file must be named following the syntax `day{number}.txt` where `{number}` should be replaced by the day number, ie : `day7.txt` `day24.txt` 13 + 14 + ```bash 15 + $ gleam run 16 + What day do you wanna run ? 17 + # Enter the day you wanna run in the prompt 18 + ``` 19 + 20 + ## Extending 21 + There is an `src/days/day.gleam` file that exist, this file is used as a template for all other day files. 22 + 23 + After greating a file, for example `day10.gleam`, you must add it to the `src/aoc.gleam` in the case statement, for it to be launchable with the CLI.
+16
gleam.toml
··· 1 + name = "aoc" 2 + author = "Evann (Estym) Regnault" 3 + version = "1.0.0" 4 + 5 + [dependencies] 6 + simplifile = ">= 2.2.0 and < 3.0.0" 7 + gleam_erlang = ">= 0.27.0 and < 1.0.0" 8 + gleam_stdlib = ">= 0.40.0 and < 1.0.0" 9 + nibble = ">= 1.1.1 and < 2.0.0" 10 + gleam_otp = ">= 0.12.1 and < 1.0.0" 11 + birl = ">= 1.7.1 and < 2.0.0" 12 + gleam_regexp = ">= 1.0.0 and < 2.0.0" 13 + 14 + [dev-dependencies] 15 + gleeunit = ">= 1.0.0 and < 2.0.0" 16 +
+25
manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" }, 6 + { name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" }, 7 + { name = "gleam_erlang", version = "0.32.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "B18643083A0117AC5CFD0C1AEEBE5469071895ECFA426DCC26517A07F6AD9948" }, 8 + { name = "gleam_otp", version = "0.14.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5A8CE8DBD01C29403390A7BD5C0A63D26F865C83173CF9708E6E827E53159C65" }, 9 + { name = "gleam_regexp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "A3655FDD288571E90EE9C4009B719FEF59FA16AFCDF3952A76A125AF23CF1592" }, 10 + { name = "gleam_stdlib", version = "0.45.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "206FCE1A76974AECFC55AEBCD0217D59EDE4E408C016E2CFCCC8FF51278F186E" }, 11 + { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, 12 + { name = "nibble", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "nibble", source = "hex", outer_checksum = "67C6BEBC1AB6D771AB893B4A7B3E66C92668C6E7774C335FEFCD545B06435FE5" }, 13 + { name = "ranger", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "B8F3AFF23A3A5B5D9526B8D18E7C43A7DFD3902B151B97EC65397FE29192B695" }, 14 + { name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, 15 + ] 16 + 17 + [requirements] 18 + birl = { version = ">= 1.7.1 and < 2.0.0" } 19 + gleam_erlang = { version = ">= 0.27.0 and < 1.0.0" } 20 + gleam_otp = { version = ">= 0.12.1 and < 1.0.0" } 21 + gleam_regexp = { version = ">= 1.0.0 and < 2.0.0" } 22 + gleam_stdlib = { version = ">= 0.40.0 and < 1.0.0" } 23 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 24 + nibble = { version = ">= 1.1.1 and < 2.0.0" } 25 + simplifile = { version = ">= 2.2.0 and < 3.0.0" }
+28
src/aoc.gleam
··· 1 + import birl 2 + import birl/duration 3 + import gleam/erlang 4 + import gleam/int 5 + import gleam/io 6 + import gleam/result 7 + import gleam/string 8 + 9 + pub fn main() { 10 + erlang.get_line("What day do you wanna run ? ") 11 + |> result.unwrap("") 12 + |> string.trim() 13 + |> int.parse() 14 + |> result.unwrap(0) 15 + |> run_day() 16 + } 17 + 18 + pub fn run_day(day: Int) { 19 + let start = birl.now() 20 + case day { 21 + 0 -> io.println_error("Invalid day") 22 + _ -> io.println("Tried to run day " <> int.to_string(day)) 23 + } 24 + birl.now() 25 + |> birl.difference(start) 26 + |> duration.accurate_decompose 27 + |> io.debug 28 + }
+24
src/days/day.gleam
··· 1 + import gleam/io 2 + import simplifile 3 + 4 + pub fn start() -> Nil { 5 + let assert Ok(content) = simplifile.read("inputs/day{number}.txt") 6 + let data = parse(content) 7 + 8 + let _ = io.debug(part1(data)) 9 + let _ = io.debug(part2(data)) 10 + 11 + Nil 12 + } 13 + 14 + fn parse(_data: String) { 15 + Nil 16 + } 17 + 18 + fn part1(_data) { 19 + Nil 20 + } 21 + 22 + fn part2(_data) { 23 + Nil 24 + }
+90
src/utils/utils.gleam
··· 1 + import gleam/int 2 + import gleam/list 3 + import gleam/result 4 + import gleam/string 5 + 6 + // Gets a char at an index 7 + pub fn get_char_at_index(str: String, idx: Int) -> String { 8 + let assert Ok(char) = 9 + str 10 + |> string.to_graphemes 11 + |> list_get_at(idx) 12 + 13 + char 14 + } 15 + 16 + // Gets item at index in a list 17 + pub fn list_get_at(list: List(a), index: Int) -> Result(a, String) { 18 + case index { 19 + 0 -> { 20 + case list { 21 + [x, ..] -> Ok(x) 22 + _ -> Error("Overflowing index") 23 + } 24 + } 25 + _ -> { 26 + case list { 27 + [_, ..y] -> list_get_at(y, index - 1) 28 + _ -> Error("Overflowing index") 29 + } 30 + } 31 + } 32 + } 33 + 34 + // Sets value at an index in a list 35 + pub fn list_set_at( 36 + liste: List(a), 37 + index: Int, 38 + value: a, 39 + ) -> Result(List(a), String) { 40 + let #(head, tail) = 41 + liste 42 + |> list.split(index) 43 + 44 + let popped = list.pop(tail, fn(_) { True }) 45 + 46 + case popped { 47 + Error(_) -> Error("Index Overflow") 48 + Ok(new_head) -> Ok(list.flatten([head, [value], new_head.1])) 49 + } 50 + } 51 + 52 + // Creates a loop, somehow 53 + pub fn loop( 54 + value: a, 55 + condition: fn(a) -> Bool, 56 + post: fn(a) -> a, 57 + body: fn(a) -> b, 58 + ) { 59 + let res = body(value) 60 + let new_value = post(value) 61 + case condition(new_value) { 62 + False -> res 63 + True -> loop(new_value, condition, post, body) 64 + } 65 + } 66 + 67 + pub fn create_int_range(start: Int, end: Int) -> List(Int) { 68 + loop( 69 + [start], 70 + fn(lst) { list.last(lst) |> result.unwrap(0) < end }, 71 + fn(lst) { 72 + list.append(lst, [list.last(lst) |> result.unwrap(0) |> int.add(1)]) 73 + }, 74 + fn(lst) { lst }, 75 + ) 76 + } 77 + 78 + // Find indexes of items in a list that satisfies a predicate 79 + pub fn list_find_indexes(liste: List(a), predicate: fn(a) -> Bool) -> List(Int) { 80 + let range = create_int_range(0, list.length(liste)) 81 + 82 + range 83 + |> list.map(fn(idx) { 84 + let assert Ok(val) = list_get_at(liste, idx) 85 + 86 + #(idx, predicate(val)) 87 + }) 88 + |> list.filter(fn(x) { x.1 == True }) 89 + |> list.map(fn(x) { x.0 }) 90 + }