summaryrefslogtreecommitdiff
path: root/2016/aoc18/src/main.rs
blob: 52ad7a9ab97103917eb361ceeabeb1679b8c71b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);
}