 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
I solved the "towers of hanoi" puzzle using an iterative solver with an
explicit stack inside the bullet physics playground.
Video link
https://www.youtube.com/watch?v=blw8_oLthRQ
Source code
https://github.com/bullet-physics-playground/bpp/blob/master/demo/koppi/hanoi.lua
Happy POVing!
--
koppi
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
hi,
koppi <jak### [at] gmail com> wrote:
> I solved the "towers of hanoi" puzzle using an iterative solver with an
> explicit stack inside the bullet physics playground.
> ... hanoi.lua
the POV-Ray parser can do recursion, any chance of your trying to make a SDL
implementation ?
regards, jr.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 8/16/26 13:48, jr wrote:
> the POV-Ray parser can do recursion, any chance of your trying to make a SDL
> implementation ?
Hi,
attached is the SDL version. Please give it a try.
Best regards,
koppi
Post a reply to this message
Attachments:
Download 'hanoi.pov.txt' (17 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 16/08/2026 13:48, jr wrote:
> hi,
>
> koppi <jak### [at] gmail com> wrote:
>> I solved the "towers of hanoi" puzzle using an iterative solver with an
>> explicit stack inside the bullet physics playground.
>> ... hanoi.lua
>
> the POV-Ray parser can do recursion, any chance of your trying to make a SDL
> implementation ?
>
>
> regards, jr.
>
yes of course.
writing the macro is really very simple. my old project about tower of
hanoi:
// -----------------------------------------
// num : number of disc
// source : string
// dest : string
// helper : string
// -----------------------------------------
#macro tower_of_hanoi(num, source, dest, helper)
#if ( num = 1 )
Display(1,source,dest)
#else
tower_of_hanoi(num - 1, source, helper, dest)
Display(num,source,dest)
tower_of_hanoi(num - 1, helper, dest, source)
#end
#end
invoked in this way:
tower_of_hanoi(NumDisk, "1", "3", "2")
for NumDisk = 5 for exemple, this macro give:
(roman numerals refer to the discs, arabic numerals towers)
For 5 pieces, 31 moves are required.
Sequence :
001 : Move disk I from 1 to 3
002 : Move disk II from 1 to 2
003 : Move disk I from 3 to 2
004 : Move disk III from 1 to 3
005 : Move disk I from 2 to 1
006 : Move disk II from 2 to 3
007 : Move disk I from 1 to 3
008 : Move disk IV from 1 to 2
009 : Move disk I from 3 to 2
010 : Move disk II from 3 to 1
011 : Move disk I from 2 to 1
012 : Move disk III from 3 to 2
013 : Move disk I from 1 to 3
014 : Move disk II from 1 to 2
015 : Move disk I from 3 to 2
016 : Move disk V from 1 to 3
017 : Move disk I from 2 to 1
018 : Move disk II from 2 to 3
019 : Move disk I from 1 to 3
020 : Move disk III from 2 to 1
021 : Move disk I from 3 to 2
022 : Move disk II from 3 to 1
023 : Move disk I from 2 to 1
024 : Move disk IV from 2 to 3
025 : Move disk I from 1 to 3
026 : Move disk II from 1 to 2
027 : Move disk I from 3 to 2
028 : Move disk III from 1 to 3
029 : Move disk I from 2 to 1
030 : Move disk II from 2 to 3
031 : Move disk I from 1 to 3
... but from there on, it's difficult to implement the movement of the
discs to turn it into an animation. I never really found a solution. The
project fell through :(
If anyone has the heart...
--
klp
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 8/17/26 16:39, kurtzlepirate wrote:
> On 16/08/2026 13:48, jr wrote:
>
> invoked in this way:
> tower_of_hanoi(NumDisk, "1", "3", "2")
>
> ... but from there on, it's difficult to implement the movement of the
> discs to turn it into an animation. I never really found a solution. The
> project fell through :(
>
>
> If anyone has the heart...
Did not know, it is possible with macros. Attached is the version with
recursion + animation.
Happy POVing,
koppi
Post a reply to this message
Attachments:
Download 'hanoi-recursive.pov.txt' (8 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
hi,
koppi <jak### [at] gmail com> wrote:
> ... Attached is the version with recursion + animation.
thanks for yesterday's post. the 'pegs' are a little too "bright" perhaps, but
wow, very nice indeed. looking forward to playing with today's code :-), later.
regards, jr.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
hi,
kurtzlepirate <kur### [at] free fr> wrote:
> On 16/08/2026 13:48, jr wrote:
> > ...
> > the POV-Ray parser can do recursion, any chance of your trying to make a SDL
> > implementation ?
> yes of course.
> ... but from there on, it's difficult to implement the movement of the
> discs to turn it into an animation. I never really found a solution. The
> project fell through :(
> If anyone has the heart...
sorry, v nearly forgot.
given we have the moves, which could be put in a csv type file, creating the
animation should not be too difficult from there. lmk please what you think,
would be happy to see if the project can be "resurrected".
regards, jr.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Mathologer episode:
https://www.youtube.com/watch?v=MbonokcLbNo
minimum 1023 moves for the shortest solution.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 8/18/26 12:16, jr wrote:
> thanks for yesterday's post. the 'pegs' are a little too "bright" perhaps, but
> wow, very nice indeed. looking forward to playing with today's code :-), later.
jr, if you could improve the textures / lightning, this would be awesome
(as I do not have the super texturing skills).
Best gregards,
koppi
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 8/18/26 20:56, Bald Eagle wrote:
> Mathologer episode:
>
> https://www.youtube.com/watch?v=MbonokcLbNo
>
> minimum 1023 moves for the shortest solution.
Oh! - And there is even a book about the tower of hanoi problem, will
order it, thanks Bald for sharing!
Best regards,
koppi
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
hi,
koppi <jak### [at] gmail com> wrote:
>...
> jr, if you could improve the textures / lightning, this would be awesome
> (as I do not have the super texturing skills).
that makes two of us </grin>. thanks for the invitation, I hope to get round to
it this week. cheers.
regards, jr.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"jr" <cre### [at] gmail com> wrote:
> that makes two of us </grin>. thanks for the invitation, I hope to get round to
> it this week. cheers.
Hi all,
I have updated the peg shapes and textures.
You can see the video of the 7 disks version here:
https://youtu.be/pzjSfkN2DG4
I also uploaded the hanoi.pov file to GitHub:
https://github.com/koppi/povray-animations
Best regards,
koppi
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |