lib/aoc2021/puzzles/amphipod.rb
# In Simon's bitboard implementation, mask is a 7-bit representation
# of the hallway, where 64 is the leftmost spot and 1 is the rightmost.
# For the moment, our hallway has spots 0, 1, 3, 5, 7, 9, and 10.
# Switching to the bitboard might perform better.
In Simon's bitboard implementation, mask is a 7-bit representation
of the hallway, where 64 is the leftmost spot and 1 is the rightmost.
For the moment, our hallway has spots 0, 1, 3, 5, 7, 9, and 10.
Switching to the bitboard might perform better.
In Simon ' s bitboard implementation mask is a 7 - bit representation of the hallway where 64 is the leftmost spot and 1 is the rightmost . For the moment our hallway has spots 0 1 3 5 7 9 and 10 . Switching to the bitboard might perform better .
def commit(from_room, hall_pos)
        pod = @board[from_room].shift
        @board[hall_pos] = pod if hall_pos 
                 if self.rooms[0].is_empty() {
                     self.hallway.amber = 0;
                 if self.rooms[1].is_empty() {
                     self.hallway.bronze = 0;
                 if self.rooms[2].is_empty() {
                     self.hallway.copper = 0;
                 if self.rooms[3].is_empty() {
                     self.hallway.desert = 0;
        8.step(by: -2, to: 2).each do |room|
          if @board[room].empty?
            amph   = ROOM_AMPHIPOD[room]
            @board = @board.map { |spot| spot == amph ? nil : spot }
          end
        end
        self
      end
def commit ( from_room , hall_pos ) pod = @board [ from_room ] . shift @board [ hall_pos ] = pod if hall_pos 8 . step ( by : - 2 , to : 2 ) . each do | room | if @board [ room ] . empty? amph = ROOM_AMPHIPOD [ room ] @board = @board . map { | spot | spot == amph ? nil : spot } end end self end
In Simon's bitboard implementation, mask is a 7-bit representation
of the hallway, where 64 is the leftmost spot and 1 is the rightmost.
In Simon ' s bitboard implementation mask is a 7 - bit representation of the hallway where 64 is the leftmost spot and 1 is the rightmost .
# might be nil, indicating that this pod goes into its room # target below is the from_room parameter, and # mask below is the hall_pos param #         match pod { #             Amphipod::Amber => { #                 self.rooms[target].take(); #                 self.hallway.amber |= mask; #             } #             Amphipod::Bronze => { #                 self.rooms[target].take(); #                 self.hallway.bronze |= mask; #             } #             Amphipod::Copper => { #                 self.rooms[target].take(); #                 self.hallway.copper |= mask; #             } #             Amphipod::Desert => { #                 self.rooms[target].take(); #                 self.hallway.desert |= mask; #             } #         } # #         if self.rooms[0].is_empty() { #             self.hallway.amber = 0; #         } #         if self.rooms[1].is_empty() { #             self.hallway.bronze = 0; #         } #         if self.rooms[2].is_empty() { #             self.hallway.copper = 0; #         } #         if self.rooms[3].is_empty() { #             self.hallway.desert = 0; #         }
from_room
<not_specific>
hall_pos
<not_specific>