| I'm curious how well Arc will fare (size, readability) on the "8 Queens" problem. For comparison, here's a naive version I coded in Ruby: def valid? stack
q2 = stack.length - 1
(0..stack.length-2).each do |q1|
return false if stack[q1] == stack[q2] || (q1-q2).abs == (stack[q1]-stack[q2]).abs
end
end
def queens stack, n
if n == 8
puts "[ #{stack.join(', ')} ]"
else
(1..8).each do |rank|
stack.push(rank)
queens(stack, n+1) if valid?(stack)
stack.pop
end
end
end
queens [], 0
Which produces the output: [ 1, 5, 8, 6, 3, 7, 2, 4 ]
[ 1, 6, 8, 3, 7, 4, 2, 5 ]
[ 1, 7, 4, 6, 8, 2, 5, 3 ]
[ 1, 7, 5, 8, 2, 4, 6, 3 ]
[ 2, 4, 6, 8, 3, 1, 7, 5 ]
...
[ 8, 3, 1, 6, 2, 5, 7, 4 ]
[ 8, 4, 1, 3, 6, 2, 7, 5 ]
|