[Challenge] Who wants a challenge?

Cool …

1 Like

Filter?

Refactored slightly:

``````from functools import lru_cache

@lru_cache(maxsize=None)
def hanoi(n, a, b, c):
if n == 0:
return ()
return hanoi(n-1, a, c, b) + ((a, b),) +  hanoi(n-1, c, b, a)
``````

Very nice though :3

If anyone wants an explanation of how that works:
Moving the whole tower can be done by moving all rings but the last to the auxiliary peg, then moving the bottom ring to the destination peg, and finally placing the rings that were placed on the auxiliary peg onto the destination peg.

That algorithm relies on being able to move multiple rings at once, and to do that it uses itself, because that’s what this algorithm does!

An important detail is that to move an empty tower, no moves are required.

1 Like

Do you know how to produce them manually? Writing down the code is a lot like writing down your manual process, is it not? I’ve got a similar problem in mind if you want it!

Haha, that was the hardest part of the problem, actually working with the tuples, which is a bit tedious. I just didn’t quite find a way to do it right, so I just kept on fixing until it worked (without refactoring at the end). This might be a bit better .

It’s not ‘Tribonacci’ is it?

Noo but it’s iterative, involving two numbers and has a nice story to go with it!

Nothing really comes to mind. I’ll just have to wait then.

I guess I’ll try it…

What’s that?

Same as Fibonacci, but we the tree previous numbers instead.
See here.

2 Likes

Okay, here goes!

If a chessboard were to have wheat placed upon each square such that one grain were placed on the first square, two on the second, four on the third, and so on (doubling the number of grains on each subsequent square), how many grains of wheat would be on the chessboard at the finish?

Here’s one version of the story: http://www.singularitysymposium.com/exponential-growth.html

So… what do you want me to do? I could use Python to print all of the numbers, but I think it would crash every computer it’s run on…

I want to know the total number of wheat that would have to be placed on the chess board to meet the described requirement. We can describe very large numbers, even if we can’t quite imagine the quantity!

No, try it! It won’t

…on the sixty fourth square the king would have had to put more than 18,000,000,000,000,000,000 grains of rice which is equal to about 210 billion tons and is allegedly sufficient to cover the whole territory of India with a meter thick layer of rice.

So I don’t think I need to do all the Math
I’m top of my class, but SERIOUSLY? My head will explode! (So will my computer…)

EDIT: Overall it’s 9,223,372,036,854,775,808 grains.

You can even do it in one line, for any size of the board.

If you think that’s the case, then you take this challenge!

Nahh. You do it! You wanted a challenge, right