Il giorno sab 1 ago 2020 alle ore 09:38 Daniele Zambelli
<daniele.zambe...@gmail.com> ha scritto:
> Il giorno mar 28 lug 2020 alle ore 21:56 maria teresa panunzio 
> <mariateresa.panun...@yahoo.it> ha scritto:
>> Buona serata,
>> chiedo aiuto per capire  perchè una funzione ricorsiva si comporta come un 
>> ciclo infinito.
>> Ieri sera, ho lasciato che il programma andasse in esecuzione e avesse una 
>> notte intera davanti...ahimè stamane era ancora lì.
>> Non ho segnalazioni.
>> grazie a chi mi vorrà suggerire qualche metodo.
>
> Il problema è interessante, ma non ho il tempo per analizzare 300 righe di 
> codice. Riusciresti a mandare un programma funzionante, che riproduce il 
> problema, di poche righe?

Se non ho sbagliato ad interpretare, credo corrisponda a:
```
from kanren import var, lall, lany, membero, eq, run
people = var()
rules = lall(
    # There are 3 people: Giovanni, Berto, Laura
    (eq, (var(), var(), var()), people),
    # Giovanni's house is Splendor or Majestic
    lany(
        (membero, ("Giovanni", "Splendor", var()), people),
        (membero, ("Giovanni", "Majestic", var()), people),
    ),
    # Room 305 is in Splendor house
    (membero, (var(), "Splendor", "305"), people),
    # Berto's house is Beatiful
    (membero, ("Berto", "Beatiful", var()), people),
    # Laura lives in room 406
    (membero, ("Laura", var(), "406"), people),
    # Who lives in house Majestic?
    (membero, (var(), "Majestic", var()), people),
    # Who lives in room 204?
    (membero, (var(), var(), "204"), people),
)
solutions = run(0, people, rules)
solution = list({tuple(sorted(s)) for s in solutions})[0]
for s in solution:
    print(*s)
```

HAND,
㎝

-- 
!!!! THE 🍺-WARE LICENSE (Revision ㊷):
    <㎝🐌🐍.🇮🇹> wrote this 📧. As long as you retain this notice you can
    do whatever you want with this stuff. If we meet some day, and you
    think this stuff is worth it, you can buy me a 🍺 in return. — ㎝
_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python

Rispondere a