diff options
author | Irene Knapp <ireneista@gmail.com> | 2020-11-30 22:06:13 -0800 |
---|---|---|
committer | Irene Knapp <ireneista@gmail.com> | 2020-11-30 22:06:13 -0800 |
commit | d8ab28bbaba52e2c9f30aad2cc9812bd8a44becf (patch) | |
tree | 9fcdd14a34ccd14246ceb5198d97f76c7313e9ca /01 | |
parent | 40f28f1c6e301ead0b21b97f06ea3b8e93723707 (diff) |
Day 1!
Diffstat (limited to '01')
-rw-r--r-- | 01/src/main.rs | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/01/src/main.rs b/01/src/main.rs index 480e6db..a46ee99 100644 --- a/01/src/main.rs +++ b/01/src/main.rs @@ -2,7 +2,55 @@ use advent_lib::prelude::*; fn main() -> Result<()> { - advent_lib::greeting()?; + let mut args = std::env::args(); + if args.len() != 2 { + eprintln!("Usage: advent input"); + } + let _ = args.next(); + let filename = args.next().unwrap(); + + let mut input = advent_lib::read_int_file(&filename)?; + input.sort(); + + for i in 0 .. input.len() { + let a = input[i]; + if a > 2020 { + break; + } + + for j in i+1 .. input.len() { + let b = input[j]; + + if a + b == 2020 { + let product = a * b; + println!("a: {:?}, b: {:?}, a*b: {:?}", a, b, product); + } + } + } + + for i in 0 .. input.len() { + let a = input[i]; + if a > 2020 { + break; + } + + for j in i+1 .. input.len() { + let b = input[j]; + + if a + b > 2020 { + break; + } + + for k in j+1 .. input.len() { + let c = input[k]; + + if a + b + c == 2020 { + let product = a * b * c; + println!("a: {:?}, b: {:?}, c: {:?}, a*b*c: {:?}", a, b, c, product); + } + } + } + } Ok(()) } |