38 lines
982 B
Text
38 lines
982 B
Text
program mayan_numerals;
|
|
loop for n in [4005, 8017, 326205, 886205, 18380658207197784] do
|
|
print(str n + ":");
|
|
print(mayan(n));
|
|
end loop;
|
|
|
|
proc mayan(n);
|
|
carts := [cartouche(d) : d in to_base20(n)];
|
|
topbtm := '+----' * #carts + '+\n';
|
|
lines := [+/['|' + c(l) : c in carts] + '|\n' : l in [1..4]];
|
|
return topbtm +/ lines + topbtm;
|
|
end proc;
|
|
|
|
proc cartouche(n);
|
|
parts := {
|
|
[0, ' '],
|
|
[1, ' . '],
|
|
[2, ' .. '],
|
|
[3, '... '],
|
|
[4, '....'],
|
|
[5, '----']
|
|
};
|
|
|
|
cart := [parts((n-m) min 5 max 0) : m in [15,10,5,0]];
|
|
if n=0 then cart(4) := ' @ '; end if;
|
|
return cart;
|
|
end proc;
|
|
|
|
proc to_base20(n);
|
|
if n=0 then return [0]; end if;
|
|
ds := [];
|
|
loop while n>0 do
|
|
ds := [n mod 20] + ds;
|
|
n div:= 20;
|
|
end loop;
|
|
return ds;
|
|
end proc;
|
|
end program;
|