XIX . , , . , . , .
|
|
[]
, 1883 [1] . « (Claus) -- (Li-Sou-Stian)»[1] , (Lucas) - (Saint Louis).
[]
. , . , . . ( , , «» , : , .)
[]
| . |
, , . , . , . Bell Labs . , 2632058.
. N . N, ( G(0)), ( G(i) G(i+1)). I- I- ( , ). , I I- . , , , ( ). , , : N , f->t->r->f->t->r-> ( f- , t- , r- ), N , f->r->t->f->r->t->
C++:
// #include <iostream> using namespace std; void hanoi_towers(int quantity, int from, int to, int buf_peg) //quantity- , from- (1-3),to- (1-3) { //buf_peg - (1-3) if (quantity != 0) { hanoi_towers(quantity-1, from, buf_peg, to); cout << from << " -> " << to << endl; hanoi_towers(quantity-1, buf_peg, to, from); } } int main() { setlocale(LC_ALL,"rus"); int start_peg, destination_peg, buffer_peg, plate_quantity; cout << " :" << endl; cin >> start_peg; cout << " :" << endl; cin >> destination_peg; cout << " :" << endl; cin >> buffer_peg; cout << " :" << endl; cin >> plate_quantity; hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg); return 0; }
program hanoi-bns(input,output); var n:integer; procedure tower(k:integer;a,b,c:char); begin if k>1 then tower(k-1,a,c,b); writeln('from ',a,' to ',b); if k>1 then tower(k-1,c,b,a) end; begin read(n); tower(n,'A','C','B') end.
def Hanoi(n, A, C, B): if n != 0: Hanoi(n - 1, A, B, C) print 'Move the plate from', A, 'to', C Hanoi(n - 1, B, C, A)
#include <stdio.h> #include <math.h> void carryingOver(int, int, int); main() { int number, countDisk, counter = 1, count; printf(" : "); /* */ scanf("%d", &number); while (counter <= pow(2, number) - 1) { /* */ if (counter % 2 != 0) { /* */ printf("%3d %d ", counter, 1); carryingOver(number, counter, 1); /* */ } else { /* */ count = counter; countDisk = 0; while (count % 2 == 0) { /* */ countDisk++; /* 2 */ count = count / 2; } printf("%3d %d ", counter, countDisk + 1); carryingOver(number, counter, countDisk + 1); } counter++; } return 0; } /* */ void carryingOver(int n ,int i, int k) { int t, axisX, axisY, axisZ; if (n % 2 == 0) { /* */ axisX = 1; /* */ axisY = 2; axisZ = 3; } else { axisX = 1; axisY = 3; axisZ = 2; } /* */ /* */ /* k */ t = ((i / pow(2, k - 1)) - 1) / 2; if (k % 2 != 0) { /* */ switch (t % 3) { /* */ case 0: printf("%d -> %d\n", axisX, axisY); break; case 1: printf("%d -> %d\n", axisY, axisZ); break; case 2: printf("%d -> %d\n", axisZ, axisX); break; } } else { /* */ switch (t % 3) { case 0: printf("%d -> %d\n", axisX, axisZ); break; case 1: printf("%d -> %d\n", axisZ, axisY); break; case 2: printf("%d -> %d\n", axisY, axisX); break; } } }
.
[]
, , , , , 3 , . -, , . , 64 . 64 , , .
64 , , , .
.
, , 18 446 744 073 709 551 615. , , , 580 .
, , .
[]
" " ("Now Inhale")[2] 64 . - , , . "-" , " " .
[]
[]

