master
george 2 years ago
parent afaf4a1ddf
commit 38123f3a00

3
.gitignore vendored

@ -1,2 +1,3 @@
/target
target/
input
testinput

7
day01/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day01"
version = "0.1.0"

@ -0,0 +1,8 @@
[package]
name = "day01"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -0,0 +1,30 @@
use std::io::{self, BufRead};
fn main() {
let lines = io::stdin().lock().lines().map(|l| l.unwrap());
let mut sum = 0;
let mut max = [0, 0, 0];
for line in lines {
if let Ok(num) = line.parse::<usize>() {
sum += num;
} else {
match (sum > max[0], sum > max[1], sum > max[2]) {
(_, _, true) => {
max.rotate_left(1);
max[2] = sum;
}
(_, true, false) => {
max[0] = max[1];
max[1] = sum;
}
(true, false, false) => {
max[0] = sum;
}
_ => (),
}
sum = 0;
}
}
println!("P1: {} P2: {}", max[2], max.iter().sum::<usize>());
}

@ -2,7 +2,7 @@
# AOC_SESSION_COOKIE="samplecookie" ./fetchinput.sh 13
# defaults to current day unless specified day is passed in
DAY=`date +%d`
DAY=$(printf "%01d" `date +%d`)
! [ "$1" = "" ] && printf "%d" $1 >/dev/null 2>&1 && DAY=$1
[ "$AOC_SESSION_COOKIE" = "" ] && echo "\$AOC_SESSION_COOKIE not set" && exit 1

Loading…
Cancel
Save