AOC18
authorJustin Worthe <justin.worthe@gmail.com>
Sun, 18 Dec 2016 07:39:41 +0000 (09:39 +0200)
committerJustin Worthe <justin.worthe@gmail.com>
Sun, 18 Dec 2016 07:39:41 +0000 (09:39 +0200)
aoc18/Cargo.lock [new file with mode: 0644]
aoc18/Cargo.toml [new file with mode: 0644]
aoc18/src/main.rs [new file with mode: 0644]

diff --git a/aoc18/Cargo.lock b/aoc18/Cargo.lock
new file mode 100644 (file)
index 0000000..d26659d
--- /dev/null
@@ -0,0 +1,4 @@
+[root]
+name = "aoc18"
+version = "0.1.0"
+
diff --git a/aoc18/Cargo.toml b/aoc18/Cargo.toml
new file mode 100644 (file)
index 0000000..5eadfea
--- /dev/null
@@ -0,0 +1,6 @@
+[package]
+name = "aoc18"
+version = "0.1.0"
+authors = ["Justin Worthe <justin.worthe@gmail.com>"]
+
+[dependencies]
diff --git a/aoc18/src/main.rs b/aoc18/src/main.rs
new file mode 100644 (file)
index 0000000..52ad7a9
--- /dev/null
@@ -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);
+}