This commit is contained in:
2020-12-02 11:43:17 -08:00
commit 9eaf7517af
6 changed files with 157 additions and 0 deletions

BIN
src/problem1/.part1.rs.swp Normal file

Binary file not shown.

1
src/problem1/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod part1;

76
src/problem1/part1.rs Normal file
View File

@@ -0,0 +1,76 @@
/*
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
*/
use crate::Problem;
pub struct Problem1 {
number_list: Vec<i32>,
}
impl Problem1 {}
impl Problem for Problem1 {
fn new(input: &String) -> Self {
Problem1 {
number_list: input
.split("\n")
.filter_map(|s| {
let s = s.trim();
if !s.is_empty() {
Some(s.parse::<i32>().unwrap())
} else {
None
}
}).collect(),
}
}
fn run_part1(&self) {
let mut a_list = Vec::new();
let mut b_list = Vec::new();
for i in &self.number_list {
if *i >= 2020 / 2 {
a_list.push(i);
} else {
b_list.push(i);
}
}
for a in &a_list {
for b in &b_list {
if *a + *b == 2020 {
println!("Sum found, {} and {}", a, b)
}
}
}
}
fn run_part2(&self) {
let mut a_list = Vec::new();
let mut b_list = Vec::new();
let mut c_list = Vec::new();
for i in &self.number_list {
a_list.push(i);
b_list.push(i);
c_list.push(i);
if *i >= 2020 / 2 {
} else if *i >= 2020 / 3 {
} else {
}
}
for a in &a_list {
for b in &b_list {
for c in &c_list {
if *a + *b + *c == 2020 {
println!("Sum found, {}, {}, and {}", a, b, c)
}
}
}
}
}
}