push my shit
This commit is contained in:
commit
cd57ddfcdb
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Scramble's Advent of Code 2022
|
||||||
|
Doing it in Rust, might perhaps also learn Zig.
|
7
rust/1/README.me
Normal file
7
rust/1/README.me
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
I just overwrote the first puzzle's solution with the second's, I'll have to be more organised in future days
|
||||||
|
|
||||||
|
First puzzle was just a single `let max: i32 = 0` instead of the `top` Vec, so same thing just a bit simpler
|
||||||
|
|
||||||
|
For the second part I keep the top 3 values and add a new one whenever it's at least greater than the smallest one, and keep those 3 values sorted so the smallest one is always first
|
||||||
|
|
||||||
|
Also I have a bug because the last elf is never taken into account, I should just append an empty line to the iterator
|
2259
rust/1/input.txt
Normal file
2259
rust/1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
rust/1/main
Executable file
BIN
rust/1/main
Executable file
Binary file not shown.
24
rust/1/main.rs
Normal file
24
rust/1/main.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use std::{fs::File, io::{BufReader, BufRead}};
|
||||||
|
|
||||||
|
fn main() -> () {
|
||||||
|
let path = "input.txt";
|
||||||
|
|
||||||
|
let input = File::open(path).unwrap();
|
||||||
|
let buf = BufReader::new(input);
|
||||||
|
|
||||||
|
let mut top = [0; 3];
|
||||||
|
let mut cur = 0;
|
||||||
|
|
||||||
|
for line in buf.lines() {
|
||||||
|
let line = line.unwrap();
|
||||||
|
if line == "" {
|
||||||
|
top[0] = top[0].max(cur);
|
||||||
|
top.sort();
|
||||||
|
cur = 0;
|
||||||
|
} else {
|
||||||
|
cur += line.parse::<i32>().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{}", top.iter().fold(0, |acc, el| {acc + el}));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user