Created
June 22, 2017 09:00
-
-
Save arjo129/d4d85b7feff2014ae3535349d3cc7bbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------- MODULE hanoi ------------------------------- | |
EXTENDS Integers, Sequences | |
\* Towers of hanoi problem | |
VARIABLES tower1, tower2, tower3 | |
\* Initiallize the towers | |
Init == /\ tower1 = <<3,2,1,0>> | |
/\ tower2 = <<0>> | |
/\ tower3 = <<0>> | |
\* Transition rules | |
move(from,to,helper) == | |
IF Len(from) /= 0 /\ Len(to) /= 0 THEN | |
IF Head(from) > Head(to) | |
THEN /\ to' = <<Head(from)>> \o to | |
/\ from' = Tail(from) | |
/\ helper' = helper | |
ELSE to' = to /\ from' = from /\ helper' = helper | |
ELSE to' = to /\ from' = from /\ helper' = helper | |
\* Next states | |
Next == \/ move(tower1,tower2,tower3) | |
\/ move(tower2,tower1,tower3) | |
\/ move(tower1,tower3,tower2) | |
\/ move(tower3,tower1,tower2) | |
\/ move(tower3,tower2,tower1) | |
\/ move(tower2,tower3,tower1) | |
\* Terminal state | |
TerminalState == tower3 /= <<3,2,1,0>> | |
============================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment