Cvičenie 6

Flag for a country

flag.txt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % WHICH FLAG FOR THE NEW STATE? % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % A small new state has been founded in Europe. A passionate debate about % % its national flag results in the following consensus: The flag consists % % of three horizontal stripes, and the only acceptable colours for these % % stripes are white, green, red and blue. % % % % The combination of these colours is subject to strict conditions. Most % % importantly, no colour may be used for more than one stripe. % % % % It is impossible to use both white and green in the flag. % % % % If green appears in the flag, then the upper stripe must be blue. % % % % The flag may have a red stripe, but only if it also has a white stripe. % % % % If the colour white is used, then the lower stripe must not be blue. % % % % If the colour blue is used, then the upper stripe must not be red. % % % % The flag committee receives three different design proposals, all of % % which comply with the requirements. One ot them is finally accepted. % % The other two have suggested the same colour for the lower stripe. % % % % What will be the colours of the new national flag? % % % % Thus, there are several solutions, and one of them assigns a colour to % % the lower stripe that is different from the colours assigned to the lower % % stripe by any other solutions. There is only one such solution, otherwise % % the problem would be underspecified. % % The most natural approach is to determine all solutions and to let the % % user select the correct one among them. % % Alternatively, a system with sufficient functionality could determine % % the solutions that are unique with respect to the colour of the lower % % stripe. % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Sudoku

Vyriešte sudoku pomocou ASP.

Poznámka: priamočiare zakódovanie sudoku by bolo pomocou predikátu sudoku(X,Y,N), ktorý znamená, že na súradniciach X,Y je číslo N. Tak sa ale trošku ťažšie kontroluje, či sú dve políčka v tom istom "podštvorci". Trošku jednoduchšie sa to kontroluje pri kódovaní ktoré používa predikát sudoku(Xa,Xb,Ya,Yb,N), kde 0 ≤ Xa,Xb,Ya,Yb < 3 a ktorý znamená, že N je na pozícii Xa*3+Xb, Ya*3+Yb (Xa,Ya sú vlastne súradnice podštvorca, a Xb,Yb sú súradnice v rámci toho podštvorca).

Ukážkový vstup: input.txt. input.lp a ešte aj skript txt2dlv.sh, ktorý vie prerobiť textový vstup na logický program (obidva pre prvé kódovanie). Pre druhé kódovanie input2.lp a txt2dlv2.sh.

Vim logo FireFox logo CSS XHTML
Jozef Siska @ KAI FMFI UK YoYo @ KSP KAI (DAI) KSP