Skip to content

Instantly share code, notes, and snippets.

@clvv
Created April 6, 2011 06:27
Show Gist options
  • Save clvv/905224 to your computer and use it in GitHub Desktop.
Save clvv/905224 to your computer and use it in GitHub Desktop.
Quiz on Mental Day of the Week Calculation
#!/usr/bin/env ruby
# This is a quiz that test you on your mental day of the week calculation.
# Enter a number according to the date prompted, Monday being 1. (1..7)
times = 10 # Number of dates
i = total_time = 0
times.times do
year = rand > 0.3 ? 1900 + rand(150) : 1600 + rand(700)
# tweak year for your own needs, this one is pretty general
month, day = rand(12) + 1, rand(31) + 1
puts date = Time.utc(year, month, day)
dow = date.strftime('%u')
t0 = Time.now
i += 1 if gets.strip == dow.to_i
puts dow
puts t = Time.now - t0
total_time += t
end
puts "#{i * 100.0 / times}% correct, average time: #{total_time / times} secs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment