Mayan numerals: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
 
(17 intermediate revisions by 13 users not shown)
Line 140:
:*   The Wikipedia entry:   [[https://en.wikipedia.org/wiki/Maya_numerals Mayan numerals]]
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<syntaxhighlight lang="11l">-V
UL = ‘╔’
UC = ‘╦’
UR = ‘╗’
LL = ‘╚’
LC = ‘╩’
LR = ‘╝’
HB = ‘═’
VB = ‘║’
 
Mayan = [‘ ’,
‘ ∙ ’,
‘ ∙∙ ’,
‘∙∙∙ ’,
‘∙∙∙∙’]
 
M0 = ‘ @ ’
M5 = ‘────’
 
F toBase20(=n)
V result = [n % 20]
n I/= 20
L n != 0
result [+]= n % 20
n I/= 20
R reversed(result)
 
F toMayanNumeral(=d)
V result = [Mayan[0], Mayan[0], Mayan[0], Mayan[0]]
I d == 0
result[3] = :M0
R result
 
L(i) (3..0).step(-1)
I d >= 5
result[i] = :M5
d -= 5
E
result[i] = Mayan[d]
L.break
 
R result
 
F draw(mayans)
V idx = mayans.len - 1
 
print(:UL, end' ‘’)
L(i) 0 .. idx
print(:HB * 4, end' ‘’)
I i < idx
print(:UC, end' ‘’)
E
print(:UR)
 
L(i) 1..4
print(:VB, end' ‘’)
L(j) 0 .. idx
print(mayans[j][i - 1]‘’:VB, end' ‘’)
print()
 
print(:LL, end' ‘’)
L(i) 0 .. idx
print(:HB * 4, end' ‘’)
I i < idx
print(:LC, end' ‘’)
E
print(:LR)
 
L(n) [4005, 8017, 326205, 886205, 1081439556]
print(‘Converting ’n‘ to Mayan:’)
V digits = toBase20(n)
V mayans = digits.map(d -> toMayanNumeral(d))
draw(mayans)
print()</syntaxhighlight>
 
{{out}}
<pre>
Converting 4005 to Mayan:
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ @ ║────║
╚════╩════╩════╝
 
Converting 8017 to Mayan:
╔════╦════╦════╦════╗
║ ║ ║ ║ ∙∙ ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ ∙ ║ @ ║ @ ║────║
╚════╩════╩════╩════╝
 
Converting 326205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ ∙∙ ║ @ ║────║────║────║
╚════╩════╩════╩════╩════╝
 
Converting 886205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
 
Converting 1081439556 to Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ∙ ║ ∙∙ ║∙∙∙ ║∙∙∙∙║∙∙∙ ║ ∙∙ ║ ∙ ║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╝
</pre>
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm">putch: equ 2
puts: equ 9
org 100h
Line 266 ⟶ 387:
d0: db '| $| . $| .. $|... $|....$'
d5: db '|----$'
dn: db '|',13,10,'$'</langsyntaxhighlight>
 
{{out}}
Line 309 ⟶ 430:
|....|----|----|----|----|----|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+----+----+----+----+</pre>
 
=={{header|Amazing Hopper}}==
{{Trans|BASIC}}
<syntaxhighlight lang="c">
#include <basico.h>
 
algoritmo
muestra=""
obtener total argumentos
cuando ' sea distinto a( 2 ) '{ terminar }
obtener parámetro alfanumérico (2), guardar en 'muestra'
 
lsimb={}, '" "," . "," .. ","... ","...."'#(utf8("────")), enlistar en 'lsimb'
 
largo=0, #( largo = len(muestra))
sdígitos={}, separar( muestra, sdígitos, "")
ndígitos=0, #( ndígitos = number(sdígitos) )
 
m=0, t=0
#( m = largo-1)
 
// convertir dígitos a base 20,la base de los mayas:
iterar para( j=m, #(j>=1), --j )
iterar para( i=1, #(i<=j), ++i )
bit.and( #(ndígitos[i]), 1 ), por '10',
guardar en 't'
#( ndígitos[i+1] += t )
#( ndígitos[i] = int(ndígitos[i]/2) )
siguiente
siguiente
 
s=1
iterar mientras ( #( ndígitos[s]==0 && s<largo) )
++s
reiterar
// armar los cartuchos:
imprimir ( #(utf8("╔═════")),#(replicate( utf8("═════"), largo-s) ), #(utf8("═╗")), NL,\
#(utf8("║┌────")),#(replicate( utf8("┬────"), largo-s) ), #(utf8("┐║")), NL )
n=0
iterar para ( l=3, #(l>=0), --l )
 
imprimir (#(utf8("║")))
iterar para ( i=s, #(i<=largo), ++i )
si ( bit.or ( #(ndígitos[i]), l ), es igual a '0' )
imprimir ( #(utf8("│ Θ ")) )
sino
guardar ' #(ndígitos[i]-5*l) ' en 'n'
si ( #(n>5) )
n=5
sino si ( n, es negativo? )
n=0
fin si
imprimir( #(utf8("│")), #(lsimb[n+1]) )
fin si
siguiente
imprimir (#(utf8("│║")),NL)
siguiente
 
imprimir ( #(utf8("║└────")),#(replicate( utf8("┴────"), largo-s) ), #(utf8("┘║")), NL,\
#(utf8("╚═════")),#(replicate( utf8("═════"), largo-s) ), #(utf8("═╝")), NL )
saltar
 
terminar
</syntaxhighlight>
{{out}}
<pre>
$ hopper3 basica/nummaya.bas 4005
╔════════════════╗
║┌────┬────┬────┐║
║│ │ │ │║
║│ │ │ │║
║│────│ │ │║
║│────│ Θ │────│║
║└────┴────┴────┘║
╚════════════════╝
 
$ hopper3 basica/nummaya.bas 8017
╔═════════════════════╗
║┌────┬────┬────┬────┐║
║│ │ │ │ .. │║
║│ │ │ │────│║
║│ │ │ │────│║
║│ . │ Θ │ Θ │────│║
║└────┴────┴────┴────┘║
╚═════════════════════╝
 
$ hopper3 basica/nummaya.bas 326205
╔══════════════════════════╗
║┌────┬────┬────┬────┬────┐║
║│ │ │ │ │ │║
║│ │ │────│ │ │║
║│ │ │────│────│ │║
║│ .. │ Θ │────│────│────│║
║└────┴────┴────┴────┴────┘║
╚══════════════════════════╝
 
$ hopper3 basica/nummaya.bas 886205
╔══════════════════════════╗
║┌────┬────┬────┬────┬────┐║
║│ │ │ │ │ │║
║│ │ │────│ │ │║
║│ │────│────│────│ │║
║│────│────│────│────│────│║
║└────┴────┴────┴────┴────┘║
╚══════════════════════════╝
 
$ hopper3 basica/nummaya.bas 98380658201233422
╔═══════════════════════════════════════════════════════════════════════╗
║┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐║
║│ │ │ │ │ │ │ │ │ │ .. │ │ │ │ │║
║│ │ │ │ │ │....│ │ │ │────│....│ │ . │ │║
║│ │ │ │ .. │....│────│....│ │ .. │────│────│ │────│ │║
║│ . │....│ Θ │────│────│────│────│....│────│────│────│... │────│ .. │║
║└────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘║
╚═══════════════════════════════════════════════════════════════════════╝
 
</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">mayan←{
ds←6 4⍴' . .. ... ....────'
d←{ ⍵=0:4 4⍴¯14↑'Θ'
Line 320 ⟶ 565:
btm←'╚',(1↓∊(≢d)⍴⊂'╩════'),'╝'
top⍪((⊃,/'║',¨d),'║')⍪btm
}</langsyntaxhighlight>
 
{{out}}
Line 369 ⟶ 614:
=={{header|AppleScript}}==
Applescript supports only small integers (up to (2^29)-1 = 536870911).
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
Line 632 ⟶ 877:
end |λ|
end script
end wikiTable</langsyntaxhighlight>
{{Out}}
Mayan 4005:
Line 675 ⟶ 920:
|style="width:3em;vertical-align:bottom;"|Θ
|}
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">UL: "╔"
UC: "╦"
UR: "╗"
LL: "╚"
LC: "╩"
LR: "╝"
HB: "═"
VB: "║"
 
Mayan: [" ", " ∙ ", " ∙∙ ", "∙∙∙ ", "∙∙∙∙"]
 
M0: " Θ "
M5: "────"
 
toMayan: function [digit][
result: array.of:4 Mayan\0
if digit = 0 [
result\3: M0
return result
]
 
d: digit
loop 3..0 'i [
if? d >= 5 [
result\[i]: M5
d: d - 5
]
else [
result\[i]: Mayan\[d]
break
]
]
return result
]
 
draw: function [mayans][
idx: dec size mayans
 
prints UL
 
loop 0..idx 'i [
loop 0..3 'j [
prints HB
]
prints (i < idx)? -> UC -> UR ++ `\n`
]
 
loop 1..4 'i [
prints VB
loop 0..idx 'j ->
prints mayans\[j]\[dec i] ++ VB
print ""
]
 
prints LL
 
loop 0..idx 'i [
loop 0..3 'j ->
prints HB
prints (i < idx)? -> LC -> LR ++ `\n`
]
]
 
loop [4005, 8017, 326205, 886205, 1081439556] 'n [
print ["Converting" n "to Mayan:"]
digs: digits.base:20 n
mayans: map digs => toMayan
draw mayans
print ""
]</syntaxhighlight>
 
{{out}}
 
<pre>Converting 4005 to Mayan:
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ Θ ║────║
╚════╩════╩════╝
 
Converting 8017 to Mayan:
╔════╦════╦════╦════╗
║ ║ ║ ║ ∙∙ ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ ∙ ║ Θ ║ Θ ║────║
╚════╩════╩════╩════╝
 
Converting 326205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ ∙∙ ║ Θ ║────║────║────║
╚════╩════╩════╩════╩════╝
 
Converting 886205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
 
Converting 1081439556 to Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ∙ ║ ∙∙ ║∙∙∙ ║∙∙∙∙║∙∙∙ ║ ∙∙ ║ ∙ ║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╝</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">MayanNumerals(num){
pwr:=1, obj:=[], grid:=[]
while (num // 20**pwr)
pwr++
while --pwr
{
obj.Push(num // 20**pwr)
num := Mod(num, 20**pwr)
}
obj.Push(num)
cols := obj.count()
loop % cols
{
c := A_Index
loop 4
grid[c, A_Index] := " "
grid[c, 4] := " Θ "
}
for i, v in obj
{
j := 5
loop % v//5
{
j := 5 - A_Index
grid[i, j] := "————"
}
rem := ""
loop % Mod(v, 5)
rem .= "●"
rem := rem = "●" ? " ● " : rem = "●●" ? " ●● " : rem = "●●●" ? "●●● " : rem
if Mod(v, 5)
grid[i, j-1] := rem
}
return grid2table(grid, cols)
}
 
grid2table(grid, cols){
loop, % cols-1
topRow .= "════╦", bottomRow .= "════╩"
topRow := "╔" topRow "════╗"
bottomRow := "╚" bottomRow "════╝"
loop % 4
{
r := A_Index
loop % cols
result .= "║" grid[A_Index, r]
result .= "║`n"
}
result := topRow "`n" result . bottomRow
return % result
}</syntaxhighlight>
Examples:<syntaxhighlight lang="autohotkey">for i, n in [4005, 8017, 326205, 886205, 194481]
{
x := MayanNumerals(n)
Gui, Font, S12, Consolas
Gui, Add, Text, , % n
Gui, Add, Text, y+0, % x
Gui, Show, y100
MsgBox, 262180, , continue with next number?
IfMsgBox, No
ExitApp
Gui, Destroy
}</syntaxhighlight>
{{out}}
<pre>
4005 8017 326205 886205 194481
╔════╦════╦════╗ ╔════╦════╦════╦════╗ ╔════╦════╦════╦════╦════╗ ╔════╦════╦════╦════╦════╗ ╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║ ║ ║ ●● ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║ ║ ║ ║ ║ ║ ║ ║————║ ║ ║ ║————║ ║ ║ ║ ║ ║————║ ║ ║ ║ ║ ║ ║ ║ ║
║————║ ║ ║ ║ ║ ║ ║————║ ║ ║ ║————║————║ ║ ║ ║————║————║————║ ║ ║ ║ ║ ● ║ ║ ║
║————║ Θ ║————║ ║ ● ║ Θ ║ Θ ║————║ ║ ●● ║ Θ ║————║————║————║ ║————║————║————║————║————║ ║ ● ║●●●●║————║●●●●║ ● ║
╚════╩════╩════╝ ╚════╩════╩════╩════╝ ╚════╩════╩════╩════╩════╝ ╚════╩════╩════╩════╩════╝ ╚════╩════╩════╩════╩════╝
</pre>
 
=={{header|BASIC}}==
<langsyntaxhighlight BASIClang="basic">10 DEFINT A-Z: DIM L$(5)
15 FOR I=0 TO 5: READ L$(I): NEXT I
20 LINE INPUT I$
Line 700 ⟶ 1,135:
210 FOR I=S TO M: PRINT "+----";: NEXT I: PRINT "+"
220 END
230 DATA " "," . "," .. ","... ","....","----"</langsyntaxhighlight>
 
{{out}}
Line 751 ⟶ 1,186:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let reads(v) be
Line 820 ⟶ 1,255:
mayan(v)
$) repeat
$)</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>Number? 4005
Line 859 ⟶ 1,294:
 
=={{header|C}}==
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <string.h>
#include <stdint.h>
Line 948 ⟶ 1,383:
free(m);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 987 ⟶ 1,422:
|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
 
const std::vector<std::string> MAYAN_DIGITS = { " Θ ", " ∙ ", " ∙∙ ", "∙∙∙ ", "∙∙∙∙", "────" };
const std::string BLANK = " ";
 
std::unordered_map<std::string, std::string> BORDER { { "horizontal_beam", "═" }, { "vertical_beam", "║" },
{ "lower_left", "╚" }, { "lower_central", "╩" }, { "lower_right", "╝" },
{ "upper_left", "╔" }, { "upper_central", "╦" }, { "upper_right", "╗" } };
 
std::vector<int32_t> to_base20(const int32_t& number) {
std::vector<int32_t> result;
result.emplace_back(number % 20);
int32_t n = number / 20;
while ( n != 0 ) {
result.emplace_back(n % 20);
n /= 20;
}
std::reverse(result.begin(), result.end());
return result;
}
 
std::vector<std::string> to_mayan_numeral(int32_t digit) {
std::vector<std::string> result(4, BLANK);
if ( digit == 0 ) {
result[3] = MAYAN_DIGITS[0];
return result;
}
 
for ( int32_t i = 3; i >= 0; --i ) {
if ( digit >= 5 ) {
result[i] = MAYAN_DIGITS[5];
digit -= 5;
} else {
result[i] = ( digit == 0 ) ? BLANK : MAYAN_DIGITS[digit];
break;
}
}
return result;
}
 
void display(const std::vector<std::vector<std::string>>& numerals) {
const int32_t index = numerals.size() - 1;
 
std::cout << BORDER["upper_left"];
for ( int32_t i = 0; i <= index; ++i ) {
for ( int32_t j = 0; j <= 3; ++j ) {
std::cout << BORDER["horizontal_beam"];
}
if ( i < index ) {
std::cout << BORDER["upper_central"];
} else {
std::cout << BORDER["upper_right"] << std::endl;
}
}
 
for ( int32_t i = 1; i <= 4; ++i ) {
std::cout << BORDER["vertical_beam"];
for ( int32_t j = 0; j <= index; ++j ) {
std::cout << numerals[j][i - 1] + BORDER["vertical_beam"];
}
std::cout << std::endl;
}
 
std::cout << BORDER["lower_left"];
for ( int32_t i = 0; i <= index; ++i ) {
for ( int32_t j = 0; j <= 3; ++j ) {
std::cout << BORDER["horizontal_beam"];
}
if ( i < index ) {
std::cout << BORDER["lower_central"];
} else {
std::cout << BORDER["lower_right"] << std::endl;
}
}
}
 
int main() {
for ( const int32_t& base10 : { 4'005, 8'017, 326'205, 886'205, 1'081'439'556 } ) {
std::cout << "Base 10 number, " << base10 << " to Mayan:" << std::endl;
std::vector<int32_t> digits = to_base20(base10);
std::vector<std::vector<std::string>> mayans;
for ( const int32_t& digit : digits ) {
std::vector<std::string> mayan = to_mayan_numeral(digit);
mayans.push_back(mayan);
}
display(mayans);
std::cout << std::endl;
}
}
</syntaxhighlight>
{{ out }}
<pre>
Base 10 number, 4005 to Mayan:
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ Θ ║────║
╚════╩════╩════╝
 
Base 10 number, 8017 to Mayan:
╔════╦════╦════╦════╗
║ ║ ║ ║ ∙∙ ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ ∙ ║ Θ ║ Θ ║────║
╚════╩════╩════╩════╝
 
Base 10 number, 326205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ ∙∙ ║ Θ ║────║────║────║
╚════╩════╩════╩════╩════╝
 
Base 10 number, 886205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
 
Base 10 number, 1081439556 to Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ∙ ║ ∙∙ ║∙∙∙ ║∙∙∙∙║∙∙∙ ║ ∙∙ ║ ∙ ║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╝
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">% 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</syntaxhighlight>
{{out}}
<pre>$ ./mayan 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
 
$ ./mayan 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
 
$ ./mayan 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
 
$ ./mayan 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
 
$ ./mayan 18380658207197784
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | | |....| | | | | |....| | | |
| | |....|----|....| | | |....|----|....| | |
| |....|----|----|----|....| |....|----|----|----|....| |
|....|----|----|----|----|----|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+----+----+----+----+</pre>
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
include "argv.coh";
 
Line 1,064 ⟶ 1,731:
(n, arg) := AToI(arg);
if n <= 0 then Error(); end if;
print_mayan(n as uint32);</langsyntaxhighlight>
 
{{out}}
Line 1,105 ⟶ 1,772:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Mayan numerals. Nigel Galloway: February 19th., 2021
let N=[|"│ ";"│. ";"│.. ";"│... ";"│....";"│~~~~"|]
Line 1,116 ⟶ 1,783:
printfn "┘"
[4005L;8017L;326205L;886205L]|>List.iter(fun n->printfn "%d" n; mayan n)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,149 ⟶ 1,816:
</pre>
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: arrays formatting io kernel make math math.extras
sequences ;
IN: rosetta-code.mayan-numerals
Line 1,182 ⟶ 1,849:
{ 4005 8017 326205 886205 } [ .mayan ] each ;
 
MAIN: mayan-numerals</langsyntaxhighlight>
{{out}}
Mayan 4005:
Line 1,221 ⟶ 1,888:
|style="width:3em;vertical-align:bottom;"|●
|}
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Dim As Integer i, j, m, n, s, v
Dim As String maya(5), num
For i = 0 To 5
Read maya(i)
Next i
Const ul = Chr(201), uc = Chr(203), ur = Chr(187), ll = Chr(200)
Const lc = Chr(202), lr = Chr(188), hb = Chr(205), vb = Chr(186)
 
Dim As Longint numbers(0 To ...) = {4005, 8017, 326205, 886205, 1081439556, 18380658207197784}
For v = 0 To Ubound(numbers)
num = Str(numbers(v))
Print "Converting"; numbers(v); " to Mayan:"
m = Len(num)
Redim As Integer D(m)
For i = 1 To m
D(i) = Val(Mid(num,i,1))
Next i
For j = m-1 To 1 Step -1
For i = 1 To j
D(i+1) += 10*(D(i) And 1)
D(i) \= 2
Next i
Next j
s = 1
Do While D(s) = 0 And s < m
s += 1
Loop
For i = s To m
Print Iif(i < m-1, ul+hb+hb+hb+hb, uc+hb+hb+hb+hb);
Next i
Print ur
For j = 3 To 0 Step -1
For i = s To m
If (D(i) Or j) = 0 Then
Print vb + " @ ";
Else
n = D(i)-5*j
If n > 5 Then
n = 5
Elseif n < 0 Then
n = 0
End If
Print vb; maya(n);
End If
Next i
Print vb
Next j
For i = s To m
Print Iif(i < m-1, ll+hb+hb+hb+hb, lc+hb+hb+hb+hb);
Next i
Print lr + Chr(10) '"+"
Next v
Sleep
Data " "," . "," .. ","... ","....","----"</syntaxhighlight>
{{out}}
<pre>Same as BASIC entry.</pre>
 
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Mayan_numerals}}
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,328 ⟶ 2,060:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,374 ⟶ 2,106:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Bool (bool)
import Data.List (intercalate, transpose)
import qualified Data.Map.Strict as M
Line 1,512 ⟶ 2,244:
leftPadded xs =
let w = maximum (length <$> xs)
in ((<>) =<< flip replicate [] . (-) w . length) <$> xs</langsyntaxhighlight>
{{Out}}
Mayan 4005:
Line 1,680 ⟶ 2,412:
 
=={{header|J}}==
J does not support Unicode by default.
 
<langsyntaxhighlight Jlang="j">elems =: 6 4$' . .. ... ....----'
digit =: (elems{~5:<.0:>.15 10 5 0-~])`((4 4$_14{.'@')&[)@.(0&=)
mayan =: ":@(digit each@(20&#.^:_1))</langsyntaxhighlight>
 
{{out}}
Line 1,741 ⟶ 2,472:
=={{header|Java}}==
Unicode characters used. See <code>Character.toChars</code>.
<langsyntaxhighlight lang="java">
import java.math.BigInteger;
 
Line 1,923 ⟶ 2,654:
 
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,008 ⟶ 2,739:
 
=={{header|JavaScript}}==
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 2,225 ⟶ 2,956:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
Mayan 4005:
Line 2,398 ⟶ 3,129:
|}
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
{{trans|Wren}}
<syntaxhighlight lang="jq">def m:
{ ul: "╔",
uc: "╦",
ur: "╗",
ll: "╚",
lc: "╩",
lr: "╝",
hb: "═",
vb: "║",
 
m0: " Θ ",
m5: "────"
};
def mayan: [
" ",
" ∙ ",
" ∙∙ ",
"∙∙∙ ",
"∙∙∙∙"
];
 
# decimal number to base-20 array, most significant digit first
def dec2vig:
[recurse(if . >= 20 then ./20|floor else empty end) | . % 20]
| reverse;
def vig2quin:
if . >= 20 then "Cannot convert a number >= 20." | error
else . as $n
| [mayan[0], mayan[0], mayan[0], mayan[0]]
| if $n == 0
then .[3] = m.m0
else (($n/5)|floor) as $fives
| ($n % 5) as $rem
| .[3-$fives] = mayan[$rem]
| reduce range(3; 3-$fives; -1) as $i (.; .[$i] = m.m5)
end
end;
def draw($mayans):
($mayans|length) as $lm
| (reduce range(0; $lm) as $i (m.ul;
. + m.hb * 4 + if $i < $lm - 1 then m.uc else m.ur + "\n" end ) )
+ (reduce range(1; 5) as $i ("";
. + m.vb
+ (reduce range(0; $lm) as $j ("";
. + $mayans[$j][$i-1] + m.vb)) + "\n" ) )
+ (reduce range(0; $lm) as $i (m.ll;
. + (m.hb * 4)
+ if ($i < $lm - 1) then m.lc else m.lr + "\n" end ) );
 
def decimal2mayan:
"Converting \(.) to Mayan:",
draw(dec2vig | map( vig2quin ) ),
"" ;
 
4005, 8017, 326205, 886205, 1081439556
| decimal2mayan</syntaxhighlight>
{{out}}
<pre>
Converting 4005 to Mayan:
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ Θ ║────║
╚════╩════╩════╝
 
 
Converting 8017 to Mayan:
╔════╦════╦════╦════╗
║ ║ ║ ║ ∙∙ ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ ∙ ║ Θ ║ Θ ║────║
╚════╩════╩════╩════╝
 
 
Converting 326205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ ∙∙ ║ Θ ║────║────║────║
╚════╩════╩════╩════╩════╝
 
 
Converting 886205 to Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
 
 
Converting 1081439556 to Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ∙ ║ ∙∙ ║∙∙∙ ║∙∙∙∙║∙∙∙ ║ ∙∙ ║ ∙ ║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╝
</pre>
 
=={{header|Julia}}==
<h4> First version, using a style sheet, output to html, with the capability of proper style within the browser.</h4>
<langsyntaxhighlight lang="julia">using Gumbo
mayan_glyphs(x, y) = (x == 0 && y == 0) ? "\n<td>Θ</td>\n" : "<td>\n" * "●" ^ x * "<br />\n───" ^ y * "</td>\n"
Line 2,438 ⟶ 3,279:
 
testmayan()
</syntaxhighlight>
</lang>
<h4> Version 2, using local wiki style table formatting: translation of style code from the Raku version. </h4>
<langsyntaxhighlight lang="julia">mayan_glyphs(x, y) = (x == 0 && y == 0) ? "\n| style=$tdconfig | Θ" : "\n| style=$tdconfig | " * "●" ^ x * "<br>───" ^ y
 
inttomayan(n) = (s = string(n, base=20); map(ch -> reverse(divrem(parse(Int, ch, base=20), 5)), split(s, "")))
Line 2,458 ⟶ 3,299:
 
testmayan()
</syntaxhighlight>
</lang>
{{out}}
 
Line 2,529 ⟶ 3,370:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[MakeLengthFive, MayanNumeral]
MakeLengthFive[ci_String] := Module[{c},
c = If[EvenQ[StringLength[ci]], ci <> " ", ci];
Line 2,555 ⟶ 3,396:
MayanNumeral[326205]
MayanNumeral[886205]
MayanNumeral[1337]</langsyntaxhighlight>
{{out}}
Outputs a graphical representation of the cartouches.
Line 2,562 ⟶ 3,403:
{{trans|Go}}
Free adaptation of the Go version.
<syntaxhighlight lang="nim">
<lang Nim>
import algorithm
 
Line 2,638 ⟶ 3,479:
let mayans = digits.mapIt(it.toMayanNumeral)
mayans.draw()
echo ""</langsyntaxhighlight>
 
{{out}}
Line 2,685 ⟶ 3,526:
{{trans|Raku}}
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use ntheory qw/fromdigits todigitstring/;
 
my $t_style = '"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"';
Line 2,719 ⟶ 3,560:
}
 
print join "\n<br>\n", @output;</langsyntaxhighlight>
{{out}}
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
Line 2,773 ⟶ 3,614:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">/* MAYAN NUMERALS IN PL/M
THIS PROGRAM RUNS UNDER CP/M AND TAKES THE NUMBER ON THE COMMAND LINE */
Line 2,871 ⟶ 3,712:
 
CALL EXIT;
EOF</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>A>MAYAN 4005
Line 2,916 ⟶ 3,757:
{{trans|Raku}}
Three-way output controlled by the first two constants.
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>-- demo\rosetta\Mayan_numerals.exw
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Mayan_numerals.exw</span>
constant as_html = true, -- false == nasty ascii
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o [when as_html is true])</span>
inline_css = true -- also uses wiki tables ({| etc) if false
<span style="color: #008080;">constant</span> <span style="color: #000000;">as_html</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- false == nasty ascii</span>
 
<span style="color: #000000;">inline_css</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span> <span style="color: #000080;font-style:italic;">-- also uses wiki tables ({| etc) if false</span>
string html = ""
 
<span style="color: #004080;">string</span> <span style="color: #000000;">html</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
constant t_style = "border-collapse: separate; text-align: center; border-spacing: 3px 0px;",
c_style = "border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;"&
<span style="color: #008080;">constant</span> <span style="color: #000000;">t_style</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"</span><span style="color: #0000FF;">,</span>
"border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;"&
<span style="color: #000000;">c_style</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;"</span><span style="color: #0000FF;">&</span>
"vertical-align: bottom;width: 3.25em;",
<span style="color: #008000;">"border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;"</span><span style="color: #0000FF;">&</span>
dot = "&#x25cf;",
<span style="color: #008000;">"vertical-align: bottom;width: 3.25em;"</span><span style="color: #0000FF;">,</span>
bar = "&#x2500;&#x2500;&#x2500;",
<span style="color: #000000;">dot</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x25cf;"</span><span style="color: #0000FF;">,</span>
zero = "&#x0398;",
<span style="color: #000000;">bar</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x2500;&#x2500;&#x2500;"</span><span style="color: #0000FF;">,</span>
digits = {" 0 "," . "," .. ","... ","...."}
<span style="color: #000000;">zero</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x0398;"</span><span style="color: #0000FF;">,</span>
 
<span style="color: #000000;">digits</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">" 0 "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" . "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" .. "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"... "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"...."</span><span style="color: #0000FF;">}</span>
function to_seq(atom a)
sequence s = {}
<span style="color: #008080;">function</span> <span style="color: #000000;">to_seq</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
while true do
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
s = prepend(s,remainder(a,20))
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
a = floor(a/20)
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">))</span>
if a=0 then exit end if
<span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">/</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)</span>
end while
<span style="color: #008080;">if</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return s
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
end function
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
procedure show_mayan(atom a)
sequence s = to_seq(a)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show_mayan</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
if not as_html then
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">to_seq</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
string tb = join(repeat('+',length(s)+1),"------"),
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">as_html</span> <span style="color: #008080;">then</span>
ln = join(repeat('|',length(s)+1)," ")
<span style="color: #004080;">string</span> <span style="color: #000000;">tb</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'+'</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"------"</span><span style="color: #0000FF;">),</span>
sequence res = {tb,ln,ln,ln,ln,tb}
<span style="color: #000000;">ln</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'|'</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)</span>
for i=1 to length(s) do
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">tb</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tb</span><span style="color: #0000FF;">}</span>
integer si = s[i], l = 5, m = i*7-4
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
while true do
<span style="color: #004080;">integer</span> <span style="color: #000000;">si</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">*</span><span style="color: #000000;">7</span><span style="color: #0000FF;">-</span><span style="color: #000000;">4</span>
res[l][m..m+3] = digits[min(si+1,5)]
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
si -= 5
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">l</span><span style="color: #0000FF;">][</span><span style="color: #000000;">m</span><span style="color: #0000FF;">..</span><span style="color: #000000;">m</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">si</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)]</span>
if si<=0 then exit end if
<span style="color: #000000;">si</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">5</span>
l -= 1
<span style="color: #008080;">if</span> <span style="color: #000000;">si</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
printf(1,"%d\n%s\n\n",{a,join(res,"\n")})
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
else
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d\n%s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)})</span>
for i=1 to length(s) do
<span style="color: #008080;">else</span>
sequence res = repeat("",4)
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
integer si = s[i], l = 4
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span>
while true do
<span style="color: #004080;">integer</span> <span style="color: #000000;">si</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">4</span>
res[l] = iff(si>=5?bar:iff(si?join(repeat(dot,si),""):zero))
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
si -= 5
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">l</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">si</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">5</span><span style="color: #0000FF;">?</span><span style="color: #000000;">bar</span><span style="color: #0000FF;">:</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">si</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dot</span><span style="color: #0000FF;">,</span><span style="color: #000000;">si</span><span style="color: #0000FF;">),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">):</span><span style="color: #000000;">zero</span><span style="color: #0000FF;">))</span>
if si<=0 then exit end if
<span style="color: #000000;">si</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">5</span>
l -= 1
<span style="color: #008080;">if</span> <span style="color: #000000;">si</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
s[i] = join(res,"<br>")
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
end for
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"&lt;br&gt;"</span><span style="color: #0000FF;">)</span>
if inline_css then
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
html &= sprintf(" <table>\n <caption>%d</caption>\n <tr>\n",a)
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
for i=1 to length(s) do
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" &lt;table&gt;\n &lt;caption&gt;%d&lt;/caption&gt;\n &lt;tr&gt;\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
html &= sprintf(" <td>%s</td>\n",{s[i]})
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
end for
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" &lt;td&gt;%s&lt;/td&gt;\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]})</span>
html &= " </tr>\n </table>\n"
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
else
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" &lt;/tr&gt;\n &lt;/table&gt;\n"</span>
html &= sprintf("{| style=\"%s\"\n|+ %d\n|-\n",{t_style,a})
<span for istyle=1 to length(s)"color: do#008080;">else</span>
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"{| style=\"%s\"\n|+ %d\n|-\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">t_style</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">})</span>
html &= sprintf("| style=\"%s\" | %s\n",{c_style,s[i]})
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
end for
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"| style=\"%s\" | %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">c_style</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]})</span>
html &= "|}\n"
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end if
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">"|}\n"</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
constant html_header = """
<!DOCTYPE html>
<span style="color: #008080;">constant</span> <span style="color: #000000;">html_header</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
<html lang="en">
&lt;!DOCTYPE html&gt;
<head>
&lt;html lang="en"&gt;
<meta charset="utf-8" />
&lt;head&gt;
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
&lt;meta charset="utf-8" /&gt;
<title>Mayan numerals</title>
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
<style>
&lt;title&gt;Mayan numerals&lt;/title&gt;
table {%s}
&lt;style&gt;
td { %s }
table {%s}
</style>
td { %s }
</head>
&lt;/style&gt;
<body>
&lt;/head&gt;
<h2>Mayan numerals</h2>
&lt;body&gt;
""",
&lt;h2&gt;Mayan numerals&lt;/h2&gt;
wiki_header = """
"""</span><span style="color: #0000FF;">,</span>
The following is intended to be pasted into the rosettacode wiki, or similar<br>
<span style="color: #000000;">wiki_header</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
""",
The following is intended to be pasted into the rosettacode wiki, or similar&lt;br&gt;
html_footer = """
"""</span><span style="color: #0000FF;">,</span>
</body>
<span style="color: #000000;">html_footer</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
</html>
&lt;/body&gt;
"""
&lt;/html&gt;
 
"""</span>
constant tests = {4005, 8017, 326205, 886205, 26960840421, 126524984376952}
 
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">4005</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">8017</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">326205</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">886205</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">26960840421</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">126524984376952</span><span style="color: #0000FF;">}</span>
for i=1 to length(tests) do show_mayan(tests[i]) end for
 
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">show_mayan</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
if as_html then
string filename = "Mayan_numerals.html"
<span style="color: #008080;">if</span> <span style="color: #000000;">as_html</span> <span style="color: #008080;">then</span>
integer fn = open(filename,"w")
<span style="color: #004080;">string</span> <span style="color: #000000;">filename</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Mayan_numerals.html"</span>
if inline_css then
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"w"</span><span style="color: #0000FF;">)</span>
printf(fn,html_header,{t_style,c_style})
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
else
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">html_header</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">t_style</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c_style</span><span style="color: #0000FF;">})</span>
printf(fn,wiki_header)
<span style="color: #008080;">else</span>
end if
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">wiki_header</span><span style="color: #0000FF;">)</span>
puts(fn,html)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
if inline_css then
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">html</span><span style="color: #0000FF;">)</span>
puts(fn,html_footer)
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
end if
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">html_footer</span><span style="color: #0000FF;">)</span>
close(fn)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
if inline_css then
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
system(filename)
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
else
<span style="color: #000000;">system</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span>
printf(1,"See %s\n",{filename})
<span style="color: #008080;">else</span>
{} = wait_key()
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"See %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">})</span>
end if
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
else
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
?"done"
<span style="color: #008080;">else</span>
{} = wait_key()
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
end if</lang>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
{{out}}
With inline_css set to false. Note these are always height-4.
Line 3,243 ⟶ 4,087:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">#START_X=-4 : #START_Y=2
Dim pl$(5)
pl$(0)=" Θ " : pl$(1)=" • " : pl$(2)=" •• "
Line 3,310 ⟶ 4,154:
ConsoleLocate(0,#START_Y+7) : Print("Dezimal = "+i$)
ConsoleLocate(0,#START_Y+8) : Print("Vigesimal= "+j$)
ForEver</langsyntaxhighlight>
{{out}}
<pre>MAYAN: ?
Line 3,359 ⟶ 4,203:
=={{header|Python}}==
{{Works with|Python|3.7}}
<langsyntaxhighlight Pythonlang="python">'''Mayan numerals'''
 
from functools import (reduce)
Line 3,496 ⟶ 4,340:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
Mayan numeral representations of various integers:
Line 3,586 ⟶ 4,430:
These don't particularly resemble the Mayan cartouche, more like mahjong tiles actually. It would have been ''so'' much easier and more compact if I could have put all the styling into a CSS file instead of inlining it, but oh well, it was entertaining to do.
 
<syntaxhighlight lang="raku" perl6line>### Formatting ###
my $t-style = '"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"';
my $c-style = '"border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;'~
Line 3,604 ⟶ 4,448:
 
say @output.join: "\n$joiner\n";
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,685 ⟶ 4,529:
Or, plain old text mode. Not as pretty, but still serviceable.
 
<syntaxhighlight lang="raku" perl6line>### Formatting ###
use Terminal::Boxer;
my $joiner = "\n";
Line 3,699 ⟶ 4,543:
}
 
say @output.join: $joiner;</langsyntaxhighlight>
 
{{out}}
Line 3,760 ⟶ 4,604:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program converts decimal numbers to the Mayan numbering system (with cartouches).*/
parse arg $ /*obtain optional arguments from the CL*/
if $='' then $= 4005 8017 326205 886205, /*Not specified? Then use the default.*/
Line 3,772 ⟶ 4,616:
call $MAYAN # '(overlap)' /*invoke the $MAYAN (REXX) subroutine.*/
say
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
The &nbsp; '''$MAYAN.REX''' &nbsp; (REXX program) subroutine can be seen here &nbsp; ───► &nbsp; [[Mayan_numerals\$MAYAN.REX]].
 
Line 3,826 ⟶ 4,670:
╚════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╝
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">numbers = ARGV.map(&:to_i)
if numbers.length == 0
puts
puts("usage: #{File.basename(__FILE__)} number...")
exit
end
 
def maya_print(number)
digits5s1s = number.to_s(20).chars.map { |ch| ch.to_i(20) }.map { |dig| dig.divmod(5) }
puts(('+----' * digits5s1s.length) + '+')
3.downto(0) do |row|
digits5s1s.each do |d5s1s|
if row < d5s1s[0]
print('|----')
elsif row == d5s1s[0]
print("|#{[(d5s1s[0] == 0 ? ' @ ' : ' '), ' . ', ' .. ', '... ', '....'][d5s1s[1]]}")
else
print('| ')
end
end
puts('|')
end
puts(('+----' * digits5s1s.length) + '+')
end
 
numbers.each do |num|
puts(num)
maya_print(num)
end</syntaxhighlight>
{{out}}
<pre>$ ruby mayan.rb 4005 8017 326205 886205 4294967296
4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
4294967296
+----+----+----+----+----+----+----+----+
| | | | | |... | | . |
| | | | | |----| |----|
| | .. | | |----|----| |----|
|... |----| .. |... |----|----|....|----|
+----+----+----+----+----+----+----+----+</pre>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">const ONE: &str = "●";
const FIVE: &str = "——";
const ZERO: &str = "Θ";
Line 3,896 ⟶ 4,807:
}
mayan
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,959 ⟶ 4,870:
{{trans|Go}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Conv
 
var ul = "╔"
Line 4,034 ⟶ 4,945:
draw.call(mayans)
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 4,080 ⟶ 4,991:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">var zero=" \u0398 ",one="\u2219", five=String("\u2500"*4,"\n"), fill=" \n";
var ds=T(" "," \u2219 "," \u2219\u2219 ","\u2219\u2219\u2219 ","\u2219\u2219\u2219\u2219");
fcn mayan(m){ //--> lists of lists of strings (each line of tile)
Line 4,088 ⟶ 4,999:
String(fill*(3-bars), ds[dots],"\n", five*bars)[0,-1].split("\n") // tile
})
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">var vbar="\u2551", hbar="\u2550"*4, ut=(hbar+"\u2566"), bt=(hbar+"\u2569");
fcn displayMayan(m){ // eg 11 is ( ( ),( * ),(----),(----) )
println("\u2554", ut*(m.len()-1), hbar,"\u2557"); // top
foreach n in (4){ println(vbar, m.apply("get",n).concat(vbar), vbar) }
println("\u255a", bt*(m.len()-1), hbar,"\u255d"); // bottom
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">foreach m in (T(4_005, 8_017, 326_205, 886_205, 503_491_211_079, 88_637_341)){
println("\n%,d:".fmt(m)); mayan(m):displayMayan(_);
}</langsyntaxhighlight>
{{out}}
<pre style="height:40ex">
Line 4,150 ⟶ 5,061:
The Raku numerals look so good, let's copy them.
{{trans|Raku}}
<langsyntaxhighlight lang="zkl">var [const]
t_style=0''"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"',
c_style=0''"border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;'
Line 4,171 ⟶ 5,082:
}).replace("!","<br>") : display(m,_)
})
.concat("\n<br>\n").println();</langsyntaxhighlight>
{{out}}
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
2,122

edits