All things are lawful, but not all things are profitable.
Norm Radder wrote: ...what determines the order of the bases in the calls to solvepuzzle?
Norm Radder wrote:The code needs some comments describing why it is doing things in the order it does them.
Henry Wong wrote:
As a side question, do you know what a Tower of Hanoi puzzle is? I actually once found one years ago in some small quaint town while on vacation. Part of me regrets now buying it, but the other parts know how tedious the solution is, and will never do it the correct way.
There are three kinds of actuaries: those who can count, and those who can't.
Is this how you meant? It completes in 15 moves.Junilu Lacar wrote:To move a tower of 4 disks,....
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
algo was derived from the rule that only a smaller disc could be placed on top of a larger.
There are three kinds of actuaries: those who can count, and those who can't.
You mean to say It should start with this?Piet Souris wrote:Maybe Ganesh can produce an identical drawing, but this time with a randomly ordered pile, performing the exact same moves, just for illustration purpose.
Ganesh Patekar wrote:You mean to say It should start with this?
Ohh! you mean all discs will be on one pole suppose all above discs are on pole 1 but in this order 3 at top then 2 then 4 and at last 1. Am I correct ?Junilu Lacar wrote:Still start with all disks on one pole but not ordered by size
this whole recursion is way too complex for a human to follow, we have no alternative than to believe that it works!
Assuming the subtasks that move 3 disks never breaks the "no larger disk on top of a smaller one" rule
Ganesh Patekar wrote:not easy to understand practically by tracing how these values gets swapped as It uses stacks. It's been more than 7-8 hours I'm trying to understand how these value gets assigned to each other.
Yes sure, I will read It once again.Junilu Lacar wrote:Ging back to my textual description:
I found this one, explained in detail.Study how the recursive calls are made
Campbell Ritchie wrote:Good description but the code style is iffy, and I think there were two mathematical mistakes
I challenge you to find the three things I wasn't happy about.
He did say that factorials were only defined for positive numbers.Ganesh Patekar wrote:. . .
What If n is a negative number, no validation.
That was one of the things I noticed; he missed out 0! = 1. The other thing I noticed was related; I would have used 0 as the base case. In fact I would have said that the factorial is only defined for natural numbers, not integers. Since there is no such thing as a negative natural number, that would have given a simpler definition of the domain of the factorial function.What If n is 0 where 0! =1.
No, I think single‑letter arguments are all right when they do not mean anything special, so n meaning any number is OK. I prefer i, j, k, l, m, n for integers and get told off for not using x, y.Variable name n rather number?
Of course the C chappies like single‑letter names because they can save on keystrokes.Campbell's Colleauges wrote:We're only interested in integers; we can use x and y. We're not writing Fortran.
He was writing C which doesn't have a big integer type builti‑in. My problem with the code was the use of return twice, when you can save lots of keystrokes with the ?: operator. I tried some C on Friday, so I should be able to find it and post it here. It's on a different computer, so please wait few minutes for that code. The unsigned keyword doesn't exist in Java®, but it prevents you from using negative numbers. I shall let you work out what −64 means.Return type should have been double Or BigInteger.
I shall let you explain the output for 64! and 66! and −64!Campbell's Computer wrote:[critchie@computer CPrograms]$ gcc -o factorial factorial.c
[critchie@computer CPrograms]$ ./factorial 66
66! = 0
[critchie@computer CPrograms]$ ./factorial 64
64! = 9223372036854775808
[critchie@computer CPrograms]$ ./factorial 21
21! = 14197454024290336768
[critchie@computer CPrograms]$ ./factorial -64
[“forgot” to quote output ]
My, my, aren't you a big fella. Here, have a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|