Skip to content

Instantly share code, notes, and snippets.

@0x0dea

0x0dea/nawn.rb Secret

Created August 26, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x0dea/d97760180bf25c67377d to your computer and use it in GitHub Desktop.
Save 0x0dea/d97760180bf25c67377d to your computer and use it in GitHub Desktop.
puts "Gimme numbars! Say 'done' as appropriate."
nums = ARGF.take_while { |line| line.chomp.upcase != 'DONE' }
.map { |n| n.delete(?,).to_i }
puts "These are teh numbars: #{nums}"
puts "Which op you wantses? add(+1), sub(-2), mul(*3), div(/4)"
valid = %w[add sub mul div 1 2 3 4 + - * /]
op = gets.chomp until valid.include? op
op = '+-*/'[valid.index(op) % 4]
puts "#{nums * op.center(3)} = #{nums.reduce op}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment