Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # usage: ruby air.rb
- L = Hash[("a".."f").map.with_index {|e,i| [e,i+1] }]
- LL = L.invert
- c = File.read("air-pytania.txt").split("\n\n").sort_by { rand }[0...10].map do |q|
- p = q.split("\n")
- puts p.first
- correct = 0
- (1...p.size).each do |i|
- correct = i if p[i] =~ /\* (.+)/
- puts LL[i] + ") " + p[i].gsub(/\*|-/, '')
- end
- print "Odp: "
- ans = gets.chomp
- if ans == LL[correct]
- puts "Dobrze!"
- puts
- 1
- else
- puts "Dupa. Poprawna odpowiedz to: #{LL[correct]}"
- puts
- 0
- end
- end.inject(0){|s,e| s + e}
- puts
- puts
- puts "Wynik: #{c}/10"
Add Comment
Please, Sign In to add comment