Cvičenie 11

Vyriešte logickú úlohu Double Arrow z minuloročnej sútťaže INTERLOS. Zadanie je medzi zadaniami úloh z prvej sady s názvom "L3 Double Arrows" na 6. strane.

Zadanie z pdf je prepísané tu:

da.in
   0  1  2  3  4  5  6  7  8  9  10  11
 0             dr
 1                          d
 2        4  4  9  5  7  6  7  5 dl
 3        7  5  4  8  6  5  8  5      l
 4        7  6  5  2 10  4  6  8
 5    dr  6  4  3  2  2  5  5  4
 6    ur  7  6  6  4  5  3 10  7
 7        6  8  8  6  9  6  8 11
 8        4  1  3  4  5  4  4  1
 9        6  4  4  5  9  5  6  5
10              u
11                          u

Zakódované v LP by mohlo vyzerať napríklad takto (samotná tabuľka čísel začína na riadku/stĺpci 2, aby sa ľahšie pracovalo so šípkami):

da_in.lp
count(2,2,4).
count(2,3,4).
count(2,4,9).
count(2,5,5).
count(2,6,7).
count(2,7,6).
count(2,8,7).
count(2,9,5).
count(3,2,7).
count(3,3,5).
count(3,4,4).
count(3,5,8).
count(3,6,6).
count(3,7,5).
count(3,8,8).
count(3,9,5).
count(4,2,7).
count(4,3,6).
count(4,4,5).
count(4,5,2).
count(4,6,10).
count(4,7,4).
count(4,8,6).
count(4,9,8).
count(5,2,6).
count(5,3,4).
count(5,4,3).
count(5,5,2).
count(5,6,2).
count(5,7,5).
count(5,8,5).
count(5,9,4).
count(6,2,7).
count(6,3,6).
count(6,4,6).
count(6,5,4).
count(6,6,5).
count(6,7,3).
count(6,8,10).
count(6,9,7).
count(7,2,6).
count(7,3,8).
count(7,4,8).
count(7,5,6).
count(7,6,9).
count(7,7,6).
count(7,8,8).
count(7,9,11).
count(8,2,4).
count(8,3,1).
count(8,4,3).
count(8,5,4).
count(8,6,5).
count(8,7,4).
count(8,8,4).
count(8,9,1).
count(9,2,6).
count(9,3,4).
count(9,4,4).
count(9,5,5).
count(9,6,9).
count(9,7,5).
count(9,8,6).
count(9,9,5).

arr(0,4,dr).
arr(1,8,d).
arr(2,10,dl).
arr(3,11,l).
arr(5,1,dr).
arr(6,1,ur).
arr(10,4,u).
arr(11,8,u).

Riešenie

yoyo@tableta 11 $ time dlv da_in.lp arr.lp -pfilter=arr
DLV [build BEN/Oct 11 2007   gcc 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]

{arr(0,4,dr), arr(1,8,d), arr(2,10,dl), arr(3,11,l), arr(5,1,dr), arr(6,1,ur),
arr(10,4,u), arr(11,8,u), arr(0,2,dr), arr(0,5,dr), arr(0,7,dr), arr(1,3,dr),
arr(1,4,dr), arr(1,6,dr), arr(1,7,dr), arr(2,1,dr), arr(3,0,dr), arr(4,1,dr),
arr(8,1,dr), arr(0,3,d), arr(0,9,d), arr(1,2,d), arr(0,6,dl), arr(0,8,dl),
arr(1,5,dl), arr(1,9,dl), arr(4,10,dl), arr(5,11,dl), arr(2,11,l), arr(4,11,l),
arr(6,10,l), arr(7,10,l), arr(7,11,l), arr(9,10,l), arr(5,0,ur), arr(8,0,ur),
arr(9,1,ur), arr(10,5,ur), arr(10,8,ur), arr(11,2,ur), arr(11,3,ur),
arr(11,4,ur), arr(11,5,ur), arr(11,7,ur), arr(10,2,u), arr(10,6,u), arr(11,6,u),
arr(2,0,r), arr(3,1,r), arr(4,0,r), arr(6,0,r), arr(7,0,r), arr(7,1,r),
arr(9,0,r), arr(3,10,ul), arr(5,10,ul), arr(6,11,ul), arr(8,10,ul),
arr(8,11,ul), arr(9,11,ul), arr(10,3,ul), arr(10,7,ul), arr(10,9,ul),
arr(11,9,ul)}

real    0m0.115s
user    0m0.108s
sys     0m0.001s
Vim logo FireFox logo CSS XHTML
Jozef Siska @ KAI FMFI UK YoYo @ KSP KAI (DAI) KSP