Basic Pascal Tutorial/Chapter 4/Solution/ja
Sent here from Solution 4/ja.
English · Français · Български · 中文(中国) · 日本語
4Ga - ハノイの塔の解答例 (著者: Tao Yue, 状態: 原文のまま変更なし)
(* 著者: Tao Yue
日付: 13 July 2000
記述:
ハノイの塔の解答
Version:
1.0 - original version
*)
program TowersofHanoi;
var
numdiscs : integer;
(********************************************************)
procedure DoTowers (NumDiscs, OrigPeg, NewPeg, TempPeg : integer);
(* 変数の説明:
Number of discs -- OrigPegに載っている円盤の数
OrigPeg -- 塔の棒の数
NewPeg -- 塔から移動させる棒のナンバー
TempPeg -- 一時的に置いておくために使う棒のナンバー
*)
begin
(* 最初のベースの場合を処理する -- 1つの円盤 *)
if NumDiscs = 1 then
writeln (OrigPeg, ' ---> ', NewPeg)
(* 他のすべての場合を処理する *)
else
begin
(* 最初に一番下の円盤以外の全てを TempPeg に移動させる。その際には NewPeg を一時保存の棒として使う *)
DoTowers (NumDiscs-1, OrigPeg, TempPeg, NewPeg);
(* 次に一番下の円盤を OrigPeg から NewPeg に動かす*)
writeln (OrigPeg, ' ---> ', NewPeg);
(* 最後に一時的に TempPeg にある円盤を NewPeg に動かす。その移動の際、OrigPeg を一時的な棒として使う *)
DoTowers (NumDiscs-1, TempPeg, NewPeg, OrigPeg)
end
end;
(********************************************************)
begin (* Main *)
write ('Please enter the number of discs in the tower ===> ');
readln (numdiscs);
writeln;
DoTowers (numdiscs, 1, 3, 2)
end. (* Main *)| previous | contents | next |
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Solution/ja", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 3 people, 2015–2022
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Derakun | Created page | |
| Trev | Fixed syntax highlighting (minor) | |
| Kai Burghardt | Kai Burghardt moved page Solution 4/ja to Basic Pascal Tutorial/Chapter 4/Solution/ja: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Clut... (minor) | |
| Kai Burghardt | bypass redirects [cf. discussion] | |
| Kai Burghardt | bypass [previously missed] redirect [cf. discussion] | |
| Kai Burghardt | bypass language bar/categorization template redirect [cf. discussion] (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
