Skip to content

Commit 10c9558

Browse files
authored
Merge pull request #3 from connorslade/dev
Update daily solution definition format
2 parents 347b95e + 3919b1e commit 10c9558

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2107
-2311
lines changed

Cargo.lock

Lines changed: 569 additions & 315 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ name = "advent_of_code"
44
version = "0.1.0"
55

66
[workspace]
7-
members = ["scaffold", "common", "aoc_lib", "aoc_2021", "aoc_2022", "aoc_2023"]
7+
members = [
8+
"scaffold",
9+
"common",
10+
"aoc_lib",
11+
"aoc_2021",
12+
"aoc_2022",
13+
"aoc_2023",
14+
"aoc_2024",
15+
]
816

917
[dependencies]
1018
common = { path = "common" }
1119
aoc_2021 = { path = "aoc_2021" }
1220
aoc_2022 = { path = "aoc_2022" }
1321
aoc_2023 = { path = "aoc_2023" }
22+
aoc_2024 = { path = "aoc_2024" }
1423

1524
clap = { version = "4.0.29", features = ["derive"] }
1625
chrono = "0.4.31"

aoc_2021/src/day_01.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

3-
pub struct Day01;
3+
solution!("Sonar Sweep", 1);
44

5-
impl Solution for Day01 {
6-
fn name(&self) -> &'static str {
7-
"Sonar Sweep"
8-
}
5+
fn part_a(input: &str) -> Answer {
6+
let data = input
7+
.lines()
8+
.map(|x| x.parse::<u32>().unwrap())
9+
.collect::<Vec<u32>>();
910

10-
fn part_a(&self, input: &str) -> Answer {
11-
let data = input
12-
.lines()
13-
.map(|x| x.parse::<u32>().unwrap())
14-
.collect::<Vec<u32>>();
15-
16-
data.windows(2).filter(|x| x[0] < x[1]).count().into()
17-
}
11+
data.windows(2).filter(|x| x[0] < x[1]).count().into()
12+
}
1813

19-
fn part_b(&self, input: &str) -> Answer {
20-
let d = input
21-
.lines()
22-
.map(|x| x.parse::<u32>().unwrap())
23-
.collect::<Vec<u32>>();
14+
fn part_b(input: &str) -> Answer {
15+
let d = input
16+
.lines()
17+
.map(|x| x.parse::<u32>().unwrap())
18+
.collect::<Vec<u32>>();
2419

25-
d.windows(4).filter(|x| x[2] > x[0]).count().into()
26-
}
20+
d.windows(4).filter(|x| x[2] > x[0]).count().into()
2721
}

aoc_2021/src/day_02.rs

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

3-
pub struct Day02;
3+
solution!("Dive!", 2);
44

5-
impl Solution for Day02 {
6-
fn name(&self) -> &'static str {
7-
"Dive!"
8-
}
9-
10-
fn part_a(&self, input: &str) -> Answer {
11-
let mut dep: u32 = 0;
12-
let mut hor: u32 = 0;
5+
fn part_a(input: &str) -> Answer {
6+
let mut dep: u32 = 0;
7+
let mut hor: u32 = 0;
138

14-
for i in input.lines() {
15-
let seg = i.split(' ').collect::<Vec<&str>>();
16-
let x = seg[1].parse::<u32>().unwrap();
9+
for i in input.lines() {
10+
let seg = i.split(' ').collect::<Vec<&str>>();
11+
let x = seg[1].parse::<u32>().unwrap();
1712

18-
match seg[0] {
19-
"forward" => hor += x,
20-
"up" => dep -= x,
21-
"down" => dep += x,
22-
_ => {}
23-
}
13+
match seg[0] {
14+
"forward" => hor += x,
15+
"up" => dep -= x,
16+
"down" => dep += x,
17+
_ => {}
2418
}
25-
26-
(dep * hor).into()
2719
}
2820

29-
fn part_b(&self, input: &str) -> Answer {
30-
let mut dep: u32 = 0;
31-
let mut hor: u32 = 0;
32-
let mut aim: u32 = 0;
33-
34-
for i in input.lines() {
35-
let seg = i.split(' ').collect::<Vec<&str>>();
36-
let x = seg[1].parse::<u32>().unwrap();
37-
38-
match seg[0] {
39-
"forward" => {
40-
hor += x;
41-
dep += aim * x;
42-
}
43-
"up" => aim -= x,
44-
"down" => aim += x,
45-
_ => {}
21+
(dep * hor).into()
22+
}
23+
24+
fn part_b(input: &str) -> Answer {
25+
let mut dep: u32 = 0;
26+
let mut hor: u32 = 0;
27+
let mut aim: u32 = 0;
28+
29+
for i in input.lines() {
30+
let seg = i.split(' ').collect::<Vec<&str>>();
31+
let x = seg[1].parse::<u32>().unwrap();
32+
33+
match seg[0] {
34+
"forward" => {
35+
hor += x;
36+
dep += aim * x;
4637
}
38+
"up" => aim -= x,
39+
"down" => aim += x,
40+
_ => {}
4741
}
48-
49-
(dep * hor).into()
5042
}
43+
44+
(dep * hor).into()
5145
}

aoc_2021/src/day_03.rs

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,67 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

3-
pub struct Day03;
3+
solution!("Binary Diagnostic", 3);
44

5-
impl Solution for Day03 {
6-
fn name(&self) -> &'static str {
7-
"Binary Diagnostic"
8-
}
5+
fn part_a(input: &str) -> Answer {
6+
let num_len = input.lines().next().unwrap().len();
97

10-
fn part_a(&self, input: &str) -> Answer {
11-
let num_len = input.lines().next().unwrap().len();
8+
let mut gamma = vec![0; num_len];
9+
let mut epsilon = vec![1; num_len];
1210

13-
let mut gamma = vec![0; num_len];
14-
let mut epsilon = vec![1; num_len];
11+
for i in 0..num_len {
12+
let mut z = 0;
13+
let mut o = 0;
1514

16-
for i in 0..num_len {
17-
let mut z = 0;
18-
let mut o = 0;
15+
input.lines().for_each(|j| match j.chars().nth(i).unwrap() {
16+
'0' => z += 1,
17+
'1' => o += 1,
18+
_ => {}
19+
});
1920

20-
input.lines().for_each(|j| match j.chars().nth(i).unwrap() {
21-
'0' => z += 1,
22-
'1' => o += 1,
23-
_ => {}
24-
});
25-
26-
if o > z {
27-
epsilon[i] = 0;
28-
gamma[i] = 1;
29-
}
21+
if o > z {
22+
epsilon[i] = 0;
23+
gamma[i] = 1;
3024
}
31-
32-
let gamma = int_from_bin(&gamma).unwrap();
33-
let epsilon = int_from_bin(&epsilon).unwrap();
34-
35-
(epsilon * gamma).into()
3625
}
3726

38-
fn part_b(&self, input: &str) -> Answer {
39-
let num_len = input.lines().next().unwrap().len();
40-
41-
let mut oxygen_keep = input.lines().collect::<Vec<&str>>();
42-
let mut oxygen_raw = vec![[0, 0]; num_len];
43-
let mut oxygen_gen = 0;
27+
let gamma = int_from_bin(&gamma).unwrap();
28+
let epsilon = int_from_bin(&epsilon).unwrap();
4429

45-
let mut co2_keep = oxygen_keep.clone();
46-
let mut co2_raw = oxygen_raw.clone();
47-
let mut co2_scrub = 0;
30+
(epsilon * gamma).into()
31+
}
4832

49-
for i in 0..num_len {
50-
// Filter Oxygen
51-
let imax = get_imax(&oxygen_raw, i);
52-
oxygen_raw = gen_raw(oxygen_raw, num_len, &oxygen_keep);
53-
oxygen_keep.retain(|x| x.chars().nth(i).unwrap() == imax);
33+
fn part_b(input: &str) -> Answer {
34+
let num_len = input.lines().next().unwrap().len();
5435

55-
// Filter Co2
56-
let imax = get_imax(&co2_raw, i);
57-
co2_raw = gen_raw(co2_raw, num_len, &co2_keep);
58-
co2_keep.retain(|x| x.chars().nth(i).unwrap() != imax);
36+
let mut oxygen_keep = input.lines().collect::<Vec<&str>>();
37+
let mut oxygen_raw = vec![[0, 0]; num_len];
38+
let mut oxygen_gen = 0;
5939

60-
if oxygen_keep.len() == 1 {
61-
oxygen_gen = isize::from_str_radix(oxygen_keep.first().unwrap(), 2).unwrap();
62-
}
40+
let mut co2_keep = oxygen_keep.clone();
41+
let mut co2_raw = oxygen_raw.clone();
42+
let mut co2_scrub = 0;
6343

64-
if co2_keep.len() == 1 {
65-
co2_scrub = isize::from_str_radix(co2_keep.first().unwrap(), 2).unwrap();
66-
}
44+
for i in 0..num_len {
45+
// Filter Oxygen
46+
let imax = get_imax(&oxygen_raw, i);
47+
oxygen_raw = gen_raw(oxygen_raw, num_len, &oxygen_keep);
48+
oxygen_keep.retain(|x| x.chars().nth(i).unwrap() == imax);
49+
50+
// Filter Co2
51+
let imax = get_imax(&co2_raw, i);
52+
co2_raw = gen_raw(co2_raw, num_len, &co2_keep);
53+
co2_keep.retain(|x| x.chars().nth(i).unwrap() != imax);
54+
55+
if oxygen_keep.len() == 1 {
56+
oxygen_gen = isize::from_str_radix(oxygen_keep.first().unwrap(), 2).unwrap();
6757
}
6858

69-
(oxygen_gen * co2_scrub).into()
59+
if co2_keep.len() == 1 {
60+
co2_scrub = isize::from_str_radix(co2_keep.first().unwrap(), 2).unwrap();
61+
}
7062
}
63+
64+
(oxygen_gen * co2_scrub).into()
7165
}
7266

7367
fn int_from_bin(inp: &[u32]) -> Option<usize> {

aoc_2021/src/day_04.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

3-
pub struct Day04;
3+
solution!("Giant Squid", 4);
44

5-
impl Solution for Day04 {
6-
fn name(&self) -> &'static str {
7-
"Giant Squid"
8-
}
9-
10-
fn part_a(&self, input: &str) -> Answer {
11-
let bingo = Bingo::parse_input(input);
12-
let winning = bingo.solve();
5+
fn part_a(input: &str) -> Answer {
6+
let bingo = Bingo::parse_input(input);
7+
let winning = bingo.solve();
138

14-
winning.0[winning.1].final_out(winning.2).into()
15-
}
9+
winning.0[winning.1].final_out(winning.2).into()
10+
}
1611

17-
fn part_b(&self, input: &str) -> Answer {
18-
let bingo = Bingo::parse_input(input);
19-
let loseing = bingo.loseing_solve();
12+
fn part_b(input: &str) -> Answer {
13+
let bingo = Bingo::parse_input(input);
14+
let losing = bingo.losing_solve();
2015

21-
loseing.0[loseing.1].final_out(loseing.2).into()
22-
}
16+
losing.0[losing.1].final_out(losing.2).into()
2317
}
2418

2519
#[derive(Debug, Clone)]
@@ -73,7 +67,7 @@ impl Bingo {
7367
}
7468
}
7569

76-
fn loseing_solve(self) -> (Vec<Board>, usize, u32) {
70+
fn losing_solve(self) -> (Vec<Board>, usize, u32) {
7771
let mut nums = self.numbers.clone();
7872
let mut tick = self.boards;
7973
let mut take = self.take;

aoc_2021/src/day_05.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

33
use hashbrown::HashMap;
44

5-
pub struct Day05;
5+
solution!("Hydrothermal Venture", 5);
66

7-
impl Solution for Day05 {
8-
fn name(&self) -> &'static str {
9-
"Hydrothermal Venture"
10-
}
11-
12-
fn part_a(&self, input: &str) -> Answer {
13-
run(input, false).into()
14-
}
7+
fn part_a(input: &str) -> Answer {
8+
run(input, false).into()
9+
}
1510

16-
fn part_b(&self, input: &str) -> Answer {
17-
run(input, true).into()
18-
}
11+
fn part_b(input: &str) -> Answer {
12+
run(input, true).into()
1913
}
2014

2115
/// dig -> Weather to include Diagonal Lines

aoc_2021/src/day_06.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
use common::{Answer, Solution};
1+
use common::{solution, Answer};
22

33
use std::hash::Hash;
44

55
use hashbrown::HashMap;
66

7-
pub struct Day06;
7+
solution!("Lanternfish", 6);
88

9-
impl Solution for Day06 {
10-
fn name(&self) -> &'static str {
11-
"Lanternfish"
12-
}
13-
14-
fn part_a(&self, input: &str) -> Answer {
15-
let data = Fish::parse_inp(input);
16-
Fish::sim(data, 80).into()
17-
}
9+
fn part_a(input: &str) -> Answer {
10+
let data = Fish::parse_inp(input);
11+
Fish::sim(data, 80).into()
12+
}
1813

19-
fn part_b(&self, input: &str) -> Answer {
20-
let data = Fish::parse_inp(input);
21-
Fish::sim(data, 256).into()
22-
}
14+
fn part_b(input: &str) -> Answer {
15+
let data = Fish::parse_inp(input);
16+
Fish::sim(data, 256).into()
2317
}
2418

2519
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]

0 commit comments

Comments
 (0)