Shell Script for Tower of Hanoi

sarveshgupta

sarveshgupta

@sarveshgupta-txtmu5 Oct 22, 2024
hello CEans

Can anyone please help with a shell script for Tower of Hanoi ? 😕

as we cannot pass parameters to functions in Linux please tell a program in c/c++ otherwise but without use of recursion so that it can be translated into Linux shell script syntax

Thanks

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Dec 21, 2009

     #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
       int n, x;
       printf( "How many disks? " );
       scanf( "%d", &n );
       printf("\n");
       for (x=1; x < (1 << n); x++)
          printf( "move from tower %i to tower %i.\n",
             (x&x-1)%3, ((x|x-1)+1)%3 );
    return 0;
    }
    This is not my creation ..hope it will help you
  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Dec 21, 2009

    thanks a lot goyal

    But you are sure that it will work! so can i use it directly without checking as i have the exam tomorrow itself

    Also can you explain it a little bit what is the code doing by taking an example of 3 disks
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Dec 21, 2009

    sorry ...i can't explain you..but i am sure it will work...I have tested it...
    as it is not created by me......
  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Dec 21, 2009

    Ok thanks a lot ! 😁