@@ -91,7 +91,7 @@ impl BitGrid {
9191 // (4,4) = 1 << 24 = 16777216
9292 fn mask ( x : i32 , y : i32 ) -> u32 {
9393 if ( 0 ..5 ) . contains ( & x) && ( 0 ..5 ) . contains ( & y) {
94- 1 << y * 5 + x
94+ 1 << ( y * 5 + x)
9595 } else {
9696 0
9797 }
@@ -137,9 +137,7 @@ struct InfiniteGrid {
137137
138138impl InfiniteGrid {
139139 fn get ( & self , depth : i32 , x : i32 , y : i32 ) -> bool {
140- if depth < 0 || depth as usize >= self . grids . len ( ) {
141- false
142- } else if x == 2 && y == 2 {
140+ if depth < 0 || depth as usize >= self . grids . len ( ) || ( x == 2 && y == 2 ) {
143141 false
144142 } else {
145143 self . grids [ depth as usize ] . get ( x, y)
@@ -222,14 +220,14 @@ impl InfiniteGrid {
222220 let mut data = 0 ;
223221 for y in 0 ..5 {
224222 for x in 0 ..5 {
225- if !( x == 2 && y == 2 ) {
226- if match ( self . get ( depth, x, y) , self . count_neighbours ( depth, x, y) ) {
223+ if !( x == 2 && y == 2 )
224+ && match ( self . get ( depth, x, y) , self . count_neighbours ( depth, x, y) ) {
227225 ( true , 1 ) => true ,
228226 ( false , 1 | 2 ) => true ,
229227 ( _, _) => false ,
230- } {
231- data += BitGrid :: mask ( x, y) ;
232228 }
229+ {
230+ data += BitGrid :: mask ( x, y) ;
233231 }
234232 }
235233 }
@@ -238,10 +236,10 @@ impl InfiniteGrid {
238236 }
239237
240238 // remove empty grids at ends
241- while grids. len ( ) > 0 && grids[ 0 ] . biodiversity_rating ( ) == 0 {
239+ while ! grids. is_empty ( ) && grids[ 0 ] . biodiversity_rating ( ) == 0 {
242240 grids. pop_front ( ) ;
243241 }
244- while grids. len ( ) > 0 && grids[ grids. len ( ) - 1 ] . biodiversity_rating ( ) == 0 {
242+ while ! grids. is_empty ( ) && grids[ grids. len ( ) - 1 ] . biodiversity_rating ( ) == 0 {
245243 grids. pop_back ( ) ;
246244 }
247245
0 commit comments