day1
This commit is contained in:
commit
4130a8208f
7
day1/Cargo.lock
generated
Normal file
7
day1/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
8
day1/Cargo.toml
Normal file
8
day1/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
2255
day1/input.txt
Normal file
2255
day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
25
day1/src/main.rs
Normal file
25
day1/src/main.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::io::BufRead;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let input = &args[1];
|
||||||
|
let reader = BufReader::new(File::open(input).expect("where file?"));
|
||||||
|
|
||||||
|
let mut sum: i64 = 0;
|
||||||
|
let mut max: i64 = 0;
|
||||||
|
for line in reader.lines() {
|
||||||
|
if !line.as_ref().unwrap().trim().is_empty() {
|
||||||
|
sum += line.unwrap().parse::<i64>().unwrap();
|
||||||
|
} else {
|
||||||
|
if sum > max {
|
||||||
|
max = sum;
|
||||||
|
}
|
||||||
|
sum = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Max: {}", max);
|
||||||
|
}
|
14
day1/test.txt
Normal file
14
day1/test.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
1000
|
||||||
|
2000
|
||||||
|
3000
|
||||||
|
|
||||||
|
4000
|
||||||
|
|
||||||
|
5000
|
||||||
|
6000
|
||||||
|
|
||||||
|
7000
|
||||||
|
8000
|
||||||
|
9000
|
||||||
|
|
||||||
|
10000
|
Loading…
Reference in New Issue
Block a user