Submit first star
This commit is contained in:
commit
019dc4d0ce
|
@ -0,0 +1,8 @@
|
|||
/target
|
||||
|
||||
|
||||
# Added by cargo
|
||||
#
|
||||
# already existing elements were commented out
|
||||
|
||||
#/target
|
|
@ -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"
|
|
@ -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]
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue