diff --git a/2018/loc.svg b/2018/loc.svg index 3f034c5..6f60c7e 100644 --- a/2018/loc.svg +++ b/2018/loc.svg @@ -32,10 +32,10 @@ z +" id="m7029ccf672" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -71,7 +71,7 @@ z - + @@ -110,7 +110,7 @@ z - + @@ -139,7 +139,7 @@ z - + @@ -153,7 +153,7 @@ z - + @@ -193,7 +193,7 @@ z - + @@ -286,10 +286,10 @@ z +" id="m9772f4f0de" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -302,7 +302,7 @@ L -3.5 0 - + @@ -316,7 +316,7 @@ L -3.5 0 - + @@ -331,7 +331,7 @@ L -3.5 0 - + @@ -346,7 +346,7 @@ L -3.5 0 - + @@ -361,7 +361,7 @@ L -3.5 0 - + @@ -577,7 +577,7 @@ z - - - + diff --git a/2018/src/day18.rs b/2018/src/day18.rs index dc6fbd2..9690824 100644 --- a/2018/src/day18.rs +++ b/2018/src/day18.rs @@ -12,10 +12,11 @@ enum Tile { Tree, Lumber, Open, + Invalid, } impl Tile { - pub fn next(self, counts: &[usize; 3]) -> Self { + pub fn next(self, counts: &[usize; 4]) -> Self { match self { Tile::Open => { if counts[Tile::Tree as usize] >= 3 { @@ -38,6 +39,7 @@ impl Tile { Tile::Open } } + Tile::Invalid => Tile::Invalid, } } } @@ -48,7 +50,7 @@ impl From for Tile { '|' => Tile::Tree, '#' => Tile::Lumber, '.' => Tile::Open, - _ => panic!("Invalid tile '{}'", c) + _ => Tile::Invalid } } } @@ -59,6 +61,7 @@ impl From for char { Tile::Tree => '|', Tile::Lumber => '#', Tile::Open => '.', + Tile::Invalid => 'X', } } } @@ -98,7 +101,7 @@ impl Day18 { let ymax = if y < height - 1 { y + 1 } else { y }; for x in 0..self.width { - let mut counts = [0; 3]; + let mut counts = [0; 4]; let xmin = if x > 0 { x - 1 } else { x }; let xmax = if x < width - 1 { x + 1 } else { x };