Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- 2011may20 -- http://angg.twu.net/LUA/8queens.lua.html -- http://angg.twu.net/LUA/8queens.lua -- (find-angg "LUA/8queens.lua") toxy = function (s) return s:byte(1, 1)-64, s:sub(2)+0 end toan = function (x, y) return string.char(64+x)..(y+0) end attack = function (an1, an2) local x1, y1 = toxy(an1) local x2, y2 = toxy(an2) local dx, dy = x2-x1, y2-y1 return dx==0 or dy==0 or dx==dy or dx==-dy end settest = function (x, y) an[x] = toan(x, y) for i=1,x-1 do if attack(an[i], an[x]) then return false end end return true end an = {} for y1=1,8 do if settest(1, y1) then for y2=1,8 do if settest(2, y2) then for y3=1,8 do if settest(3, y3) then for y4=1,8 do if settest(4, y4) then for y5=1,8 do if settest(5, y5) then for y6=1,8 do if settest(6, y6) then for y7=1,8 do if settest(7, y7) then for y8=1,8 do if settest(8, y8) then print(table.concat(an, " ")) end end end end end end end end end end end end end end end end --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "8queens.lua" --]]