Deutsch   English   Français   Italiano  
<sgkue5$hu3$1@gioia.aioe.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.misty.com!eternal-september.org!reader02.eternal-september.org!aioe.org!wWi+bf82x/J4IG13ZEtRgw.user.46.165.242.75.POSTED!not-for-mail
From: Samuel DEVULDER <samuel_dot_devulder@laposte_dot_net.invalid>
Newsgroups: fr.sci.maths
Subject: Re: Sugurus
Date: Tue, 31 Aug 2021 11:57:26 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgkue5$hu3$1@gioia.aioe.org>
References: <61291b21$0$21601$426a74cc@news.free.fr>
 <slrnsikqbh.2ai.sc@scarpet42p.localdomain>
 <sgdrre$8rg$1@cabale.usenet-fr.net> <sgkle5$ko$1@gioia.aioe.org>
 <sgklt3$7lk$1@gioia.aioe.org> <sgkphb$1g1$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="18371"; posting-host="wWi+bf82x/J4IG13ZEtRgw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
 Thunderbird/91.0.3
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 210830-8, 30/8/2021), Outbound message
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
Bytes: 3676
Lines: 86

Le 31/08/2021 à 10:33, Samuel DEVULDER a écrit :
> 
> Bref, cela s'encode très bien sous la forme de prédicats Prolog, par 
> exemple là:
> https://pastebin.com/sKq1DRMk
> 
> Le code Prolog est généré par ce script Lua que j'ai écrit rapidement(il 
> est archi perfectible et ne m'aide qu'à expérimenter):
> https://pastebin.com/uATrbBUD

Erratum, j'ai pasté une mauvaise version, voici la bonne version du 
générateur:

	https://pastebin.com/uX9vz7Lu

qui donne ce genre de fichier Prolog:

----8<--------------------------------------------------------------
eq(X,X).
ne(X,X):-!,fail.
ne(_,_).
ex(_,[]).
ex(X,[X|_]):-!,false.
ex(X,[_|L]):-ex(X,L).
in(X,[X|L],L).
in(X,[Y|L],[Y|M]):-in(X,L,M).
match([],[]).
match([X|L],Q):-in(X,Q,M),match(L,M).
suguru([
[V1_1,V1_2,V1_3],
[V2_1,V2_2,V2_3],
[V3_1,V3_2,V3_3]]) :-
	eq(V1_1, 1),
	match([V1_2,V1_3], [1,2]),
	match([V2_1,V3_1], [2,3]),
	match([V2_2,V2_3,V3_2,V3_3], [1,2,3,4]),
	ex(V1_2, [V2_2,V2_3]),
	ex(V1_3, [V2_3]),
	ex(V1_1, [V1_2,V2_2]),
	ex(V2_1, [V2_2,V1_2,V3_2]),
	ex(V3_1, [V3_2,V2_2]),
	ex(V2_2, [V1_3]),
	true.
describe:-write('solving...\n'),
	write('+---+---+---+\n'),
	write('| 1 |       |\n'),
	write('+   +---+---+\n'),
	write('|   |       |\n'),
	write('+   +   +   +\n'),
	write('|   |       |\n'),
	write('+---+---+---+\n'),
	true.
w([]).
w([X|L]):-write(X),write('\n'),w(L).
r:-reconsult(suguru).
h:-halt.
x:-describe,time(suguru(L)),w(L).
----8<--------------------------------------------------------------

Qui se résout très facilement:

----8<--------------------------------------------------------------
$ lua suguru.lua  > suguru.pl && swipl -s suguru.pl -t "x,fail;h"
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 7.2.3)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

solving...
+---+---+---+
| 1 |       |
+   +---+---+
|   |       |
+   +   +   +
|   |       |
+---+---+---+
% 1,162 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
[1,2,1]
[3,4,3]
[2,1,2]
% 32 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
----8<--------------------------------------------------------------

sam.