summaryrefslogtreecommitdiff
path: root/06/src/part-1.rs
diff options
context:
space:
mode:
Diffstat (limited to '06/src/part-1.rs')
-rw-r--r--06/src/part-1.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/06/src/part-1.rs b/06/src/part-1.rs
new file mode 100644
index 0000000..5a1660e
--- /dev/null
+++ b/06/src/part-1.rs
@@ -0,0 +1,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());
+}