+9
.gitignore
+9
.gitignore
-10
2015/16/sue.txt
-10
2015/16/sue.txt
+6
-1
2015/18/rust/src/main.rs
+6
-1
2015/18/rust/src/main.rs
···
1
1
use std::mem::swap;
2
2
3
-
fn generations(times: u32, mut world: Vec<u8>, size: usize, stuck: bool) -> Vec<u8> {
3
+
fn generations(
4
+
times: u32,
5
+
mut world: Vec<u8>,
6
+
size: usize,
7
+
stuck: bool,
8
+
) -> Vec<u8> {
4
9
let pos = |x, y| y * (size + 2) + x;
5
10
6
11
let sizep = size + 1;
+40
-18
2015/19/rust/src/main.rs
+40
-18
2015/19/rust/src/main.rs
···
1
-
struct Combination {
2
-
original: String,
3
-
target: String,
4
-
}
1
+
use std::collections::{HashMap, HashSet};
5
2
6
3
fn main() {
7
-
let input: String = std::fs::read_to_string("../input.txt").expect("invalid input!!");
8
-
let input: Vec<&str> = input.split("\n").collect();
9
-
let combinations: Vec<Combination> = &input[..input.len() - 2].iter().map(|v| {
10
-
let v: Vec<&str> = v.split(" ").collect();
11
-
match v[..] {
12
-
[original, _, target] => Combination {
13
-
original: original.to_string(),
14
-
target: target.to_string(),
15
-
},
16
-
_ => Combination {
17
-
original: "".to_string(),
18
-
target: "".to_string(),
19
-
},
4
+
let input = include_str!("../../input.txt");
5
+
let input: Vec<&str> = input.trim().split("\n").collect();
6
+
7
+
let combinations: HashMap<String, Vec<String>> = {
8
+
let mut combinations = HashMap::new();
9
+
input[..input.len() - 2].iter().for_each(|v| {
10
+
let v: Vec<&str> = v.split(" ").collect();
11
+
match v[..] {
12
+
[original, "=>", target] => {
13
+
let entry = combinations
14
+
.entry(original.to_string())
15
+
.or_insert(Vec::with_capacity(1));
16
+
entry.push(target.to_string());
17
+
}
18
+
_ => panic!("{:?}", v),
19
+
}
20
+
});
21
+
combinations
22
+
};
23
+
24
+
let medicine_mol = input.last().unwrap();
25
+
26
+
// part 1
27
+
{
28
+
let mol_len = medicine_mol.len();
29
+
let mut possibilities: HashSet<String> = HashSet::new();
30
+
for i in 0..mol_len {
31
+
let (a, b) = medicine_mol.split_at(i);
32
+
combinations.iter().for_each(|(from, to)| {
33
+
to.iter().for_each(|to| {
34
+
possibilities.insert(format!(
35
+
"{}{}",
36
+
a,
37
+
b.replacen(from, to, 1)
38
+
));
39
+
})
40
+
});
20
41
}
21
-
}).
42
+
println!("Part 1: {}", possibilities.len() - 1)
43
+
}
22
44
}
+2
-1
2015/2/rust/src/main.rs
+2
-1
2015/2/rust/src/main.rs
+7
2015/20/rust/Cargo.lock
+7
2015/20/rust/Cargo.lock
+6
2015/20/rust/Cargo.toml
+6
2015/20/rust/Cargo.toml
+33
2015/20/rust/src/main.rs
+33
2015/20/rust/src/main.rs
···
1
+
fn main() {
2
+
let input: u64 = include_str!("../../input.txt")
3
+
.trim()
4
+
.parse()
5
+
.expect("bad input");
6
+
let input = input / 10;
7
+
8
+
let mut highest_house = (0, 0);
9
+
let mut house: u64 = 1;
10
+
// while highest_house.1 < input {
11
+
while house < 10 {
12
+
let presents = if house % 2 == 0 {
13
+
(1..house + 1).fold(0, |acc, elf| {
14
+
if house % elf == 0 { acc + elf } else { acc }
15
+
})
16
+
} else {
17
+
(1..house.div_ceil(2) + 1).fold(0, |acc, elf| {
18
+
if house % (elf * 2) == 0 {
19
+
acc + elf
20
+
} else {
21
+
acc
22
+
}
23
+
})
24
+
};
25
+
if presents > highest_house.1 {
26
+
highest_house = (house, presents);
27
+
}
28
+
house += 1;
29
+
println!("{} {}", house, presents);
30
+
}
31
+
32
+
println!("Part 1: {:?}", highest_house);
33
+
}
+2
-1
2015/4/rust/src/main.rs
+2
-1
2015/4/rust/src/main.rs
+3
-1
2025/1/rust/src/main.rs
+3
-1
2025/1/rust/src/main.rs
···
43
43
turn,
44
44
// if it is below zero before being moduloed and the original number itself wasn't zero it means that it did touch zero but the division thing wouldn't count it, so we give this extra support.
45
45
// of course, there is no need to deal with a negative to positive situation because the acc.turn will never be negative!!!
46
-
zeroes: acc.zeroes + raw_zeroes + (acc.turn != 0 && raw_turn <= 0) as i32,
46
+
zeroes: acc.zeroes
47
+
+ raw_zeroes
48
+
+ (acc.turn != 0 && raw_turn <= 0) as i32,
47
49
}
48
50
},
49
51
);
+2
-88
2025/1/zig/build.zig
+2
-88
2025/1/zig/build.zig
···
1
1
const std = @import("std");
2
2
3
-
// Although this function looks imperative, it does not perform the build
4
-
// directly and instead it mutates the build graph (`b`) that will be then
5
-
// executed by an external runner. The functions in `std.Build` implement a DSL
6
-
// for defining build steps and express dependencies between them, allowing the
7
-
// build runner to parallelize the build automatically (and the cache system to
8
-
// know when a step doesn't need to be re-run).
9
3
pub fn build(b: *std.Build) void {
10
-
// Standard target options allow the person running `zig build` to choose
11
-
// what target to build for. Here we do not override the defaults, which
12
-
// means any target is allowed, and the default is native. Other options
13
-
// for restricting supported target set are available.
14
4
const target = b.standardTargetOptions(.{});
15
-
// Standard optimization options allow the person running `zig build` to select
16
-
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
17
-
// set a preferred release mode, allowing the user to decide how to optimize.
5
+
18
6
const optimize = b.standardOptimizeOption(.{});
19
-
// It's also possible to define more custom flags to toggle optional features
20
-
// of this build script using `b.option()`. All defined flags (including
21
-
// target and optimize options) will be listed when running `zig build --help`
22
-
// in this directory.
23
7
24
-
// This creates a module, which represents a collection of source files alongside
25
-
// some compilation options, such as optimization mode and linked system libraries.
26
-
// Zig modules are the preferred way of making Zig code available to consumers.
27
-
// addModule defines a module that we intend to make available for importing
28
-
// to our consumers. We must give it a name because a Zig package can expose
29
-
// multiple modules and consumers will need to be able to specify which
30
-
// module they want to access.
31
-
32
-
// Here we define an executable. An executable needs to have a root module
33
-
// which needs to expose a `main` function. While we could add a main function
34
-
// to the module defined above, it's sometimes preferable to split business
35
-
// logic and the CLI into two separate modules.
36
-
//
37
-
// If your goal is to create a Zig library for others to use, consider if
38
-
// it might benefit from also exposing a CLI tool. A parser library for a
39
-
// data serialization format could also bundle a CLI syntax checker, for example.
40
-
//
41
-
// If instead your goal is to create an executable, consider if users might
42
-
// be interested in also being able to embed the core functionality of your
43
-
// program in their own executable in order to avoid the overhead involved in
44
-
// subprocessing your CLI tool.
45
-
//
46
-
// If neither case applies to you, feel free to delete the declaration you
47
-
// don't need and to put everything under a single module.
48
8
const exe = b.addExecutable(.{
49
9
.name = "zig",
50
10
.root_module = b.createModule(.{
51
-
// b.createModule defines a new module just like b.addModule but,
52
-
// unlike b.addModule, it does not expose the module to consumers of
53
-
// this package, which is why in this case we don't have to give it a name.
54
11
.root_source_file = b.path("src/main.zig"),
55
-
// Target and optimization levels must be explicitly wired in when
56
-
// defining an executable or library (in the root module), and you
57
-
// can also hardcode a specific target for an executable or library
58
-
// definition if desireable (e.g. firmware for embedded devices).
12
+
59
13
.target = target,
60
14
.optimize = optimize,
61
-
// List of modules available for import in source files part of the
62
-
// root module.
63
15
}),
64
16
});
65
17
66
-
// This declares intent for the executable to be installed into the
67
-
// install prefix when running `zig build` (i.e. when executing the default
68
-
// step). By default the install prefix is `zig-out/` but can be overridden
69
-
// by passing `--prefix` or `-p`.
70
18
b.installArtifact(exe);
71
19
72
-
// This creates a top level step. Top level steps have a name and can be
73
-
// invoked by name when running `zig build` (e.g. `zig build run`).
74
-
// This will evaluate the `run` step rather than the default step.
75
-
// For a top level step to actually do something, it must depend on other
76
-
// steps (e.g. a Run step, as we will see in a moment).
77
20
const run_step = b.step("run", "Run the app");
78
21
79
-
// This creates a RunArtifact step in the build graph. A RunArtifact step
80
-
// invokes an executable compiled by Zig. Steps will only be executed by the
81
-
// runner if invoked directly by the user (in the case of top level steps)
82
-
// or if another step depends on it, so it's up to you to define when and
83
-
// how this Run step will be executed. In our case we want to run it when
84
-
// the user runs `zig build run`, so we create a dependency link.
85
22
const run_cmd = b.addRunArtifact(exe);
86
23
run_step.dependOn(&run_cmd.step);
87
24
88
-
// By making the run step depend on the default step, it will be run from the
89
-
// installation directory rather than directly from within the cache directory.
90
25
run_cmd.step.dependOn(b.getInstallStep());
91
26
92
-
// This allows the user to pass arguments to the application in the build
93
-
// command itself, like this: `zig build run -- arg1 arg2 etc`
94
27
if (b.args) |args| {
95
28
run_cmd.addArgs(args);
96
29
}
97
30
98
-
// Creates an executable that will run `test` blocks from the executable's
99
-
// root module. Note that test executables only test one module at a time,
100
-
// hence why we have to create two separate ones.
101
31
const exe_tests = b.addTest(.{
102
32
.root_module = exe.root_module,
103
33
});
104
34
105
-
// A run step that will run the second test executable.
106
35
const run_exe_tests = b.addRunArtifact(exe_tests);
107
36
108
-
// A top level step for running all tests. dependOn can be called multiple
109
-
// times and since the two run steps do not depend on one another, this will
110
-
// make the two of them run in parallel.
111
37
const test_step = b.step("test", "Run tests");
112
38
test_step.dependOn(&run_exe_tests.step);
113
-
114
-
// Just like flags, top level steps are also listed in the `--help` menu.
115
-
//
116
-
// The Zig build system is entirely implemented in userland, which means
117
-
// that it cannot hook into private compiler APIs. All compilation work
118
-
// orchestrated by the build system will result in other Zig compiler
119
-
// subcommands being invoked with the right flags defined. You can observe
120
-
// these invocations when one fails (or you pass a flag to increase
121
-
// verbosity) to validate assumptions and diagnose problems.
122
-
//
123
-
// Lastly, the Zig build system is relatively simple and self-contained,
124
-
// and reading its source code will allow you to master it.
125
39
}
+6
-4
2025/2/rust/src/main.rs
+6
-4
2025/2/rust/src/main.rs
···
23
23
})
24
24
.collect();
25
25
26
-
let powers_of_ten: Vec<u64> = (0..=MAX_LENGTH as u32).map(|i| 10_u64.pow(i)).collect();
26
+
let powers_of_ten: Vec<u64> =
27
+
(0..=MAX_LENGTH as u32).map(|i| 10_u64.pow(i)).collect();
27
28
28
29
let [invalid_part_1, invalid_part_2] = {
29
30
let mut part_1: HashSet<u64> = HashSet::new();
···
31
32
32
33
for len in 1..=MAX_LENGTH / 2 {
33
34
// 1-9, 10-99, 100-999, 100000-999999
34
-
for combination in
35
-
*powers_of_ten.get(len - 1).unwrap_or(&1)..*powers_of_ten.get(len).unwrap()
35
+
for combination in *powers_of_ten.get(len - 1).unwrap_or(&1)
36
+
..*powers_of_ten.get(len).unwrap()
36
37
{
37
38
let mut number = 0;
38
39
// 0 is just the number (9), 1 is one repetition (99)
39
40
for repeat in 0..MAX_LENGTH / len {
40
-
number += combination * powers_of_ten.get((len * repeat) as usize).unwrap();
41
+
number += combination
42
+
* powers_of_ten.get((len * repeat) as usize).unwrap();
41
43
if repeat > 0 {
42
44
part_2.insert(number);
43
45
}
+11
-6
2025/3/rust/src/main.rs
+11
-6
2025/3/rust/src/main.rs
···
4
4
input.iter().fold(0, |acc, bank| {
5
5
let bank_len = bank.len();
6
6
let (n, _) = (0..digits).rfold((0, 0), |(number, bank_index), i| {
7
-
let (loc, max) = bank[bank_index..bank_len - i].iter().enumerate().fold(
8
-
(0_usize, &0_u64),
9
-
|(maxi, max), (i, n)| {
10
-
if n > max { (i, n) } else { (maxi, max) }
11
-
},
12
-
);
7
+
let (loc, max) = bank[bank_index..bank_len - i]
8
+
.iter()
9
+
.enumerate()
10
+
// apparently the compiler is fine with reversing this and then using the standard max_by but im not. and it seems to have the same speed results. im not gonna be using tricks here ok im nice
11
+
.reduce(
12
+
|(maxi, max), (i, n)| {
13
+
if n > max { (i, n) } else { (maxi, max) }
14
+
},
15
+
)
16
+
// #yup #i'm unwrapping #idontwannausefold
17
+
.unwrap();
13
18
14
19
((number * 10) + max, bank_index + loc + 1)
15
20
});
+20
2025/4/gleam/gleam.toml
+20
2025/4/gleam/gleam.toml
···
1
+
name = "main"
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
+
simplifile = ">= 2.3.0 and < 3.0.0"
18
+
19
+
[dev-dependencies]
20
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2025/4/gleam/manifest.toml
+14
2025/4/gleam/manifest.toml
···
1
+
# This file was generated by Gleam
2
+
# You typically do not need to edit this file
3
+
4
+
packages = [
5
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
6
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
7
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
8
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
9
+
]
10
+
11
+
[requirements]
12
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
13
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
14
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+96
2025/4/gleam/src/main.gleam
+96
2025/4/gleam/src/main.gleam
···
1
+
import gleam/bit_array
2
+
import gleam/int
3
+
import gleam/io
4
+
import gleam/list
5
+
import gleam/result
6
+
import gleam/string
7
+
import simplifile as file
8
+
9
+
fn get_place(x, y, map, size) {
10
+
case
11
+
case x, y {
12
+
_, -1 | -1, _ -> <<>>
13
+
s, _ | _, s if s == size -> <<>>
14
+
15
+
_, _ -> bit_array.slice(map, y * size + x, 1) |> result.unwrap(<<>>)
16
+
}
17
+
{
18
+
<<"@">> -> 1
19
+
_ -> 0
20
+
}
21
+
}
22
+
23
+
fn part_1(map, size) {
24
+
list.range(0, bit_array.byte_size(map) - 1)
25
+
|> list.fold(0, fn(acc, pos) {
26
+
let x = pos % size
27
+
let y = pos / size
28
+
29
+
let roll = get_place(x, y, map, size)
30
+
31
+
let neighbours =
32
+
get_place(x - 1, y - 1, map, size)
33
+
+ get_place(x, y - 1, map, size)
34
+
+ get_place(x + 1, y - 1, map, size)
35
+
+ get_place(x - 1, y, map, size)
36
+
+ get_place(x + 1, y, map, size)
37
+
+ get_place(x - 1, y + 1, map, size)
38
+
+ get_place(x, y + 1, map, size)
39
+
+ get_place(x + 1, y + 1, map, size)
40
+
41
+
case roll, neighbours < 4 {
42
+
1, True -> acc + 1
43
+
_, _ -> acc
44
+
}
45
+
})
46
+
}
47
+
48
+
fn part_2(map, size, rolls) {
49
+
let #(rolls, new_map) =
50
+
list.range(0, bit_array.byte_size(map) - 1)
51
+
|> list.fold(#(rolls, <<>>), fn(acc, pos) {
52
+
let #(total, new_map) = acc
53
+
let x = pos % size
54
+
let y = pos / size
55
+
56
+
let roll = get_place(x, y, map, size)
57
+
58
+
let neighbours =
59
+
get_place(x - 1, y - 1, map, size)
60
+
+ get_place(x, y - 1, map, size)
61
+
+ get_place(x + 1, y - 1, map, size)
62
+
+ get_place(x - 1, y, map, size)
63
+
+ get_place(x + 1, y, map, size)
64
+
+ get_place(x - 1, y + 1, map, size)
65
+
+ get_place(x, y + 1, map, size)
66
+
+ get_place(x + 1, y + 1, map, size)
67
+
68
+
case roll, neighbours < 4 {
69
+
1, True -> #(total + 1, bit_array.append(new_map, <<".">>))
70
+
1, _ -> #(total, bit_array.append(new_map, <<"@">>))
71
+
_, _ -> #(total, bit_array.append(new_map, <<".">>))
72
+
}
73
+
})
74
+
75
+
case map == new_map {
76
+
True -> rolls
77
+
False -> part_2(new_map, size, rolls)
78
+
}
79
+
}
80
+
81
+
pub fn main() {
82
+
let assert Ok(input) = file.read(from: "../input.txt")
83
+
as "Input file not found"
84
+
let input =
85
+
input |> string.trim |> string.split("\n") |> list.map(fn(v) { <<v:utf8>> })
86
+
let size = list.length(input)
87
+
let input = input |> list.fold(<<>>, fn(acc, l) { bit_array.append(acc, l) })
88
+
// @ and .
89
+
90
+
part_1(input, size)
91
+
|> int.to_string
92
+
|> io.println
93
+
part_2(input, size, 0)
94
+
|> int.to_string
95
+
|> io.println
96
+
}
+7
2025/4/rust/Cargo.lock
+7
2025/4/rust/Cargo.lock
+6
2025/4/rust/Cargo.toml
+6
2025/4/rust/Cargo.toml
+106
2025/4/rust/src/main.rs
+106
2025/4/rust/src/main.rs
···
1
+
use std::{
2
+
fs::{self, File},
3
+
io::Write,
4
+
mem::swap,
5
+
};
6
+
7
+
fn to_img(warehouse: &Vec<u8>, size: usize, name: usize) {
8
+
let mut bytes: Vec<u8> = [].to_vec();
9
+
bytes.extend(format!("P5\n{size} {size}\n1\n").as_bytes());
10
+
let mut i = size + 3;
11
+
for _ in 0..size {
12
+
for _ in 0..size {
13
+
bytes.push(*warehouse.get(i).unwrap());
14
+
i += 1;
15
+
}
16
+
i += 2;
17
+
}
18
+
let mut file = File::create(format!("out/{name}.pgm")).unwrap();
19
+
file.write_all(&bytes).unwrap();
20
+
}
21
+
22
+
fn solve(
23
+
mut warehouse: Vec<u8>,
24
+
size: usize,
25
+
part_2: bool,
26
+
visualise: bool,
27
+
) -> u32 {
28
+
if visualise {
29
+
fs::create_dir_all("out").unwrap();
30
+
}
31
+
32
+
let pos = |x, y| y * (size + 2) + x;
33
+
34
+
let sizep = size + 1;
35
+
36
+
let mut new_warehouse = vec![0_u8; (size + 2).pow(2)];
37
+
38
+
let mut rolls = 0;
39
+
40
+
let mut i = 0;
41
+
loop {
42
+
for yo in 1..sizep {
43
+
let ym = yo - 1;
44
+
let yp = yo + 1;
45
+
for xo in 1..sizep {
46
+
let xm = xo - 1;
47
+
let xp = xo + 1;
48
+
49
+
unsafe {
50
+
let was = *warehouse.get_unchecked(pos(xo, yo)) == 1;
51
+
let neighbours = warehouse.get_unchecked(pos(xm, ym))
52
+
+ warehouse.get_unchecked(pos(xo, ym))
53
+
+ warehouse.get_unchecked(pos(xp, ym))
54
+
+ warehouse.get_unchecked(pos(xm, yo))
55
+
+ warehouse.get_unchecked(pos(xp, yo))
56
+
+ warehouse.get_unchecked(pos(xm, yp))
57
+
+ warehouse.get_unchecked(pos(xo, yp))
58
+
+ warehouse.get_unchecked(pos(xp, yp));
59
+
*new_warehouse.get_unchecked_mut(pos(xo, yo)) =
60
+
match (was, neighbours < 4) {
61
+
(true, true) => {
62
+
rolls += 1;
63
+
0
64
+
}
65
+
(true, false) => 1,
66
+
(_, _) => 0,
67
+
};
68
+
}
69
+
}
70
+
}
71
+
72
+
if !part_2 || warehouse == new_warehouse {
73
+
break;
74
+
}
75
+
76
+
swap(&mut warehouse, &mut new_warehouse);
77
+
i += 1;
78
+
if visualise {
79
+
to_img(&warehouse, size, i);
80
+
}
81
+
}
82
+
rolls
83
+
}
84
+
85
+
fn main() {
86
+
let input = include_str!("../../input.txt").trim();
87
+
let size = input.split_once("\n").expect("invalid input").0.len();
88
+
// reads the input but adds a line of buffer on the sides
89
+
let buffer_line = ".".repeat(size);
90
+
let input: Vec<u8> = format!("{buffer_line}\n{input}\n{buffer_line}")
91
+
.split("\n")
92
+
.map(|line| -> Vec<u8> {
93
+
format!(".{}.", line)
94
+
.chars()
95
+
.map(|v| (v == '@') as u8)
96
+
.collect()
97
+
})
98
+
.flatten()
99
+
.collect();
100
+
101
+
let part_1 = solve(input.clone(), size, false, false);
102
+
println!("Part 1: {}", part_1);
103
+
104
+
let part_2 = solve(input.clone(), size, true, true);
105
+
println!("Part 2: {}", part_2);
106
+
}
+20
2025/5/gleam/gleam.toml
+20
2025/5/gleam/gleam.toml
···
1
+
name = "main"
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
+
simplifile = ">= 2.3.0 and < 3.0.0"
18
+
19
+
[dev-dependencies]
20
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2025/5/gleam/manifest.toml
+14
2025/5/gleam/manifest.toml
···
1
+
# This file was generated by Gleam
2
+
# You typically do not need to edit this file
3
+
4
+
packages = [
5
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
6
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
7
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
8
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
9
+
]
10
+
11
+
[requirements]
12
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
13
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
14
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+117
2025/5/gleam/src/main.gleam
+117
2025/5/gleam/src/main.gleam
···
1
+
import gleam/int
2
+
import gleam/io
3
+
import gleam/list
4
+
import gleam/order.{Eq, Gt, Lt}
5
+
import gleam/set
6
+
import gleam/string
7
+
import simplifile as file
8
+
9
+
pub fn main() {
10
+
let assert Ok(input) = file.read(from: "../input.txt")
11
+
as "Input file not found"
12
+
let assert [fresh_ranges, available] =
13
+
input |> string.trim |> string.split("\n\n")
14
+
let fresh_ranges =
15
+
fresh_ranges
16
+
|> string.trim
17
+
|> string.split("\n")
18
+
// |> list.reverse
19
+
// |> list.drop(5)
20
+
// |> list.take(12)
21
+
// |> list.reverse
22
+
|> list.map(fn(i) {
23
+
let assert [from, to] = i |> string.trim |> string.split("-")
24
+
let assert Ok(from) = int.parse(from)
25
+
let assert Ok(to) = int.parse(to)
26
+
// #(from / 100_000_000, to / 100_000_000)
27
+
#(from, to)
28
+
})
29
+
let available =
30
+
available
31
+
|> string.split("\n")
32
+
|> list.map(fn(i) {
33
+
let assert Ok(id) = int.parse(i)
34
+
id
35
+
})
36
+
37
+
available
38
+
|> list.fold(0, fn(acc, i) {
39
+
acc
40
+
+ case list.any(fresh_ranges, fn(range) { i >= range.0 && i <= range.1 }) {
41
+
True -> 1
42
+
False -> 0
43
+
}
44
+
})
45
+
|> int.to_string
46
+
|> io.println
47
+
48
+
// nicer looking but idc
49
+
// |> list.filter(fn(i) {
50
+
// list.any(fresh_ranges, fn(range) { i >= range.0 && i <= range.1 })
51
+
// })
52
+
// |> list.length
53
+
54
+
// this thing crashed my computer btw im stupid
55
+
// let haha =
56
+
// fresh_ranges
57
+
// |> list.fold(set.new(), fn(acc, i) {
58
+
// list.range(i.0, i.1) |> list.fold(acc, fn(acc, i) { set.insert(acc, i) })
59
+
// })
60
+
// io.println(set.size(haha) |> int.to_string)
61
+
62
+
let base_set: set.Set(#(Int, Int)) = set.new()
63
+
fresh_ranges
64
+
|> list.fold(base_set, fn(prev_seen_ranges, range) {
65
+
let #(range, seen_ranges) =
66
+
prev_seen_ranges
67
+
|> set.fold(#(range, prev_seen_ranges), fn(acc, seen_range) {
68
+
let #(range, seen_ranges) = acc
69
+
// echo #(
70
+
// range,
71
+
// seen_range,
72
+
// int.compare(range.0, seen_range.0),
73
+
// int.compare(range.1, seen_range.1),
74
+
// int.compare(range.0, seen_range.1),
75
+
// int.compare(range.1, seen_range.0),
76
+
// )
77
+
// btw im refusing to ever do something better than this idc about your sorting and whatever this is the way shut the fuck up i spent three hours on this i will be using it
78
+
case
79
+
int.compare(range.0, seen_range.0),
80
+
int.compare(range.1, seen_range.1),
81
+
int.compare(range.0, seen_range.1),
82
+
int.compare(range.1, seen_range.0)
83
+
{
84
+
// if there's no touching
85
+
Gt, Gt, Gt, Gt | Lt, Lt, Lt, Lt -> #(range, seen_ranges)
86
+
// if it's inside of the other one
87
+
Gt, Lt, _, _ | Eq, Lt, _, _ | Gt, Eq, _, _ | Eq, Eq, _, _ -> #(
88
+
#(-1, -1),
89
+
seen_ranges,
90
+
)
91
+
// if the other one is inside it
92
+
Lt, Gt, _, _ | Eq, Gt, _, _ | Lt, Eq, _, _ -> #(
93
+
range,
94
+
set.delete(seen_ranges, seen_range),
95
+
)
96
+
// if it's touching on the left side make them touch
97
+
Lt, Lt, _, _ -> #(
98
+
#(range.0, seen_range.1),
99
+
set.delete(seen_ranges, seen_range),
100
+
)
101
+
// if it's touching on the right size make them touch
102
+
Gt, Gt, _, _ -> #(
103
+
#(seen_range.0, range.1),
104
+
set.delete(seen_ranges, seen_range),
105
+
)
106
+
}
107
+
})
108
+
109
+
case range == #(-1, -1) {
110
+
False -> seen_ranges |> set.insert(range)
111
+
True -> seen_ranges
112
+
}
113
+
})
114
+
|> set.fold(0, fn(acc, range) { acc + range.1 - range.0 + 1 })
115
+
|> int.to_string
116
+
|> io.println
117
+
}
+7
2025/5/rust/Cargo.lock
+7
2025/5/rust/Cargo.lock
+6
2025/5/rust/Cargo.toml
+6
2025/5/rust/Cargo.toml
+75
2025/5/rust/src/main.rs
+75
2025/5/rust/src/main.rs
···
1
+
use std::{
2
+
cmp::Ordering::{Equal as Eq, Greater as Gt, Less as Lt},
3
+
collections::HashSet,
4
+
};
5
+
6
+
fn main() {
7
+
let input = include_str!("../../input.txt").trim();
8
+
let (fresh_ranges, available) = input.split_once("\n\n").unwrap();
9
+
let fresh_ranges: Vec<(u64, u64)> = fresh_ranges
10
+
.split("\n")
11
+
.map(|i| {
12
+
let (a, b) = i.split_once("-").unwrap();
13
+
(a.parse().unwrap(), b.parse().unwrap())
14
+
})
15
+
.collect();
16
+
let available = available.split("\n").map(|i| {
17
+
let i: u64 = i.parse().unwrap();
18
+
i
19
+
});
20
+
21
+
let part_1 = available.fold(0, |acc, i| {
22
+
acc + fresh_ranges
23
+
.iter()
24
+
.any(|(start, end)| &i >= start && &i <= end) as u64
25
+
});
26
+
println!("Part 1: {}", part_1);
27
+
28
+
let mut seen_ranges: HashSet<(u64, u64)> =
29
+
HashSet::with_capacity(fresh_ranges.len());
30
+
fresh_ranges.iter().for_each(|range| {
31
+
let range = seen_ranges.clone().iter().try_fold(
32
+
*range,
33
+
|range: (u64, u64), seen_range: &(u64, u64)| {
34
+
// btw im refusing to ever do something better than this idc about your sorting and whatever this is the way shut the fuck up i spent three hours on this i will be using it
35
+
match (
36
+
range.0.cmp(&seen_range.0),
37
+
range.1.cmp(&seen_range.1),
38
+
range.0.cmp(&seen_range.1),
39
+
range.1.cmp(&seen_range.0),
40
+
) {
41
+
// if there's no touching
42
+
(Gt, Gt, Gt, Gt) | (Lt, Lt, Lt, Lt) => Some(range),
43
+
// if it's inside of the other one
44
+
(Gt, Lt, _, _)
45
+
| (Eq, Lt, _, _)
46
+
| (Gt, Eq, _, _)
47
+
| (Eq, Eq, _, _) => None,
48
+
// if the other one is inside it
49
+
(Lt, Gt, _, _) | (Eq, Gt, _, _) | (Lt, Eq, _, _) => {
50
+
seen_ranges.remove(seen_range);
51
+
Some(range)
52
+
}
53
+
// if it's touching on the left side make them touch
54
+
(Lt, Lt, _, _) => {
55
+
seen_ranges.remove(seen_range);
56
+
Some((range.0, seen_range.1))
57
+
}
58
+
// if it's touching on the right size make them touch
59
+
(Gt, Gt, _, _) => {
60
+
seen_ranges.remove(seen_range);
61
+
Some((seen_range.0, range.1))
62
+
}
63
+
}
64
+
},
65
+
);
66
+
67
+
if range.is_some() {
68
+
seen_ranges.insert(range.unwrap());
69
+
}
70
+
});
71
+
let part_2 = seen_ranges
72
+
.into_iter()
73
+
.fold(0, |acc, range| acc + range.1 - range.0 + 1);
74
+
println!("Part 2: {}", part_2);
75
+
}
+20
2025/6/gleam/gleam.toml
+20
2025/6/gleam/gleam.toml
···
1
+
name = "main"
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
+
simplifile = ">= 2.3.0 and < 3.0.0"
18
+
19
+
[dev-dependencies]
20
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2025/6/gleam/manifest.toml
+14
2025/6/gleam/manifest.toml
···
1
+
# This file was generated by Gleam
2
+
# You typically do not need to edit this file
3
+
4
+
packages = [
5
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
6
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
7
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
8
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
9
+
]
10
+
11
+
[requirements]
12
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
13
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
14
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+140
2025/6/gleam/src/main.gleam
+140
2025/6/gleam/src/main.gleam
···
1
+
import gleam/dict
2
+
import gleam/int
3
+
import gleam/io
4
+
import gleam/list
5
+
import gleam/result
6
+
import gleam/string
7
+
import simplifile as file
8
+
9
+
type Part2Dict =
10
+
dict.Dict(Int, Int)
11
+
12
+
type Align {
13
+
Left
14
+
Right
15
+
}
16
+
17
+
type Operation {
18
+
Sum
19
+
Mul
20
+
}
21
+
22
+
type Part2Line {
23
+
Part2Line(align: Align, op: Operation, numbers: List(String))
24
+
}
25
+
26
+
pub fn main() {
27
+
let assert Ok(input) = file.read(from: "../input.txt")
28
+
as "Input file not found"
29
+
let input = input |> string.trim
30
+
let input_pt_1 =
31
+
list.fold(list.range(1, 10), input, fn(acc, _) {
32
+
acc |> string.replace(" ", " ")
33
+
})
34
+
35
+
input_pt_1
36
+
|> string.split("\n")
37
+
|> list.map(fn(i) { string.trim(i) |> string.split(" ") })
38
+
|> list.transpose
39
+
|> list.map(fn(i) {
40
+
let i = list.reverse(i)
41
+
let assert Ok(s) = list.first(i)
42
+
let i =
43
+
list.drop(i, 1) |> list.map(fn(i) { int.parse(i) |> result.unwrap(0) })
44
+
let r = case s {
45
+
"+" -> int.sum(i)
46
+
"*" -> list.reduce(i, int.multiply) |> result.unwrap(0)
47
+
_ -> panic as "invalid"
48
+
}
49
+
r
50
+
})
51
+
|> int.sum
52
+
|> int.to_string
53
+
|> io.println
54
+
55
+
let lines =
56
+
input
57
+
|> string.split("\n")
58
+
|> list.reverse
59
+
let assert Ok(last_line) = list.first(lines)
60
+
let #(_, bounds) =
61
+
{ last_line <> " *" }
62
+
|> string.to_graphemes
63
+
|> list.index_fold(#(0, list.new()), fn(acc, char, i) {
64
+
let #(bound_start, bounds) = acc
65
+
case char {
66
+
"*" | "+" if i > 0 -> #(i, list.append([#(bound_start, i - 1)], bounds))
67
+
_ -> acc
68
+
}
69
+
})
70
+
bounds
71
+
|> list.index_fold(dict.new(), fn(d, bound, i) {
72
+
let numbers =
73
+
list.map(lines, fn(line) {
74
+
string.slice(line, bound.0, bound.1 - bound.0)
75
+
})
76
+
let align =
77
+
numbers
78
+
|> list.drop(1)
79
+
|> list.fold_until(Left, fn(res, number) {
80
+
case
81
+
string.trim(number) == number,
82
+
string.trim_start(number) == number
83
+
{
84
+
True, _ -> list.Continue(res)
85
+
_, True -> list.Stop(Left)
86
+
_, _ -> list.Stop(Right)
87
+
}
88
+
})
89
+
let assert Ok(sign) = list.first(numbers)
90
+
let sign = case string.trim(sign) {
91
+
"*" -> Mul
92
+
"+" -> Sum
93
+
_ -> panic as sign
94
+
}
95
+
dict.insert(
96
+
d,
97
+
i,
98
+
Part2Line(
99
+
align,
100
+
sign,
101
+
numbers |> list.drop(1) |> list.map(string.trim) |> list.reverse,
102
+
),
103
+
)
104
+
})
105
+
|> dict.to_list
106
+
|> list.map(fn(i) { i.1 })
107
+
|> list.map(fn(line) {
108
+
let d: Part2Dict = dict.new()
109
+
let d =
110
+
line.numbers
111
+
|> list.fold(d, fn(d, number) {
112
+
let number_len = string.length(number)
113
+
string.to_graphemes(number)
114
+
|> list.index_fold(d, fn(d, digit, index) {
115
+
let assert Ok(digit) = digit |> int.parse
116
+
let pos = case line.align {
117
+
Right -> number_len - index
118
+
Left -> index
119
+
}
120
+
dict.insert(
121
+
d,
122
+
pos,
123
+
{ dict.get(d, pos) |> result.unwrap(0) } * 10 + digit,
124
+
)
125
+
})
126
+
})
127
+
let numbers =
128
+
dict.to_list(d)
129
+
|> list.map(fn(n) { n.1 })
130
+
131
+
let r = case line.op {
132
+
Sum -> int.sum(numbers)
133
+
Mul -> list.reduce(numbers, int.multiply) |> result.unwrap(0)
134
+
}
135
+
r
136
+
})
137
+
|> int.sum
138
+
|> int.to_string
139
+
|> io.println
140
+
}
+20
2025/7/gleam/gleam.toml
+20
2025/7/gleam/gleam.toml
···
1
+
name = "main"
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
+
simplifile = ">= 2.3.0 and < 3.0.0"
18
+
19
+
[dev-dependencies]
20
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2025/7/gleam/manifest.toml
+14
2025/7/gleam/manifest.toml
···
1
+
# This file was generated by Gleam
2
+
# You typically do not need to edit this file
3
+
4
+
packages = [
5
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
6
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
7
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
8
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
9
+
]
10
+
11
+
[requirements]
12
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
13
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
14
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+93
2025/7/gleam/src/main.gleam
+93
2025/7/gleam/src/main.gleam
···
1
+
import gleam/dict
2
+
import gleam/int
3
+
import gleam/io
4
+
import gleam/list
5
+
import gleam/set
6
+
import gleam/string
7
+
import simplifile as file
8
+
9
+
pub fn main() {
10
+
let assert Ok(input) = file.read(from: "../input.txt")
11
+
as "Input file not found"
12
+
let input = input |> string.trim |> string.split("\n")
13
+
let assert Ok(start) = input |> list.first
14
+
let start =
15
+
start
16
+
|> string.to_graphemes
17
+
|> list.index_fold(0, fn(acc, v, i) {
18
+
case v {
19
+
"S" -> i
20
+
_ -> acc
21
+
}
22
+
})
23
+
let splitters_map =
24
+
input
25
+
|> list.drop(1)
26
+
|> list.index_map(fn(line, i) {
27
+
case i % 2 {
28
+
0 -> ""
29
+
_ -> line
30
+
}
31
+
})
32
+
|> list.filter(fn(line) { line != "" })
33
+
|> list.map(fn(line) {
34
+
line
35
+
|> string.to_graphemes
36
+
|> list.index_fold(set.new(), fn(d, char, i) {
37
+
case char {
38
+
"^" -> set.insert(d, i)
39
+
_ -> d
40
+
}
41
+
})
42
+
})
43
+
let #(_beams, times) =
44
+
splitters_map
45
+
|> list.fold(#(set.new() |> set.insert(start), 0), fn(acc, splitters) {
46
+
let #(beams, times) = acc
47
+
beams
48
+
|> set.fold(#(beams, times), fn(acc, beam) {
49
+
let #(beams, times) = acc
50
+
case splitters |> set.contains(beam) {
51
+
False -> acc
52
+
True -> #(
53
+
beams
54
+
|> set.delete(beam)
55
+
|> set.insert(beam - 1)
56
+
|> set.insert(beam + 1),
57
+
times + 1,
58
+
)
59
+
}
60
+
})
61
+
})
62
+
63
+
times
64
+
|> int.to_string
65
+
|> io.println
66
+
67
+
let timelines =
68
+
splitters_map
69
+
|> list.index_fold(
70
+
dict.new() |> dict.insert("", start),
71
+
fn(timelines, splitters, i) {
72
+
echo i
73
+
// echo #(timelines, splitters)
74
+
timelines
75
+
|> dict.fold(timelines, fn(timelines, timeline, beam) {
76
+
case splitters |> set.contains(beam) {
77
+
False -> timelines
78
+
True -> {
79
+
timelines
80
+
|> dict.delete(timeline)
81
+
|> dict.insert(timeline <> "-", beam - 1)
82
+
|> dict.insert(timeline <> "+", beam + 1)
83
+
}
84
+
}
85
+
})
86
+
},
87
+
)
88
+
echo timelines
89
+
timelines
90
+
|> dict.size
91
+
|> int.to_string
92
+
|> io.println
93
+
}
+7
2025/7/rust/Cargo.lock
+7
2025/7/rust/Cargo.lock
+6
2025/7/rust/Cargo.toml
+6
2025/7/rust/Cargo.toml
+62
2025/7/rust/src/main.rs
+62
2025/7/rust/src/main.rs
···
1
+
use std::{
2
+
collections::{HashMap, HashSet},
3
+
mem::swap,
4
+
};
5
+
6
+
fn main() {
7
+
let input = include_str!("../../input.txt").trim();
8
+
9
+
let input: Vec<&str> = input.trim().split("\n").collect();
10
+
// let width = input[0].len() as u64;
11
+
let start = input[0].find("S").unwrap() as u64;
12
+
let splitters_map: Vec<HashSet<u64>> = input[0..input.len()]
13
+
.iter()
14
+
.enumerate()
15
+
.map(|(i, line)| if i % 2 != 0 { "" } else { line })
16
+
.filter(|line| line != &"")
17
+
.map(|line| {
18
+
line.chars()
19
+
.enumerate()
20
+
.fold(HashSet::new(), |mut s, (i, char)| {
21
+
if char == '^' {
22
+
s.insert(i as u64);
23
+
}
24
+
s
25
+
})
26
+
})
27
+
.collect();
28
+
29
+
let timelines = {
30
+
let mut timelines: HashMap<u64, u64> = HashMap::new();
31
+
timelines.insert(start, 1);
32
+
let mut timelines_new: HashMap<u64, u64> = HashMap::new();
33
+
for splitters in splitters_map {
34
+
for (pos, amount) in &timelines {
35
+
if splitters.contains(&pos) {
36
+
let m1 = timelines_new.entry(pos - 1).or_insert(0);
37
+
*m1 += amount;
38
+
let p1 = timelines_new.entry(pos + 1).or_insert(0);
39
+
*p1 += amount;
40
+
} else {
41
+
let e = timelines_new.entry(*pos).or_insert(0);
42
+
*e += amount;
43
+
}
44
+
}
45
+
// for pos in 0..width as u64 {
46
+
// if splitters.contains(&pos) {
47
+
// print!("^");
48
+
// } else if timelines_new.contains_key(&pos) {
49
+
// print!("|");
50
+
// } else {
51
+
// print!(".");
52
+
// }
53
+
// }
54
+
// print!("\n\n");
55
+
swap(&mut timelines, &mut timelines_new);
56
+
timelines_new.clear();
57
+
}
58
+
timelines
59
+
};
60
+
// println!("{:?}", timelines);
61
+
println!("{}", timelines.iter().fold(0, |acc, v| { acc + v.1 }))
62
+
}
+1
-1
template/rust/src/main.rs
+1
-1
template/rust/src/main.rs
+2
-88
template/zig/build.zig
+2
-88
template/zig/build.zig
···
1
1
const std = @import("std");
2
2
3
-
// Although this function looks imperative, it does not perform the build
4
-
// directly and instead it mutates the build graph (`b`) that will be then
5
-
// executed by an external runner. The functions in `std.Build` implement a DSL
6
-
// for defining build steps and express dependencies between them, allowing the
7
-
// build runner to parallelize the build automatically (and the cache system to
8
-
// know when a step doesn't need to be re-run).
9
3
pub fn build(b: *std.Build) void {
10
-
// Standard target options allow the person running `zig build` to choose
11
-
// what target to build for. Here we do not override the defaults, which
12
-
// means any target is allowed, and the default is native. Other options
13
-
// for restricting supported target set are available.
14
4
const target = b.standardTargetOptions(.{});
15
-
// Standard optimization options allow the person running `zig build` to select
16
-
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
17
-
// set a preferred release mode, allowing the user to decide how to optimize.
5
+
18
6
const optimize = b.standardOptimizeOption(.{});
19
-
// It's also possible to define more custom flags to toggle optional features
20
-
// of this build script using `b.option()`. All defined flags (including
21
-
// target and optimize options) will be listed when running `zig build --help`
22
-
// in this directory.
23
7
24
-
// This creates a module, which represents a collection of source files alongside
25
-
// some compilation options, such as optimization mode and linked system libraries.
26
-
// Zig modules are the preferred way of making Zig code available to consumers.
27
-
// addModule defines a module that we intend to make available for importing
28
-
// to our consumers. We must give it a name because a Zig package can expose
29
-
// multiple modules and consumers will need to be able to specify which
30
-
// module they want to access.
31
-
32
-
// Here we define an executable. An executable needs to have a root module
33
-
// which needs to expose a `main` function. While we could add a main function
34
-
// to the module defined above, it's sometimes preferable to split business
35
-
// logic and the CLI into two separate modules.
36
-
//
37
-
// If your goal is to create a Zig library for others to use, consider if
38
-
// it might benefit from also exposing a CLI tool. A parser library for a
39
-
// data serialization format could also bundle a CLI syntax checker, for example.
40
-
//
41
-
// If instead your goal is to create an executable, consider if users might
42
-
// be interested in also being able to embed the core functionality of your
43
-
// program in their own executable in order to avoid the overhead involved in
44
-
// subprocessing your CLI tool.
45
-
//
46
-
// If neither case applies to you, feel free to delete the declaration you
47
-
// don't need and to put everything under a single module.
48
8
const exe = b.addExecutable(.{
49
9
.name = "zig",
50
10
.root_module = b.createModule(.{
51
-
// b.createModule defines a new module just like b.addModule but,
52
-
// unlike b.addModule, it does not expose the module to consumers of
53
-
// this package, which is why in this case we don't have to give it a name.
54
11
.root_source_file = b.path("src/main.zig"),
55
-
// Target and optimization levels must be explicitly wired in when
56
-
// defining an executable or library (in the root module), and you
57
-
// can also hardcode a specific target for an executable or library
58
-
// definition if desireable (e.g. firmware for embedded devices).
12
+
59
13
.target = target,
60
14
.optimize = optimize,
61
-
// List of modules available for import in source files part of the
62
-
// root module.
63
15
}),
64
16
});
65
17
66
-
// This declares intent for the executable to be installed into the
67
-
// install prefix when running `zig build` (i.e. when executing the default
68
-
// step). By default the install prefix is `zig-out/` but can be overridden
69
-
// by passing `--prefix` or `-p`.
70
18
b.installArtifact(exe);
71
19
72
-
// This creates a top level step. Top level steps have a name and can be
73
-
// invoked by name when running `zig build` (e.g. `zig build run`).
74
-
// This will evaluate the `run` step rather than the default step.
75
-
// For a top level step to actually do something, it must depend on other
76
-
// steps (e.g. a Run step, as we will see in a moment).
77
20
const run_step = b.step("run", "Run the app");
78
21
79
-
// This creates a RunArtifact step in the build graph. A RunArtifact step
80
-
// invokes an executable compiled by Zig. Steps will only be executed by the
81
-
// runner if invoked directly by the user (in the case of top level steps)
82
-
// or if another step depends on it, so it's up to you to define when and
83
-
// how this Run step will be executed. In our case we want to run it when
84
-
// the user runs `zig build run`, so we create a dependency link.
85
22
const run_cmd = b.addRunArtifact(exe);
86
23
run_step.dependOn(&run_cmd.step);
87
24
88
-
// By making the run step depend on the default step, it will be run from the
89
-
// installation directory rather than directly from within the cache directory.
90
25
run_cmd.step.dependOn(b.getInstallStep());
91
26
92
-
// This allows the user to pass arguments to the application in the build
93
-
// command itself, like this: `zig build run -- arg1 arg2 etc`
94
27
if (b.args) |args| {
95
28
run_cmd.addArgs(args);
96
29
}
97
30
98
-
// Creates an executable that will run `test` blocks from the executable's
99
-
// root module. Note that test executables only test one module at a time,
100
-
// hence why we have to create two separate ones.
101
31
const exe_tests = b.addTest(.{
102
32
.root_module = exe.root_module,
103
33
});
104
34
105
-
// A run step that will run the second test executable.
106
35
const run_exe_tests = b.addRunArtifact(exe_tests);
107
36
108
-
// A top level step for running all tests. dependOn can be called multiple
109
-
// times and since the two run steps do not depend on one another, this will
110
-
// make the two of them run in parallel.
111
37
const test_step = b.step("test", "Run tests");
112
38
test_step.dependOn(&run_exe_tests.step);
113
-
114
-
// Just like flags, top level steps are also listed in the `--help` menu.
115
-
//
116
-
// The Zig build system is entirely implemented in userland, which means
117
-
// that it cannot hook into private compiler APIs. All compilation work
118
-
// orchestrated by the build system will result in other Zig compiler
119
-
// subcommands being invoked with the right flags defined. You can observe
120
-
// these invocations when one fails (or you pass a flag to increase
121
-
// verbosity) to validate assumptions and diagnose problems.
122
-
//
123
-
// Lastly, the Zig build system is relatively simple and self-contained,
124
-
// and reading its source code will allow you to master it.
125
39
}