TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Solving the Dog-Bunny Puzzle with Program Verification Technology

25 pointsby Darmaniover 2 years ago

3 comments

an1sotropyover 2 years ago
Puzzle in question: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=32884467" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=32884467</a><p>&quot;We use Standard ML, as the language endorsed by a certain breed of university professor who thinks they know programming better than you do.&quot; yikes - that is painfully accurate.
colandermanover 2 years ago
A bit more of a big hammer, but it&#x27;s pretty straightforward with TLA+ as well:<p><pre><code> ---- MODULE DogBunny ---- VARIABLE location Init == location = [ dog |-&gt; &quot;Tree&quot;, bunny1 |-&gt; &quot;House&quot;, bunny2 |-&gt; &quot;Boat&quot; ] Goal == location = [ dog |-&gt; &quot;Bone&quot;, bunny1 |-&gt; &quot;Carrot&quot;, bunny2 |-&gt; &quot;Carrot&quot; ] Occupied(loc) == \E animal \in DOMAIN location: location[animal] = loc Unidir(animal, from, to) == location[animal] = from &#x2F;\ location&#x27; = [ location EXCEPT ![animal] = to ] Bidir(animal, a, b) == Unidir(animal, a, b) \&#x2F; Unidir(animal, b, a) Move(animal) == \&#x2F; Unidir(animal, &quot;Carrot&quot;, &quot;Tree&quot;) \&#x2F; Bidir(animal, &quot;Well&quot;, &quot;Carrot&quot;) &#x2F;\ ~Occupied(&quot;Bone&quot;) \&#x2F; Bidir(animal, &quot;Well&quot;, &quot;Tree&quot;) \&#x2F; Bidir(animal, &quot;Well&quot;, &quot;Flower&quot;) \&#x2F; Bidir(animal, &quot;Tree&quot;, &quot;House&quot;) &#x2F;\ Occupied(&quot;Bone&quot;) &#x2F;\ Occupied(&quot;Flower&quot;) \&#x2F; Unidir(animal, &quot;Flower&quot;, &quot;Boat&quot;) \&#x2F; Bidir(animal, &quot;House&quot;, &quot;Boat&quot;) &#x2F;\ Occupied(&quot;Tree&quot;) \&#x2F; Bidir(animal, &quot;House&quot;, &quot;Bone&quot;) &#x2F;\ Occupied(&quot;Carrot&quot;) \&#x2F; Unidir(animal, &quot;Bone&quot;, &quot;Boat&quot;) Next == \E animal \in DOMAIN location: Move(animal) Invariant == ~Goal ==== </code></pre> with this config file:<p><pre><code> INIT Init NEXT Next INVARIANT Invariant CHECK_DEADLOCK FALSE </code></pre> Finds (presumably) the same solution, with 26 steps.
note89over 2 years ago
Thanks for showing me petri-nets, i have been wanting to learn about them for quite some time. But been to lazy to look it up.