See en.wikipedia.org/wiki/Tower_of_Hanoi for a detailed intro, if you're not familiar with this classic recurrence problem.
Set the towers as variables, ahead of calling the function, in the global context:
send::
msg ctx.set (state :JSON)
Now call the recursion:
send::
msg sample.hanoi (disk:Number=3, source="a", dest="b", aux="c")
send::
msg ctx.echo (m)
expect:: (state[="a"] is [4,5])
expect:: (state[="b"] is [0,1,2,3])
This simplistic example would not work, because the parameters are immutable. To be able to mutate the contents of the incoming arguments, you'll need a global scope like we used in the "good" example above, with ctx.set.
send::
msg sample.hanoi.bad (disk:Number=3, source :Array=[..], dest :Array=[..], aux :Array=[..])
You need to log in to post a comment!