1
0
Fork 0

Submit first star

This commit is contained in:
Vivianne 2022-11-30 21:44:06 -08:00
commit 019dc4d0ce
5 changed files with 2294 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
/target
# Added by cargo
#
# already existing elements were commented out
#/target

7
Cargo.lock generated Normal file
View File

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

8
Cargo.toml Normal file
View File

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

2242
input.txt Normal file

File diff suppressed because it is too large Load Diff

29
src/main.rs Normal file
View File

@ -0,0 +1,29 @@
use std::env;
use std::fs;
use std::io::{self, BufRead};
fn main() {
let args: Vec<String> = env::args().collect();
let filename = if args.len() > 1 {
&args[1]
} else {
"input.txt"
};
println!("Gonna load {}!", filename);
let file = fs::File::open(filename).unwrap();
let lines = io::BufReader::new(file).lines();
let mut max_cals: u32 = 0;
let mut cur_cals: u32 = 0;
for l in lines {
if let Ok(cals) = l.unwrap().parse::<u32>() {
cur_cals += cals;
} else {
max_cals = max_cals.max(cur_cals);
println!("new cals: {}, max so far: {}", cur_cals, max_cals);
cur_cals = 0;
};
}
}