# Enter your code here. Read input from STDIN. Print output to STDOUT s = Array.new(3) for s_i in (0..2) s_t = gets.strip s[s_i] = s_t.split(' ').map(&:to_i) end s = s.inject(:+) #=begin mag_squares = [ [8, 1, 6, 3, 5, 7, 4, 9, 2], [6, 1, 8, 7, 5, 3, 2, 9, 4], [4, 3, 8, 9, 5, 1, 2, 7, 6], [2, 7, 6, 9, 5, 1, 4, 3, 8], [2, 9, 4, 7, 5, 3, 6, 1, 8], [4, 9, 2, 3, 5, 7, 8, 1, 6], [6, 7, 2, 1, 5, 9, 8, 3, 4], [8, 3, 4, 1, 5, 9, 6, 7, 2] ] #=begin for i in (0..mag_squares.length - 1) #print mag_squares[i].inject(:+).sort #mag_squares[i].each do |row| #print "#{row} #{row.inject(:+)}\n" #end #puts " " end #=end arr1_9 = [1, 2, 3, 4, 5, 6, 7, 8, 9] costs = [] for i in (0..mag_squares.length - 1) cost = 0 for k in 0..mag_squares[i].length - 1 if s[k] > mag_squares[i][k] cost += s[k] - mag_squares[i][k] elsif s[k] < mag_squares[i][k] cost += mag_squares[i][k] - s[k] end end costs << cost #if (arr1_9 <=> s.sort) == 1 #costs[i] = mag_squares[i] - s #end #if (arr1_9 <=> s.sort) == -1 #costs[i] = s - mag_squares[i] #end #mag_squares[i].each { |num| print "#{num} " } #puts " " #puts mag_squares[i].sort <=> s.sort end #costs.each { |num| print "#{num} " } #puts " " #s.each { |num| print "#{num} " } # matrix output test print costs.min #=end =begin arr1_9 = [1, 2, 3, 4, 5, 6, 7, 8, 9] s = s.inject(:+).sort print s puts " " #print arr_9 puts arr_9 <=> s =end