Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %sep_first_col(X,Ost,R) X | Ost (vizuelno) poveke nameneto za R da e vlez a X i Ost izlez
- sep_first_col([X],[Ost],[[X|Ost]]):-!.
- sep_first_col([X|OstX],[Ost|OstRest],[[X|Ost]|OstR]):-sep_first_col(OstX,OstRest,OstR).
- %Za da moze transponirano da se koristi za naoganje na transponiranata matrica
- empty([[]]):-!.
- empty([[]|Ost]):-empty(Ost).
- e_list([]).
- e_list([_|_]).
- transponirano([X],R):-sep_first_col(X,Ost,R),empty(Ost),!. %Ova so empty e za da moze da se napise ?- so nepoznato R
- transponirano([X|Ost],R):-sep_first_col(X,OstT,R),transponirano(Ost,OstT).
- count(_,[],0):-!.
- count(X,[X|Ost],R):-!,count(X,Ost,R1),R is R1+1.
- count(X,[_|Ost],R):-count(X,Ost,R).
- len([],0):-!.
- len([_|Ost],R) :-len(Ost,R1), R is R1+1.
- red_ok(L):-len(L,R),red_ok(L,R).
- red_ok(L,1):-!,count(1,L,1).
- red_ok(L,N):-count(N,L,1),N1 is N-1, red_ok(L,N1).
- redovi_ok([]):-!.
- redovi_ok([X|Ost]):-red_ok(X),redovi_ok(Ost).
- col_ok(L):-transponirano(L,R),redovi_ok(R).
- seci_red([],[[]],0.0,_):-!.
- seci_red(L,[[]|Ost],0.0,Len):-seci_red(L,Ost,Len,Len),!.
- seci_red([X|Ost],[[X|Ost1]|Ost2],N,Len):- N1 is N-1,seci_red(Ost,[Ost1|Ost2],N1,Len).
- seci_red(L,R):-len(L,N1),N is sqrt(N1),seci_red(L,R,N,N).
- seci_redovi([],[]):-!.
- seci_redovi([L|OstL],[R|OstR]):-seci_red(L,R),seci_redovi(OstL,OstR).
- trgni_nivo([],[]):-!.
- trgni_nivo([[X|Ost1]|Ost],[X|OstR]):-trgni_nivo([Ost1|Ost],OstR),!.
- trgni_nivo([[]|Ost],R):-trgni_nivo(Ost,R),!.
- trgni_nivo([X|Ost],R):-not(e_list(X)),trgni_nivo(Ost,R).
- spoi_nadnivo([[]],[]):-!.
- spoi_nadnivo([[]|Ost],R):-spoi_nadnivo(Ost,R),!.
- spoi_nadnivo([[X|Ost]|Ost2],[X|Ost1]):-spoi_nadnivo([Ost|Ost2],Ost1).
- spoi_nadnivoa([],[]):-!.
- spoi_nadnivoa([X|Ost],[R|OstR]):-spoi_nadnivo(X,R),spoi_nadnivoa(Ost,OstR).
- kvadratiziraj(L,R):- seci_redovi(L,L1),transponirano(L1,L2),seci_redovi(L2,R1),trgni_nivo(R1,R2 ),spoi_nadnivoa(R2,R).
- kvad_ok(L):-kvadratiziraj(L,R),redovi_ok(R).
- sudoku_ok(R):-redovi_ok(R),col_ok(R),kvad_ok(R).
- sudoku(L,R):- len(L,Len),LenP is Len+1, gen_sudoku(L,R,LenP),sudoku_ok(R),!.
- gen_sudoku([],[],_).
- gen_sudoku([[a|Ost]|Ost1], [[X|OstR]|OstR1], LenP) :-between(1,LenP,X), gen_sudoku([Ost|Ost1], [OstR|OstR1], LenP).
- gen_sudoku([[]|Ost],[[]|OstR],LenP):- gen_sudoku(Ost,OstR,LenP).
- gen_sudoku( [[X|Ost]|Ost1], [[X|OstR]|OstR1], LenP):- not(X = a), gen_sudoku([Ost|Ost1], [OstR|OstR1], LenP).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement