Our 3D CAD supplier models have been moved to 3Dfindit.com, the new visual search engine for 3D CAD, CAE & BIM models.
You can log in there with your existing account of this site.
The content remains free of charge.
Licensed under Creative Commons Attribution-Share Alike 3.0 (Unkown).
하노이의 탑(Tower of Hanoi)은 퍼즐의 일종이다. 세 개의 기둥과 이 기둥에 꽂을 수 있는 크기가 다양한 원판들이 있고, 퍼즐을 시작하기 전에는 한 기둥에 원판들이 작은 것이 위에 있도록 순서대로 쌓여 있다.
게임의 목적은 다음 두 가지 조건을 만족시키면서, 한 기둥에 꽂힌 원판들을 그 순서 그대로 다른 기둥으로 옮겨서 다시 쌓는 것이다.
하노이의 탑 문제는 재귀 호출을 이용하여 풀 수 있는 가장 유명한 예제 중의 하나이다. 그렇기 때문에 프로그래밍 수업에서 알고리즘 예제로 많이 사용한다. 일반적으로 원판이 n개 일 때, 2n -1번의 이동으로 원판을 모두 옮길 수 있다(2n − 1는 메르센 수라고 부른다).
참고로 64개의 원판을 옮기는 데 약 18446744073709551615번을 움직여야 하고, 한번 옮길 때 시간을 1초로 가정했을 때 64개의 원판을 옮기는 데 5849억 4241만 7355년 걸린다.
하노이의 탑은 프랑스의 수학자인 에두아르 뤼카(Édouard Lucas)가 클라우스 교수(professeur N. Claus)라는 필명으로 1883년에 발표하였다. 1년 후 드 파르빌(Henri de Parville)은 Claus가 Lucas의 애너그램임을 밝히면서 다음과 같은 이야기로 하노이의 탑을 소개하였다.
이후 라우즈 볼, 가드너 등이 하노이의 탑을 소개하면서 널리 알려졌다.
이것은 각각의 수를 구하는 컴퓨터 프로그램 등의 실행어에 대한 것이다.
let rec move_tower n a b c = match n with
| 1 -> [(a,c)]
| _ -> (move_tower (n-1) a c b) @ (move_tower 1 a b c) @ (move_tower (n-1) b a c);;
(defun hanoitowers (disc src aux dst)
(cond ((> disc 0)
(hanoitowers (- disc 1) src dst aux)
(princ (list "Move" disc "from" src "to" dst))
(hanoitowers (- disc 1) aux src dst))))
procedure Hanoi(n: integer; from, dest, by: char);
Begin
if (n=1) then
writeln('Move the plate from ', from, ' to ', dest)
else begin
Hanoi(n-1, from, by, dest);
Hanoi(1, from, dest, by);
Hanoi(n-1, by, dest, from);
end;
End;
#include <stdio.h>
void move(int from, int to){
printf("\nMove from %d to %d", from, to);
}
void hanoi(int n, int from, int by, int to){
if (n == 1)
move(from, to);
else{
hanoi(n - 1, from, to, by);
move(from, to);
hanoi(n - 1, by, from, to);
}
}
class hanoi
predicates
hanoi : (unsigned N).
end class hanoi
implement hanoi
domains
pole = string.
clauses
hanoi(N) :- move(N, "left", "centre", "right").
class predicates
move : (unsigned N, pole A, pole B, pole C).
clauses
move(0, _, _, _) :- !.
move(N, A, B, C) :-
move(N-1, A, C, B),
stdio::writef("move a disc from % pole to the % pole\n", A, C),
move(N-1, B, A, C).
end implement hanoi
goal
console::init(),
hanoi::hanoi(4).
위키미디어 공용에 관련 미디어 분류가 있습니다. |
이 글은 컴퓨터 과학에 관한 토막글입니다. 서로의 지식을 모아 알차게 문서를 완성해 갑시다. |
This article uses material from the Wikipedia article "하노이의 탑", which is released under the Creative Commons Attribution-Share-Alike License 3.0. There is a list of all authors in Wikipedia
3d,model,playground,board games,computer,strategy,thinktank