Sorting. First lowest m, then highest n & last lowest s value

dansefil = File.open(“dans.txt”)

dansearray = Array.new

resultatarray = Array.new

dansefil.each do |line|

dansind = Array.new
dansheltal = Array.new
dansheltal1 = Array.new
dansind = line.chomp.split(",")

for i in 0…7
dansheltal[i] = dansind[i].to_i
dansheltal1[i] = dansind[i].to_i
end

dansearray << dansheltal1

dansheltal.sort!

FINDING M

m = dansheltal[3]

counter = 1
if dansheltal[4] == m
counter += 1
end

if dansheltal[5] == m
counter += 1
end

if dansheltal[6] == m
counter += 1
end

s = dansheltal[0]+dansheltal[1]+dansheltal[2]+dansheltal[3]*counter

FINDING N

taeller = 0
if dansheltal[0] <= m
taeller += 1
end

if dansheltal[1] <= m
taeller += 1
end

if dansheltal[2] <= m
taeller += 1
end

if dansheltal[3] == m
end

n = taeller += counter

resultat = Array.new

Couple Number

resultat[0] = dansheltal[7]

Results

resultat[1] = m
resultat[2] = n
resultat[3] = s

resultatarray << resultat

end

dansearray.each do |x|
puts x.inspect
end

resultatarray.sort!{|a,b| a[1] <=> b[1]}

resultatarray.each_with_index do |b,a|

puts “Couple number:#{resultatarray[a][0]}\tMajority:
#{resultatarray[a][1]}\tJudge Majority: #{resultatarray[a][2]}\tTotal
Majority: #{resultatarray[a][3]}”

end

input data:

34,1,2,2,2,6,6,6
55,2,5,5,5,5,5,5
66,3,4,4,4,3,3,3
67,4,3,3,3,2,2,2
68,5,1,1,1,4,4,4
69,6,6,6,6,1,1,1

Facts:
34,55 etc. is athlete number
and 1,2,3,4,5,6 is final position

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs