#!/usr/bin/ruby # ignore the warnings! $-v = nil # define the gom informations GOMsay = ARGV.length > 0? ARGV[0].strip: "say" GOMgom = ARGV.length > 1? ARGV[1].strip: "gom" GOMcomplete = "#{GOMgom.upcase}! :D" GOMmax = 10 GOMwelcome = "\n#{GOMsay} #{GOMgom}! the thrilling game of subtracting one!\n\n" GOMegress = "\nto #{GOMsay} #{GOMgom} again, just run the program again! :D\n\n" GOMsuccess = "yay! success at subtracting one!!1" GOMfail = "you have failed at subtracting one!" GOMcomplain = ">:( oi!" def gomExit() puts GOMegress exit end # start the gom! puts GOMwelcome GOMcount = rand(GOMmax) + 1 while true # if we are finished, we are finished. declare success and quit whilst ahead if GOMcount == 0 puts GOMcomplete puts GOMsuccess gomExit end # otherwise continue to say gom puts (GOMsay+" ")*GOMcount + GOMgom gomIn = $stdin.readline # gomTokens should be GOMcount-1 empty strings and 1 GOMgom gomTokens = [] gomIn.downcase.split(GOMsay).each { |tok| # in case non-say token needs breaking up toks = tok.split.length == 0? [tok]: tok.split toks.each {|t| gomTokens += [t.strip.delete('!')]} } gomCount = gomTokens.find_all {|t| t == GOMgom}.length sayCount = gomTokens.find_all {|t| t == ""}.length otherCount = gomTokens.length - gomCount - sayCount # chance of win! ignore any alternative celebratory tokens if GOMcount == 1 && gomCount == 1 && sayCount == 0 puts GOMsuccess gomExit end # consider the fallacies that may be made if gomCount != 1 puts "#{GOMcomplain} must have one #{GOMgom}. #{GOMfail}" gomExit end if otherCount > 0 puts "#{GOMcomplain} #{GOMsay} and #{GOMgom} are all that is necessary. #{GOMfail}" gomExit end if sayCount != GOMcount-1 puts "FOOL! #{GOMfail} you are clearly destined for limited success in life." gomExit end # if no ending conditions met, continue to next exciting round! GOMcount -= 2 end