Skip to main content
6 of 6
added 1 character in body
user avatar
user avatar

Top 10 contenders:

enter image description here

My approach using Ruby:

num = [1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1]
opr = [3,4,5,6]

#3->+
#4->-
#5->/
#6->*

plc = [1,3,5,7,9,11,13,15]

$i=0

results = []
express = []

while $i < 100000 do
    opr = opr.shuffle

    tempRand=plc.shuffle.take(4)

    num[tempRand[0].to_i] = opr[0]
    num[tempRand[1].to_i] = opr[1]
    num[tempRand[2].to_i] = opr[2]
    num[tempRand[3].to_i] = opr[3]

    tempString = ''

    num.each do |e|

        if e.to_i == 0
            tempString << ''
        elsif e.to_i == 3
            tempString << '+'
        elsif e.to_i == 4
            tempString << '-'
        elsif e.to_i == 5
            tempString << '/'
        elsif e.to_i == 6
            tempString << '*'
        else
            tempString << e.to_s
        end
    end

    results << eval(tempString)
    express << tempString

    num[tempRand[0].to_i] = 0
    num[tempRand[1].to_i] = 0
    num[tempRand[2].to_i] = 0
    num[tempRand[3].to_i] = 0

    $i += 1
end

print_me = Hash[results.zip(express)]

puts print_me.sort.reverse

(try it here)

Basically just randomly swap the 0s (the blank spaces) with operators and then evaluate the result without 0s. It's not the best way to do it, but over a 100,000 iterations the max is 44,944.

user39732