POV-Ray : Newsgroups : povray.animations : towers of hanoi Server Time
9 Oct 2026 08:45:43 EDT (-0400)
  towers of hanoi (Message 1 to 12 of 12)  
From: koppi
Subject: towers of hanoi
Date: 13 Aug 2026 18:45:10
Message: <6a7e48f6@news.povray.org>
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

From: jr
Subject: Re: towers of hanoi
Date: 16 Aug 2026 07:50:00
Message: <web.6a81a345af6326dc8b21ea1c6cde94f1@news.povray.org>
hi,

koppi <jak### [at] gmailcom> 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

From: koppi
Subject: Re: towers of hanoi
Date: 17 Aug 2026 04:15:30
Message: <6a82c322@news.povray.org>
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)

From: kurtzlepirate
Subject: Re: towers of hanoi
Date: 17 Aug 2026 10:39:34
Message: <6a831d26@news.povray.org>
On 16/08/2026 13:48, jr wrote:
> hi,
> 
> koppi <jak### [at] gmailcom> 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

From: koppi
Subject: Re: towers of hanoi
Date: 18 Aug 2026 00:01:20
Message: <6a83d910@news.povray.org>
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)

From: jr
Subject: Re: towers of hanoi
Date: 18 Aug 2026 06:20:00
Message: <web.6a8430e0af6326dc8b21ea1c6cde94f1@news.povray.org>
hi,

koppi <jak### [at] gmailcom> 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

From: jr
Subject: Re: towers of hanoi
Date: 18 Aug 2026 06:30:00
Message: <web.6a843367af6326dc8b21ea1c6cde94f1@news.povray.org>
hi,

kurtzlepirate <kur### [at] freefr> 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

From: Bald Eagle
Subject: Re: towers of hanoi
Date: 18 Aug 2026 15:00:00
Message: <web.6a84aacaaf6326dc279e2c3d25979125@news.povray.org>
Mathologer episode:

https://www.youtube.com/watch?v=MbonokcLbNo

minimum 1023 moves for the shortest solution.


Post a reply to this message

From: koppi
Subject: Re: towers of hanoi
Date: 19 Aug 2026 15:41:11
Message: <6a8606d7$1@news.povray.org>
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

From: koppi
Subject: Re: towers of hanoi
Date: 19 Aug 2026 16:00:14
Message: <6a860b4e$1@news.povray.org>
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

From: jr
Subject: Re: towers of hanoi
Date: 19 Aug 2026 18:00:00
Message: <web.6a8626e7af6326dcc823645b6cde94f1@news.povray.org>
hi,

koppi <jak### [at] gmailcom> 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

From: koppi
Subject: Re: towers of hanoi
Date: 23 Aug 2026 16:10:00
Message: <web.6a8b536daf6326dcc823645b199194f2@news.povray.org>
"jr" <cre### [at] gmailcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.