Trying to create a Tower of Hanoi algorithm using Solidity. I come from Java background, and I'm having trouble to figure where to start. For example, would you write the whole thing in one contract? Any tips?


In Ethereum you pay for each executed instruction when executing a function in a smart contract. And since the solution of the Tower of Hanoi has exponential running time in the number of disks, you will quickly run out of gas. The current Ethereum gas limit is 5.4m, so you will hit that limit around 18 or 19 disks. For algorithms to solve Tower of Hanoi, you can have a look at: https://www.hackerearth.com/blog/algorithms/tower-hanoi-recursion-game-algorithm-explained/

How would you get the return value through a Ethereum client console? I would store the return value in a constant in the contract (as a field of the contract) and then have a method that can return this value.

And, yes, I would write the whole thing in one contract. But I would run it on a private blockchain since it might become expensive to actually publish and run this Tower of Hanoi contract.

Not the answer you're looking for? Browse other questions tagged or ask your own question.