Skip to content

Commit 8755078

Browse files
Large refactor
Splits different years into different subfolders, and adds a shared crate. This is because I want to start working on AoC 2019 while I wait for 2020 problems to release
1 parent 9a1e2cc commit 8755078

File tree

30 files changed

+259
-36
lines changed

30 files changed

+259
-36
lines changed

Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
[package]
2-
name = "advent-2020"
3-
version = "0.1.0"
4-
authors = ["Pi Lanningham <[email protected]>"]
5-
edition = "2018"
1+
[workspace]
62

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
9-
[dependencies]
10-
anyhow = "1.0.34"
11-
matches = "0.1.8"
3+
members = [
4+
"advent-shared",
5+
"advent-2019",
6+
"advent-2020"
7+
]
8+
default-members = ["advent-2020"]

advent-2019/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

advent-2019/Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

advent-2019/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "advent-2019"
3+
version = "0.1.0"
4+
authors = ["Pi Lanningham <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
advent-shared = { path = "../advent-shared" }
11+
anyhow = "1.0.34"

advent-2019/input/day1.txt

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
122281
2+
124795
3+
58593
4+
133744
5+
67625
6+
109032
7+
50156
8+
80746
9+
130872
10+
79490
11+
126283
12+
146564
13+
73075
14+
130170
15+
139853
16+
92599
17+
96965
18+
58149
19+
94254
20+
89074
21+
52977
22+
148092
23+
92073
24+
136765
25+
144755
26+
142487
27+
54827
28+
135588
29+
91411
30+
51597
31+
70040
32+
68880
33+
117120
34+
137115
35+
72829
36+
100048
37+
65187
38+
131464
39+
95813
40+
146891
41+
128799
42+
94568
43+
67178
44+
94903
45+
67193
46+
127613
47+
115782
48+
85360
49+
129820
50+
50989
51+
63471
52+
106724
53+
145768
54+
55169
55+
77555
56+
82978
57+
87728
58+
69141
59+
95518
60+
82985
61+
83387
62+
83089
63+
64372
64+
127931
65+
99277
66+
58930
67+
99098
68+
95621
69+
147797
70+
64102
71+
118857
72+
71014
73+
84881
74+
147294
75+
72166
76+
71348
77+
149240
78+
117963
79+
89181
80+
144770
81+
102444
82+
99103
83+
72341
84+
56076
85+
128515
86+
51319
87+
147595
88+
98431
89+
141102
90+
148617
91+
84685
92+
111427
93+
82351
94+
57021
95+
63834
96+
113059
97+
119970
98+
87078
99+
120631
100+
124942

advent-2019/src/main.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use anyhow::*;
2+
use advent_shared::parsers::*;
3+
use std::path::PathBuf;
4+
mod parsers;
5+
mod solutions;
6+
7+
fn solve<P, I, S, R>(file: &str, p: P, s: S) -> Result<R>
8+
where
9+
P : Fn(PathBuf) -> Result<I>,
10+
S : Fn(I) -> Result<R> {
11+
s(p([r"advent-2019", "input", file].iter().collect())?)
12+
}
13+
14+
fn main() {
15+
println!("1.1) {:?}", solve("day1.txt", vec_of, |a: Vec<u64>| {Ok(a)}));
16+
}

advent-2019/src/parsers/mod.rs

Whitespace-only changes.

advent-2019/src/solutions/day1.rs

Whitespace-only changes.

advent-2019/src/solutions/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod day1;

advent-2020/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

advent-2020/Cargo.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

advent-2020/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "advent-2020"
3+
version = "0.1.0"
4+
authors = ["Pi Lanningham <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
advent-shared = { path = "../advent-shared" }
11+
anyhow = "1.0.34"
12+
matches = "0.1.8"
File renamed without changes.
File renamed without changes.
File renamed without changes.

advent-2020/src/main.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mod parsers;
2+
mod solutions;
3+
use std::path::PathBuf;
4+
5+
use advent_shared::parsers::*;
6+
use solutions::*;
7+
use anyhow::*;
8+
9+
fn solve<P, I, S, R>(file: &str, p: P, s: S) -> Result<R>
10+
where
11+
P : Fn(PathBuf) -> Result<I>,
12+
S : Fn(I) -> Result<R> {
13+
s(p([r"advent-2020", "input", file].iter().collect())?)
14+
}
15+
16+
fn main() -> Result<()> {
17+
println!("1.1) {:?}", solve("day1.txt", vec_of, day1::sum_2020)?);
18+
println!("1.2) {:?}", solve("day1.txt", vec_of, day1::sum_3_2020)?);
19+
println!("2.1) {:?}", solve("day2.txt", vec_of, day2::part1::solve)?);
20+
println!("2.2) {:?}", solve("day2.txt", vec_of, day2::part2::solve)?);
21+
println!("3.1) {:?}", solve("day3.txt", vec_of, day3::part1)?);
22+
println!("3.2) {:?}", solve("day3.txt", vec_of, day3::part2)?);
23+
24+
Ok(())
25+
}

advent-2020/src/parsers/mod.rs

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

advent-shared/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

advent-shared/Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

advent-shared/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "advent-shared"
3+
version = "0.1.0"
4+
authors = ["Pi Lanningham <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
anyhow = "1.0.34"

advent-shared/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod parsers;
2+
3+
#[cfg(test)]
4+
mod tests {
5+
}

advent-shared/src/parsers/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod vec_of;
2+
pub use vec_of::*;

src/parsers/vec_of.rs renamed to advent-shared/src/parsers/vec_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::*;
2-
use std::{fmt::Debug, fs, str::FromStr};
2+
use std::{fmt::Debug, path::PathBuf, fs, str::FromStr};
33

4-
pub fn parse<T>(file: &str) -> Result<Vec<T>>
4+
pub fn vec_of<T>(file: PathBuf) -> Result<Vec<T>>
55
where
66
T: FromStr,
77
<T as FromStr>::Err: Debug,

src/main.rs

-23
This file was deleted.

src/parsers/mod.rs

-1
This file was deleted.

0 commit comments

Comments
 (0)