Also did #1 in rust.
This commit is contained in:
parent
3aae838ef7
commit
3c70653791
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*~
|
||||
|
||||
*a.out
|
||||
*main
|
||||
|
38
2022/1/main.rs
Normal file
38
2022/1/main.rs
Normal 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}");
|
||||
}
|
Loading…
Reference in New Issue
Block a user