/* iGASM Example */ /* "Towers of Hanoi". */ FUNCTIONS agent : Number; goal : Number -> Number; st : String -> Stack; fromPole, toPole, auxPole : Number -> String; INITIAL goal(1) := 7; fromPole(1) := "left"; toPole(1) := "right"; auxPole(1) := "middle"; agent := 1; st("right") := emptyStack; st("middle") := emptyStack; st("left") := stPush(stPush(stPush(stPush(stPush(stPush(stPush(emptyStack, 7), 6), 5), 4), 3), 2), 1); RULES IF goal(agent) = 0 THEN agent := agent - 1; ELSEIF goal(agent) != stTop(st(fromPole(agent))) THEN agent := agent + 1; goal(agent+1) := goal(agent) - 1; fromPole(agent+1) := fromPole(agent); toPole(agent+1) := auxPole(agent); auxPole(agent+1) := toPole(agent); ELSE st(fromPole(agent)) := stPop( st(fromPole(agent))); st(toPole(agent)) := stPush( st(toPole(agent)), goal(agent) ); goal(agent) := goal(agent) - 1; fromPole(agent) := auxPole(agent); auxPole(agent) := fromPole(agent); writeln := frompole(agent)+" -> "+toPole(agent); ENDIF FINAL goal(agent) = undef;