0

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?

closed as too broad by Ismael, Achala Dissanayake, mirg, Richard Horrocks, Lauri Peltonen Apr 23 '18 at 8:30

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

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.