Created
May 25, 2009 05:44
-
-
Save spraints/117399 to your computer and use it in GitHub Desktop.
This file contains 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
# From http://www.indy500.com/images/news/2009/2009_Indianapolis_500_Unofficial_Box_Score.pdf | |
# final place, start position, name | |
results = <<END_RESULTS | |
1,1,Helio Castroneves | |
2,18,Dan Wheldon | |
3,10,Danica Patrick | |
4,24,Townsend Bell | |
5,9,Will Power | |
6,5,Scott Dixon | |
7,3,Dario Franchitti | |
8,17,Ed Carpenter | |
9,13,Paul Tracy | |
10,16,Hideki Mutoh | |
11,33,Alex Taliani | |
12,26,Tomas Scheckter | |
13,11,Alex Lloyd | |
14,20,Scott Sharp | |
15,2,Ryan Briscoe | |
16,19,A.J. Foyt IV | |
17,21,Sarah Fisher | |
18,27,Mike Conway | |
19,28,John Andretti | |
20,30,Milka Duno | |
21,14,Vitor Meira | |
22,12,Raphael Matos | |
23,15,Justin Wilson | |
24,29,E.J. Viso | |
25,31,Nelson Philippe | |
26,25,Oriol Servia | |
27,6,Tony Kanaan | |
28,23,Robert Doornbos | |
29,22,Davey Hamilton | |
30,8,Marco Andretti | |
31,4,Graham Rahal | |
32,32,Ryan Hunter-Reay | |
33,7,Mario Moraes | |
END_RESULTS | |
TIER_COUNT=3 | |
TIER_SIZE=11 | |
def choice_indices(tier, offset) | |
(0..TIER_SIZE*TIER_SIZE-1).collect { |i| | |
case tier | |
when 0 | |
i + offset * TIER_SIZE**2 | |
when 1 | |
i % TIER_SIZE + TIER_SIZE**2 * (i / TIER_SIZE) + TIER_SIZE * offset | |
when 2 | |
i * TIER_SIZE + offset | |
end | |
} | |
end | |
choices = [] | |
results.each_line do |line| | |
final, pole, driver = line.chomp.split(',') | |
start_index = pole.to_i - 1 | |
tier = start_index / TIER_SIZE | |
choice_indices(tier, start_index % TIER_SIZE).each do |i| | |
choices[i] ||= { :score => 0, :drivers => [] } | |
choices[i][:score] += final.to_i | |
choices[i][:drivers][tier] = "#{driver} (start #{pole}, end #{final})" | |
end | |
end | |
choices.sort { |a, b| a[:score] <=> b[:score] }.each_with_index do |choice, i| | |
puts "#{(i.to_s + '.').ljust(5)} #{choice[:score]} #{choice[:drivers].join(', ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment