day1
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
/target
|
target/
|
||||||
input
|
input
|
||||||
|
testinput
|
||||||
|
|||||||
Generated
+7
@@ -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>());
|
||||||
|
}
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
# AOC_SESSION_COOKIE="samplecookie" ./fetchinput.sh 13
|
# AOC_SESSION_COOKIE="samplecookie" ./fetchinput.sh 13
|
||||||
|
|
||||||
# defaults to current day unless specified day is passed in
|
# 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
|
! [ "$1" = "" ] && printf "%d" $1 >/dev/null 2>&1 && DAY=$1
|
||||||
|
|
||||||
[ "$AOC_SESSION_COOKIE" = "" ] && echo "\$AOC_SESSION_COOKIE not set" && exit 1
|
[ "$AOC_SESSION_COOKIE" = "" ] && echo "\$AOC_SESSION_COOKIE not set" && exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user