spark_mode/src/logic.adb

45 lines
835 B
Ada

package body Logic is
-- @name Step
-- @return
-- @parameter N:Natural
-- @parameter O:Natural
-- @description Do one calculation step and safe the result to O.
procedure Step (N : Natural; O : out Natural) is
begin
if N mod 2 = 0 then
O := N / 2;
else
O := 3 * N + 1;
end if;
end Step;
-- @name Row
-- @return
-- @parameter N:Natural,Final
-- @description Calculate full row for design.
procedure Row (N : Natural; Final : out Natural) is
Old : Natural := N;
Update : Natural;
begin
while (Old < (Natural'Last / 3)) and (not (Old = 1)) loop
Step (Old, Update);
Old := Update;
end loop;
if not (Old = 1) then
Old := 1;
end if;
Final := Old;
end Row;
end Logic;