How to resolve the algorithm Tau number step by step in the CLU programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Tau number step by step in the CLU programming language
Table of Contents
Problem Statement
A Tau number is a positive integer divisible by the count of its positive divisors.
Show the first 100 Tau numbers. The numbers shall be generated during run-time (i.e. the code may not contain string literals, sets/arrays of integers, or alike).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Tau number step by step in the CLU programming language
Source code in the clu programming language
% Count the divisors of [1..N]
count_divisors = proc (n: int) returns (sequence[int])
divs: array[int] := array[int]$fill(1, n, 1)
for i: int in int$from_to(2, n) do
for j: int in int$from_to_by(i, n, i) do
divs[j] := divs[j] + 1
end
end
return(sequence[int]$a2s(divs))
end count_divisors
% Find Tau numbers up to a given limit
tau_numbers = iter (lim: int) yields (int)
divs: sequence[int] := count_divisors(lim)
n: int := 0
while n < lim do
n := n + 1
if n // divs[n] = 0 then yield(n) end
end
end tau_numbers
% Show the first 100 Tau numbers
start_up = proc ()
po: stream := stream$primary_output()
seen: int := 0
for n: int in tau_numbers(1100) do
seen := seen + 1
stream$putright(po, int$unparse(n), 5)
if seen // 10 = 0 then stream$putl(po, "") end
if seen >= 100 then break end
end
end start_up
You may also check:How to resolve the algorithm Start from a main routine step by step in the zkl programming language
You may also check:How to resolve the algorithm Percolation/Mean run density step by step in the Go programming language
You may also check:How to resolve the algorithm Pisano period step by step in the Julia programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the Joy programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the Python programming language