Created
July 26, 2008 07:54
-
-
Save hakobe/2619 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Problem | |
attr_reader :x, :y, :op | |
def initialize(op, x, y) | |
@op = op | |
@x = x | |
@y = y | |
end | |
def to_s | |
"#{x} #{op} #{y}" | |
end | |
def answer | |
x.send(op, y) | |
end | |
end | |
if RUBY_VERSION < 1.8.7 | |
class Array | |
def choice | |
self[ rand(self.size) ] | |
end | |
end | |
end | |
def create_easy_problem | |
op = [:+, :-, :*].choice | |
x = (0...10).to_a.choice | |
y = (0...10).to_a.choice | |
Problem.new(op, x, y) | |
end | |
def difficult_easy_problem | |
end | |
result = { | |
:good => 0, | |
:bad => 0, | |
} | |
100.times do |n| | |
puts "!! #{n} !!" if n % 10 == 0 | |
problem = create_easy_problem | |
print problem, " = " | |
answer = gets.to_i | |
break unless answer | |
answer = answer.to_i | |
if answer == problem.answer | |
puts "good" | |
result[:good] += 1 | |
else | |
puts "bad" | |
result[:bad] += 1 | |
end | |
end | |
pp result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment