Skip to content

Instantly share code, notes, and snippets.

@arjo129
Created June 22, 2017 09:00
Show Gist options
  • Save arjo129/d4d85b7feff2014ae3535349d3cc7bbc to your computer and use it in GitHub Desktop.
Save arjo129/d4d85b7feff2014ae3535349d3cc7bbc to your computer and use it in GitHub Desktop.
------------------------------- 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