fork(1) download
  1. # your code goes here
  2. def hanoi(disc, ori, dest, aux):
  3. if disc == 1:
  4. print('Move disc {} from tower {} to the tower {}'.format(disc, ori, dest))
  5. return
  6.  
  7. hanoi(disc - 1, ori, aux, dest)
  8. print('Move disc {} from tower {} to the tower {}'.format(disc, ori, dest))
  9. hanoi(disc - 1, aux, dest, ori)
  10.  
  11. hanoi(3, 'A', 'B', 'C')
Success #stdin #stdout 0.02s 9112KB
stdin
Standard input is empty
stdout
Move disc 1 from tower A to the tower B
Move disc 2 from tower A to the tower C
Move disc 1 from tower B to the tower C
Move disc 3 from tower A to the tower B
Move disc 1 from tower C to the tower A
Move disc 2 from tower C to the tower B
Move disc 1 from tower A to the tower B