Created
February 25, 2012 12:11
-
-
Save cormacrelf/1908130 to your computer and use it in GitHub Desktop.
You know those people who can tell you the weekday for any date? Here's how to practise that. Tip: 0 means Sunday through to 6 means Saturday when talking about "weekday codes". Grey Matters' guide might help you, too: http://gmmentalgym.blogspot.com.au/
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
#!/usr/bin/env ruby | |
require 'date' | |
require "highline/import" | |
begin | |
class Date | |
def pretty_string | |
months = [ nil,"January", "Febuary", | |
"March","April","May", | |
"June","July","August", | |
"September","October","November", | |
"December" ] | |
return "#{months[self.month]} #{self.day}, #{self.year}" | |
end | |
def wday_string | |
days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] | |
return days[self.wday] | |
end | |
end | |
def dateRand (date1, date2) | |
date1,date2 = *[date1, date2].map {|x| x.to_time} | |
Time.at((date2.to_f - date1.to_f)*rand + date1.to_f) | |
end | |
asking = true | |
while asking do | |
rand = dateRand(Date.new(1600,1,1), Date.new(2099,12,31)).to_date | |
puts rand.pretty_string | |
incorrect = true | |
while incorrect do | |
response = ask("Weekday code: ", Integer) {|response| response.validate = /\d+/} | |
if response == rand.wday | |
puts " => Correct: it's a #{rand.wday_string}" | |
incorrect = false | |
else | |
puts " => Wrong. Try again below." | |
end | |
end | |
end | |
rescue Interrupt => e | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment