summaryrefslogtreecommitdiff
path: root/2016/aoc18
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2022-04-19 20:22:56 +0200
committerJustin Wernick <justin@worthe-it.co.za>2022-04-19 20:23:15 +0200
commit174772b5b8d9f5bf5e3c8e8152adfd89f0e83f6b (patch)
treea003b748ee939b30a2bcd3caf2378228baa304c1 /2016/aoc18
parentfd75b3fb95ad049b0025cb8fc0b3459b8f872d61 (diff)
Refile for merging repos
Diffstat (limited to '2016/aoc18')
-rw-r--r--2016/aoc18/Cargo.lock4
-rw-r--r--2016/aoc18/Cargo.toml6
-rw-r--r--2016/aoc18/src/main.rs20
3 files changed, 30 insertions, 0 deletions
diff --git a/2016/aoc18/Cargo.lock b/2016/aoc18/Cargo.lock
new file mode 100644
index 0000000..d26659d
--- /dev/null
+++ b/2016/aoc18/Cargo.lock
@@ -0,0 +1,4 @@
+[root]
+name = "aoc18"
+version = "0.1.0"
+
diff --git a/2016/aoc18/Cargo.toml b/2016/aoc18/Cargo.toml
new file mode 100644
index 0000000..5eadfea
--- /dev/null
+++ b/2016/aoc18/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "aoc18"
+version = "0.1.0"
+authors = ["Justin Worthe <justin.worthe@gmail.com>"]
+
+[dependencies]
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);
+}