From: "Linklater, Lloyd \(IT\)" <LINKLLL@voughtaircraft.com>
Date: June 6, 2007 1:03:25 PM CDT
To: <submission@rubyquiz.com>
Subject: Please Forward: Ruby Quiz SubmissionI saw quiz 61 and wanted to send in something. I am a ruby n00b and want to contribute if I can.
When generating DND stats, you get to roll 4 dice and use the 3 best rolls. This is done for 6 stats. My version rolls ten thousand times and picks a good one from them. This stat list is then shown with the best stat in the first place and sorted descending. The idea behind this sorting is more than just making it easier to read. It allows for other code to place the stats intelligently. e.g. warriors get strength first, constitution second, etc. Wizards get intelligence first and dex second, and so on.
ar = Array.new
stats = Array.new
bestStats = Array.new
10_000.times do |k|
6.times do |j|
4.times {|i| ar[i] = rand(6)}
ar.sort!
stats[j] = ar[1] + ar[2] + ar[3] + 3
end
bestStats[k] = stats.sort
end
bestStats.sort!.reverse!
p bestStats[0].reverseI do not know if I am writing good code or not. I am too new to ruby for that. I can know that it looks good to me and it works.
Thanks!
Lloyd Linklater
ยทยทยท
Begin forwarded message: