From 112d1462a433ece74553bfc4811dee7013964df7 Mon Sep 17 00:00:00 2001 From: Bas Dado Date: Tue, 1 Dec 2020 09:28:16 +0100 Subject: [PATCH] Forgot to commit some files + small cleanup --- .gitignore | 1 + .idea/.gitignore | 8 ++++++++ Cargo.lock | 5 +++++ Cargo.toml | 9 +++++++++ src/day1.rs | 30 ------------------------------ src/main.rs | 24 ++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a0d1321 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../:\workspace\fun\advent-of-code-2020-rust\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c80d5b6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "advent-of-code-2020-rust" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2da4522 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "advent-of-code-2020-rust" +version = "0.1.0" +authors = ["Bas Dado "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/day1.rs b/src/day1.rs index 09e37ac..4d6a5ed 100644 --- a/src/day1.rs +++ b/src/day1.rs @@ -57,34 +57,4 @@ fn find_triplet_summing_to(nums: &Vec, target: u32) -> (u32, u32, u32){ } } panic!("Couldn't find match!"); - - // - // let mut i:usize = 0; - // let mut j:usize = nums.len() - 1; - // loop { - // if j < i { - // - // // Reset with i one higher: - // i += 1; - // j = nums.len() - 1; - // } - // - // let n1 = nums[i]; - // let n2 = nums[j]; - // let sum = n1 + n2; - // if sum + n1 > target { - // j -= 1; - // } else { - // // See if we can find a third number between i and j that makes the sum equal to the target - // let n3_target = target - sum; - // let res = nums.binary_search(&n3_target); - // if res.is_ok() { - // // Found it! - // return (n1, n2, n3_target) - // } else { - // j -= 1; - // } - // } - // } - } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0688e0a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,24 @@ +use std::time::Instant; + +mod util; +mod day1; + +fn main() { + + let now = Instant::now(); + + let args: Vec = std::env::args().collect(); + + let day_arg_idx = args.iter().position(|a| a == "-d"); + if day_arg_idx.is_some() { + match args[day_arg_idx.unwrap() + 1].parse::().unwrap() { + 1 => day1::solve(), + _ => println!("This day is not yet implemented") + } + } else { + // Solve all days: + day1::solve(); + } + + println!("Execution took {} μs", now.elapsed().as_micros()); +}