Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fii
:- use_module(library(clpfd)). %for transpose %sort words by length then hand things off to puzsol predicate puzzle_solution(Puz,Ws):- sort_ws(Ws,Ss), puzsol(Puz,Ss). %finished when word list is empty puzsol(_,[]). %solve for one word then recursively for the rest of the words puzsol(Puz,[Le-W|Ws]):- %try first the original then the transpose, each time naming the result P (P=Puz;transpose(Puz,P)), %get a horizontal line member(M,P), %get a slot in the line slot(M,S), slotlength(S,Le), %fill in the slot with this word fill(S,W), %solve for the rest of the words puzsol(P,Ws). %left edge is always a slot because there might not be a # before it. If it IS a # no need to check that because a word won't fit there anyeay slot(L,L). %a slot has anything to the left, a # A, then a var or a non-# B, and consists of B followed by the rest of the line slot(L,[B|C]):- append([_,[A,B],C],L), %check first that A isn't a var so = will not bind the var to # \+var(A), A='#', %any var or non-# can start the slot (var(B);B\='#'). %get length of the slot itself slotlength([],0):- !. slotlength([H|_],0):- \+var(H),H='#',!. slotlength([_|T],Le):- slotlength(T,Le2), Le is Le2+1. %any empty slot can be filled with an empty word, allows words to run up to the rightmost edge fill([],[]). %if the slot is not empty but the word is empty, the very next thing after the word had better be a # fill([H|_],[]):- %check for non-var first so assignment to # is not made \+var(H),H='#'. %copy word into slot from head to tail fill([H|T],[H|T2]):- fill(T,T2). %sort words by length, long to short sort_ws(Ws, Ss):- %assign a key of negative the length so that larger ones will come before smaller ones findall(L-W,(member(W,Ws),length(W,L)),Lws), %do the sort keysort(Lws,Ss).
run
|
edit
|
history
|
help
0
Examen Int Nego 30-mar-21
ARREGLOS
Objeto vació con error de anidación.
2 - codificador JSON If anidados y else ISAN sumas
Tarea2_Tun_Rojas_Diana_Carolina
base de conocimientomiarbol
PROLOG evaluacion
Mora Flores Luis Arturo Codificar árboles de decisión estructurada
1 JSON
industria 2