# frozen_string_literal: true # # represent drunks situation # class Drunks def number if @prev2 suffer2 advance elsif @prev4 suffer4 advance end consume advance end def draw2 if @prev4 suffer4 advance end consume @bomb += 2 @prev2 = true advance end def draw4 if @prev2 suffer2 advance end consume @bomb += 4 @prev4 = true advance end def skip if @prev2 suffer2 advance elsif @prev4 suffer4 advance end consume advance advance end def reverse if @prev2 suffer2 advance elsif @prev4 suffer4 advance end @reverse = !@reverse consume advance end def winner previous winner_id = @turn + 1 winner_first_num = @members[@turn].original "#{winner_id} #{winner_first_num}" end private def initialize(num) @turn = 0 @reverse = false @prev2 = false @prev4 = false @bomb = 0 @members = Array.new(num) { Drunk.new } end def advance turn = @turn + (@reverse ? -1 : 1) @turn = turn % @members.size end def previous turn = @turn + (@reverse ? 1 : -1) @turn = turn % @members.size end def suffer2 @members[@turn].penalty += @bomb @bomb = 0 @prev2 = false end def suffer4 @members[@turn].penalty += @bomb @bomb = 0 @prev4 = false end def consume @members[@turn].change += 1 end # # represent drunk # class Drunk attr_accessor :change, :penalty def original @change - @penalty end private def initialize @change = 0 @penalty = 0 end end end # ----------------------------------- exec N, M = gets.chomp.split.map(&:to_i) LS = M.times.map do gets.chomp end drunks = Drunks.new(N) LS.each do |type| case type when 'number' drunks.number when 'drawtwo' drunks.draw2 when 'drawfour' drunks.draw4 when 'skip' drunks.skip when 'reverse' drunks.reverse end end puts(drunks.winner)