Skip to content

Instantly share code, notes, and snippets.

@odlp
Created October 24, 2013 09:58
Show Gist options
  • Save odlp/7134379 to your computer and use it in GitHub Desktop.
Save odlp/7134379 to your computer and use it in GitHub Desktop.
typing.io tenline
puts `clear`
exercises = ["How much wood can a woodchuck chuck?", "What's the time Mr.Wolf?", "Peter Piper picked a peck of pickled peppers."]
def check_diff text, input
text.length.times.map{|i| 1 unless text.chars[i] == input.chars[i]}.count(1) + (input.length > text.length ? input.length - text.length : 0)
end
exercises.each do |exercise|
puts "Type the following:\n---\n#{exercise}\n---\n\n"
start_time, input, end_time = Time.now, gets.chomp, Time.now
puts "Mistakes: #{check_diff(exercise, input)} characters. Time taken: #{(end_time - start_time).round(2)} seconds.\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment