Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Mayan-numerals/CLU/mayan-numerals.clu
Normal file
50
Task/Mayan-numerals/CLU/mayan-numerals.clu
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
% This program must be linked with PCLU's "misc.lib" and "useful.lib"
|
||||
|
||||
base20 = proc (n: bigint) returns (sequence[int])
|
||||
own zero: bigint := bigint$i2bi(0)
|
||||
own twenty: bigint := bigint$i2bi(20)
|
||||
if n=zero then return(sequence[int]$[0]) end
|
||||
|
||||
digits: array[int] := array[int]$[]
|
||||
while n>zero do
|
||||
array[int]$addl(digits, bigint$bi2i(n//twenty))
|
||||
n := n/twenty
|
||||
end
|
||||
return(sequence[int]$a2s(digits))
|
||||
end base20
|
||||
|
||||
mayan = proc (digits: sequence[int]) returns (string)
|
||||
own parts: array[string] := array[string]$[0:
|
||||
" ", " . ", " .. ", "... ", "....", "----"
|
||||
]
|
||||
% generate edges
|
||||
edge: stream := stream$create_output()
|
||||
for i: int in int$from_to(1, sequence[int]$size(digits)) do
|
||||
stream$puts(edge, "+----")
|
||||
end
|
||||
stream$putl(edge, "+")
|
||||
|
||||
% generate digits
|
||||
lines: stream := stream$create_output()
|
||||
for i: int in int$from_to_by(15, 0, -5) do
|
||||
for d: int in sequence[int]$elements(digits) do
|
||||
p: int := d-i
|
||||
if p<0 then p:=0 end
|
||||
if p>5 then p:=5 end
|
||||
if i=0 & p=0
|
||||
then stream$puts(lines, "| @ ")
|
||||
else stream$puts(lines, "|" || parts[p])
|
||||
end
|
||||
end
|
||||
stream$putl(lines, "|")
|
||||
end
|
||||
|
||||
s_edge: string := stream$get_contents(edge)
|
||||
return(s_edge || stream$get_contents(lines) || s_edge)
|
||||
end mayan
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
n: bigint := bigint$parse(sequence[string]$bottom(get_argv()))
|
||||
stream$puts(po, mayan(base20(n)))
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue