def power arr, pow total = 0; arr.each {|x| total = total + x ** pow } return total end pair = [[1,4], [2,3]] start = [4,8,16] start.length.times do |i| n = pair[0].length n.times do |j| pair[0][n+j] = start[i] + pair[1][j] pair[1][n+j] = start[i] + pair[0][j] end end def cancel arr1, arr2 arr1.length.times do |i| arr2.length.times do |j| if arr1[i] == arr2[j] arr2.delete_at j arr1.delete_at i cancel arr1, arr2 break end end end end pair[0].sort!.delete_if {|x| x == 0} pair[1].sort!.delete_if {|x| x == 0} cancel pair[0], pair[1] puts "" puts "" puts "Sum Of Powers Equations" puts "" puts "" puts "" puts "" start.length.times do |i| puts "" pair[0].length.times do |j| puts "" end puts "" puts "" pair[1].length.times do |j| puts "" end puts "" end puts "
", pair[0][j],"", i+1, "", "", power(pair[0], i+1), "", power(pair[1], i+1), "", pair[1][j],"", i+1, "", "
" puts "" puts ""