Created
November 14, 2014 14:27
-
-
Save thbounzer/e51ddb947396e7ccacdc to your computer and use it in GitHub Desktop.
audiomathdrill
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
def speakthings a,b,op | |
%x{echo "#{a} #{op} #{b}" | espeak --stdin} | |
end | |
def singleop a,b,op,r | |
begin | |
puts " #{a}" | |
puts " #{op}" | |
puts " #{b}" | |
speakthings a,b,op | |
start = Time.now | |
i = STDIN.gets.chomp.to_i | |
puts r | |
end while (r != i) | |
return (Time.now - start) | |
end | |
def cycleops times,exectime,op,generator,operation | |
while times > 0 | |
a = generator.call | |
b = generator.call | |
r = operation.call a,op,b | |
exectime.push(singleop a,b,op,r) | |
times -= 1; | |
end | |
end | |
if ARGV.first | |
t = ARGV.first.to_i | |
else | |
t = 100 | |
end | |
g = Random.new | |
times_1d = t | |
times_2d = t | |
calctime1d = [] | |
calctime2d = [] | |
op = "+" | |
operation = (lambda {|a,op,b| a.send(op,b)}) | |
cycleops times_1d,calctime1d,op,(lambda {g.rand(3..9)}),operation | |
cycleops times_2d,calctime2d,op,(lambda {(g.rand(3..9).to_s + g.rand(3..9).to_s).to_i}),operation | |
puts "AVG time 1d #{(calctime1d.inject (0) {|res, temp| res+temp})/calctime1d.size.to_f}" | |
puts "AVG time 2d #{(calctime2d.inject (0) {|res, temp| res+temp})/calctime2d.size.to_f}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment