blob: 5a1660e3ac4ccfe6242f3bc386d81ad031bfb3f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
use std::io::{BufRead};
pub fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 2 { panic!("Need exactly 1 argument"); }
let num_days: usize = args[1].parse().expect("Need number of days as argument");
let mut stdin = std::io::stdin();
let mut handle = stdin.lock();
let input: String = {
let mut buf = String::new();
handle.read_line(&mut buf).unwrap();
String::from(buf.trim_end())
};
let mut fishes: Vec<u64> = input.split(',').map(|w| w.parse().expect("Malformed input")).collect();
for i in 0..num_days {
let mut new_fish_count: usize = 0;
for fish in (&mut fishes).into_iter() {
if *fish == 0 {
new_fish_count += 1;
*fish = 6;
}
else { *fish -= 1; }
}
fishes.extend(std::iter::repeat(8).take(new_fish_count));
/*
print!("After day {:>width$}: ", i, width = format!("{}", num_days).len());
for fish in (& fishes).into_iter() {
print!("{} ", *fish);
}
println!("");
*/
}
println!("After {} days there are {} fishies", num_days, fishes.len());
}
|