summaryrefslogtreecommitdiff
path: root/2016/aoc18/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '2016/aoc18/src/main.rs')
-rw-r--r--2016/aoc18/src/main.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/2016/aoc18/src/main.rs b/2016/aoc18/src/main.rs
new file mode 100644
index 0000000..52ad7a9
--- /dev/null
+++ b/2016/aoc18/src/main.rs
@@ -0,0 +1,20 @@
+fn main() {
+ let init: Vec<char> = ".^^..^...^..^^.^^^.^^^.^^^^^^.^.^^^^.^^.^^^^^^.^...^......^...^^^..^^^.....^^^^^^^^^....^^...^^^^..^".chars().collect();
+
+ let mut map = Vec::new();
+ map.push(init);
+
+ for _ in 1..400000 {
+ let last = map.last().unwrap().clone();
+ let mut next = Vec::new();
+ for i in 0..last.len() {
+ let left = if i == 0 { '.' } else { last[i-1] };
+ let right = if i == last.len()-1 { '.' } else { last[i+1] };
+ next.push(if left == right { '.' } else { '^' });
+ }
+ map.push(next);
+ }
+
+ let safe_count = map.iter().map(|row| row.iter().filter(|&&c| c=='.').count() as u32).sum::<u32>();
+ println!("Safe tiles: {}", safe_count);
+}