ACTOR = %w/digi petit rabi gema piyo/ def digi?(voice) voice =~ /nyo[^a-zA-Z0-9 ]{0,3}\Z/ end def petit?(voice) voice =~ /nyu[^a-zA-Z0-9 ]{0,3}\Z/ end def rabi?(voice) voice =~ /[a-zA-Z0-9]/ end def gema?(voice) voice =~ /gema[^a-zA-Z0-9 ]{0,3}\Z/ end def piyo?(voice) voice =~ /pyo[^a-zA-Z0-9 ]{0,3}\Z/ end STDIN.each_line.map {|line| line.chomp! actor, voice = line.split(' ',2) if [actor,voice].any?{|v| v.nil?} "WRONG!" elsif !ACTOR.include?(actor) "WRONG!" elsif send(actor+'?',voice) "CORRECT (maybe)" else "WRONG!" end }.each_with_index {|ans,i| puts ans }