home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
- { A sample Dada program. Calculates and prints the sequence
- of "hailstone numbers" for a given input. For each term N
- in this series the calculation is done as follows: If N is
- even, the next term is N/2; if N is odd, the next term is
- 3N+1. The calculation ends when N is 1. (Whether or not the
- program halts on all inputs is an interesting question.) }
-
-
- program Hailstone;
-
- var
- N : integer;
- Odd : boolean;
-
- procedure NextTerm;
-
- procedure CheckOdd;
- begin
- if (N mod 2 = 0) then Odd := False else Odd := True
- end;
-
- procedure DownStep;
- begin
- N := N/2
- end;
-
- procedure UpStep;
- begin
- N := 3*N+1
- end;
-
- begin { NextTerm }
- CheckOdd;
- if Odd then UpStep else DownStep
- end;
-
- begin { main program }
- ReadLn N;
- while N > 1 do
- begin
- WriteLn N;
- NextTerm
- end;
- end.
-