[Solved] prolog change show answer to print into list

When describing a list, always consider using DCGs. In your case, you can very easily obtain what you want with a few simple modifications to your code: show_result(Squares,MaxRow,MaxCol, List) :- phrase(show_result(Squares,MaxRow,MaxCol,1), List). show_result(_,MaxRow,_,Row) –> { Row > MaxRow }, !. show_result(Squares,MaxRow,MaxCol,Row) –> { phrase(show_result(Squares,MaxRow,MaxCol,Row,1), Line) } , [Line], { Row1 is Row+1 }, show_result(Squares,MaxRow,MaxCol,Row1). show_result(_,_,MaxCol,_,Col) … Read more

[Solved] Prolog Define Predicates [closed]

Try this one 🙂 The main idea is to accumulate number of hours in the predicate min by subtracting 60 from total time and when the total time is lower than 60 we can unify counted hours from accumulator with H variable and rest of time with M variable. minutes(X,H,M):- %main predicate min(X,0,H,M). min(X,H,ResultH,ResultM):- %ending … Read more

[Solved] EndView game on gnu Prolog [closed]

you must get transpose/2 from the other question and replace all_distinct/1 with fd_all_distinct/2. Also, get writeln and replace write here maplist(write, [R1,R2,R3,R4]). edit A simple solution would be to extend the ‘encoding’ of the finite domain, reserving two digits as blanks, instead of just the 0, and extending the logic already seen in answer posted … Read more

[Solved] Check input numbers in prolog

Since you tried something for your isDigit/1 predicate I’ll help about that : Version with an if structure : isDigit(X) :- ( number(X), X >= 0, X =< 8 -> true ; writeln(‘[0-8] AND Number’), fail). Version with a disjunction (as you tried in your OP) : isDigit(X) :- number(X), X >= 0, X =< … Read more