Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Tau-function/Pascal/tau-function.pas
Normal file
43
Task/Tau-function/Pascal/tau-function.pas
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
program tauFunction(output);
|
||||
|
||||
type
|
||||
{ name starts with `integer…` to facilitate sorting in documentation }
|
||||
integerPositive = 1..maxInt value 1;
|
||||
{ the `value …` will initialize all variables to this value }
|
||||
|
||||
{ returns Boolean value of the expression divisor ∣ dividend ----------- }
|
||||
function divides(
|
||||
protected divisor: integerPositive;
|
||||
protected dividend: integer
|
||||
): Boolean;
|
||||
begin
|
||||
{ in Pascal, function result variable has the same name as function }
|
||||
divides := dividend mod divisor = 0
|
||||
end;
|
||||
|
||||
{ returns τ(i) --------------------------------------------------------- }
|
||||
function tau(protected i: integerPositive): integerPositive;
|
||||
var
|
||||
count, potentialDivisor: integerPositive;
|
||||
begin
|
||||
{ count is initialized to 1 and every number is divisible by one }
|
||||
for potentialDivisor := 2 to i do
|
||||
begin
|
||||
count := count + ord(divides(potentialDivisor, i))
|
||||
end;
|
||||
|
||||
{ in Pascal, there must be exactly one assignment to result variable }
|
||||
tau := count
|
||||
end;
|
||||
|
||||
{ === MAIN ============================================================= }
|
||||
var
|
||||
i: integerPositive;
|
||||
f: string(6);
|
||||
begin
|
||||
for i := 1 to 100 do
|
||||
begin
|
||||
writeStr(f, 'τ(', i:1);
|
||||
writeLn(f:8, ') = ', tau(i):5)
|
||||
end
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue