CrazyEngineers
  • Shell Script for Tower of Hanoi

    Updated: Oct 22, 2024
    Views: 1.0K
    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
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberDec 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
    Are you sure? This action cannot be undone.
    Cancel
  • sarveshgupta

    MemberDec 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
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberDec 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......
    Are you sure? This action cannot be undone.
    Cancel
  • sarveshgupta

    MemberDec 21, 2009

    Ok thanks a lot ! 😁
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register