Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,61 @@
sequence board
integer limit, tries
constant ROW = 1, COL = 2
constant moves = {{-2,-2},{-2,2},{2,-2},{2,2},{-3,0},{3,0},{0,-3},{0,3}}
function solve(integer row, integer col, integer n)
integer nrow, ncol
tries+= 1
if n>limit then return 1 end if
for move=1 to length(moves) do
nrow = row+moves[move][ROW]
ncol = col+moves[move][COL]*3
if nrow>=1 and nrow<=length(board)
and ncol>=1 and ncol<=length(board[row])
and board[nrow][ncol]=' ' then
board[nrow][ncol-1..ncol] = sprintf("%2d",n)
if solve(nrow,ncol,n+1) then return 1 end if
board[nrow][ncol-1..ncol] = " "
end if
end for
return 0
end function
procedure Hopido(sequence s, integer w, integer h)
integer x, y
atom t0 = time()
board = split(s,'\n')
limit = 0
for x=1 to h do
for y=3 to w*3 by 3 do
if board[x][y]='0' then
board[x][y] = ' '
limit += 1
end if
end for
end for
while 1 do
x = rand(h)
y = rand(w)*3
if board[x][y]=' ' then exit end if
end while
board[x][y] = '1'
tries = 0
if solve(x,y,2) then
puts(1,join(board,"\n"))
printf(1,"\nsolution found in %d tries (%3.2fs)\n",{tries,time()-t0})
else
puts(1,"no solutions found\n")
end if
end procedure
constant board1 = """
. 0 0 . 0 0 .
0 0 0 0 0 0 0
0 0 0 0 0 0 0
. 0 0 0 0 0 .
. . 0 0 0 . .
. . . 0 . . ."""
Hopido(board1,7,6)