36 lines
1 KiB
Text
36 lines
1 KiB
Text
$ include "seed7_05.s7i";
|
|
include "rational.s7i";
|
|
|
|
const func array integer: fractran (in integer: limit, in var integer: number, in array rational: program) is func
|
|
result
|
|
var array integer: output is 0 times 0;
|
|
local
|
|
var integer: index is 1;
|
|
var rational: newNumber is 0/1;
|
|
begin
|
|
output := [] (number);
|
|
while index <= length(program) and length(output) <= limit do
|
|
newNumber := rat(number) * program[index];
|
|
if newNumber = rat(trunc(newNumber)) then
|
|
number := trunc(newNumber);
|
|
output &:= number;
|
|
index := 1;
|
|
else
|
|
incr(index);
|
|
end if;
|
|
end while;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
const array rational: program is []
|
|
(17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1);
|
|
var array integer: output is 0 times 0;
|
|
var integer: number is 0;
|
|
begin
|
|
output := fractran(15, 2, program);
|
|
for number range output do
|
|
write(number <& " ");
|
|
end for;
|
|
writeln;
|
|
end func;
|