summaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
authorcos <cos>2020-12-01 22:36:49 +0100
committercos <cos>2020-12-01 23:47:05 +0100
commitb2087ba800937e357a94ff7491cefae15e5198ef (patch)
treef5e5e6f38f0f211341d9d94a7234921ec2d0e5a5 /2020
parentf44158d941198d175c26ef8f74e80e4d4d0fa7a2 (diff)
downloadadventofcode-b2087ba800937e357a94ff7491cefae15e5198ef.zip
Add code to measure time and memory consumption
Diffstat (limited to '2020')
-rw-r--r--2020/rust/Cargo.toml1
-rw-r--r--2020/rust/day01/Cargo.toml1
-rw-r--r--2020/rust/day01/src/main.rs36
3 files changed, 23 insertions, 15 deletions
diff --git a/2020/rust/Cargo.toml b/2020/rust/Cargo.toml
index 9674b94..ee71f9e 100644
--- a/2020/rust/Cargo.toml
+++ b/2020/rust/Cargo.toml
@@ -1,5 +1,6 @@
[workspace]
members = [
+ "aoc",
"day01",
# "day02",
# "day03",
diff --git a/2020/rust/day01/Cargo.toml b/2020/rust/day01/Cargo.toml
index 674217d..4bf07f8 100644
--- a/2020/rust/day01/Cargo.toml
+++ b/2020/rust/day01/Cargo.toml
@@ -5,4 +5,5 @@ authors = ["cos <cos>"]
edition = "2018"
[dependencies]
+aoc = { path = "../aoc" }
anyhow = "1.0"
diff --git a/2020/rust/day01/src/main.rs b/2020/rust/day01/src/main.rs
index 38f25d2..fb661e6 100644
--- a/2020/rust/day01/src/main.rs
+++ b/2020/rust/day01/src/main.rs
@@ -43,6 +43,8 @@ fn part2(input: &[usize]) -> Option<usize> {
}
fn main() {
+ let ( do_part_1, do_part_2 ) = aoc::do_parts();
+
let filename = match args().nth(1) {
Some(f) => f,
None => {
@@ -50,22 +52,26 @@ fn main() {
std::process::exit(1);
},
};
- match read_input(filename) {
+ match read_input(filename) {
Ok(input) => {
- match part1(&input) {
- Some(solution) => println!("Part1, product found to be: {}", solution),
- None => {
- eprintln!("Part1, no solution found");
- std::process::exit(1);
- }
- };
- match part2(&input) {
- Some(solution) => println!("Part2, product found to be: {}", solution),
- None => {
- eprintln!("Part2, no solution found");
- std::process::exit(1);
- }
- };
+ if do_part_1 {
+ match part1(&input) {
+ Some(solution) => println!("Part1, product found to be: {}", solution),
+ None => {
+ eprintln!("Part1, no solution found");
+ std::process::exit(1);
+ }
+ };
+ }
+ if do_part_2 {
+ match part2(&input) {
+ Some(solution) => println!("Part2, product found to be: {}", solution),
+ None => {
+ eprintln!("Part2, no solution found");
+ std::process::exit(1);
+ }
+ };
+ }
},
Err(err) => eprintln!("Could not read input: {}", err),
}