Also did #1 in rust.

This commit is contained in:
David Vereb 2022-12-01 14:11:30 -05:00
parent 3aae838ef7
commit 3c70653791
2 changed files with 40 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*~
*a.out
*main

38
2022/1/main.rs Normal file
View File

@ -0,0 +1,38 @@
use std::fs;
fn main()
{
let contents = fs::read_to_string("data.txt")
.expect("Could not find data.txt.");
let mut numbers = Vec::new();
let mut total = 0;
let mut max = 0;
for line in contents.split('\n')
{
if line == ""
{
if total > max
{
max = total;
}
numbers.push(total);
total = 0;
}
else
{
let i = line.parse::<i32>().unwrap();
total += i;
}
}
println!("Max: {max}");
numbers.sort();
let mut top_three = 0;
for amt in &numbers[numbers.len() - 3..numbers.len()]
{
top_three += amt;
}
println!("Top Three: {top_three}");
}