Mayan numerals: Difference between revisions

Added FreeBASIC
(→‎{{header|Haskell}}: Pruned out liftA2 import (used <$> ... <*> instead))
(Added FreeBASIC)
 
(47 intermediate revisions by 23 users not shown)
Line 16:
task will be using the "vertical" format &nbsp; (as displayed below). &nbsp; Using the vertical format makes
it much easier to draw/construct the Mayan numerals (glyphs) with simple dots ('''.''')
and hyphen ('''-'''); &nbsp; &nbsp; (however, round bullets ('''&bull;''') and long dashes ('''─''')
make a better presentation on Rosetta Code).
 
Line 113:
║ ││║
║ ∙││║
13──► ║ ∙││║ ◄─── this glyph form <u>won't</u> be used in this Rosetta Code task.
║ ∙││║
╚════╝
Line 141:
<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}}==
<syntaxhighlight lang="8080asm">putch: equ 2
puts: equ 9
org 100h
lxi h,80h ; Get length of command line input
mov a,m
cpi 2
rc ; If no input, stop
add l
mov l,a ; Go to end of numbers
mov c,l ; C = end of numbers
inx h
mvi m,0FFh ; Terminate digit sequence with FFh
dcx h
sub0: mov a,m
cpi 32 ; When space reached, we're at the beginning
jz to20
sui '0' ; Subtract '0' from each digit and make sure
rc ; they are all valid
cpi 10
rnc
mov m,a
dcx h
jmp sub0
to20: mov a,c ; Calculate amount of numbers
sui 81h
mov c,a
to20l: mov e,c ; E = digit counter
mvi l,82h ; Start at beginning
div2: mov a,m ; Grab digit
jnc $+5 ; If carry, add ten
adi 10
rar ; Divide by two
mov m,a ; Write back
inx h
dcr e
jnz div2 ; Keep going
dcx h ; For the last number we want
ral ; to keep the carry
mov m,a ; This digit is now base-20
dcr c ; One fewer digit left to do
jnz to20l
mvi l,81h ; Find start and end of numbers
start: inx h
mov a,m
ana a
jz start
mov b,l ; B = start
inr a ; If number is zero, output nothing
rz
nend: inx h
mov a,m
inr a
jnz nend
mov a,l ; A = end
sub b
mov c,a ; C = amount
call edge
mvi d,3 ; D=line
line: push b ; Save start and amount
mov l,b ; HL = first digit
mvi h,0
num: call dline ; Print line for digit
inx h ; Next digit
dcr c
jnz num
push d ; Save line number
lxi d,dn ; Print end of line
call print
pop d ; Restore variables
pop b
dcr d
jp line ; Print next line
edge: push b ; Print edge (top or bottom)
edge_l: push b ; Keep counter
lxi d,edges
call print
pop b
dcr c
jnz edge_l
lxi d,edgen
call print
pop b
ret
dline: push h ; Print line for digit (D'th from bottom)
push d
push b
mov a,m
ora d ; Line and number both 0?
jnz $+9
lxi d,dz ; Then print line with @
jmp dnum
mov a,d ; 5 * line
add a
add a
add d
mov e,a
mov a,m ; A -= 5 * line
sub e
lxi d,d0 ; If <0, empty
jm dnum
cpi 5
jc $+9
lxi d,d5 ; If >=5, ----
jmp dnum
add a ; Otherwise, d[n]
mov l,a
add a
add l
mov l,a
mvi h,0
dad d
xchg
dnum: call print
pop b
pop d
pop h
ret
print: mvi c,puts
jmp 5
edges: db '+----$'
edgen: db '+',13,10,'$'
dz: db '| @ $'
d0: db '| $| . $| .. $|... $|....$'
d5: db '|----$'
dn: db '|',13,10,'$'</syntaxhighlight>
 
{{out}}
 
<pre>A>mayan 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
 
A>mayan 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
 
A>mayan 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
 
A>mayan 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
 
A>mayan 18380658207197784
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | | |....| | | | | |....| | | |
| | |....|----|....| | | |....|----|....| | |
| |....|----|----|----|....| |....|----|----|----|....| |
|....|----|----|----|----|----|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+----+----+----+----+</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}}
<syntaxhighlight lang="apl">mayan←{
ds←6 4⍴' . .. ... ....────'
d←{ ⍵=0:4 4⍴¯14↑'Θ'
ds[1+5⌊0⌈⍵-15 10 5 0;]
}¨20(⊥⍣¯1)⍵
top←'╔',(1↓∊(≢d)⍴⊂'╦════'),'╗'
btm←'╚',(1↓∊(≢d)⍴⊂'╩════'),'╝'
top⍪((⊃,/'║',¨d),'║')⍪btm
}</syntaxhighlight>
 
{{out}}
 
<pre style='line-height: normal; height: 50ex;> mayan 4005
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ Θ ║────║
╚════╩════╩════╝
mayan 8017
╔════╦════╦════╦════╗
║ ║ ║ ║ .. ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ . ║ Θ ║ Θ ║────║
╚════╩════╩════╩════╝
mayan 326205
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ .. ║ Θ ║────║────║────║
╚════╩════╩════╩════╩════╝
mayan 886205
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
mayan 717784
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║....║ ║ ║
║ ║....║────║....║ ║
║....║────║────║────║....║
╚════╩════╩════╩════╩════╝
mayan 2080000 ⍝ It's not the end of the world
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║... ║ ║ ║ ║ ║
║────║ ║ ║ ║ ║
║────║ Θ ║ Θ ║ Θ ║ Θ ║
╚════╩════╩════╩════╩════╝</pre>
 
=={{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 407 ⟶ 877:
end |λ|
end script
end wikiTable</langsyntaxhighlight>
{{Out}}
Mayan 4005:
Line 450 ⟶ 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}}==
<syntaxhighlight lang="basic">10 DEFINT A-Z: DIM L$(5)
15 FOR I=0 TO 5: READ L$(I): NEXT I
20 LINE INPUT I$
30 M=LEN(I$): DIM D(M)
40 FOR I=1 TO M: D(I)=VAL(MID$(I$,I,1)): NEXT I
50 FOR J=M-1 TO 1 STEP -1
60 FOR I=1 TO J
70 D(I+1) = D(I+1) + 10*(D(I) AND 1)
80 D(I) = D(I)\2
90 NEXT I,J
100 S=1
110 IF D(S)=0 AND S<M THEN S=S+1: GOTO 110
120 FOR I=S TO M: PRINT "+----";: NEXT I: PRINT "+"
130 FOR L=3 TO 0 STEP -1
140 FOR I=S TO M
150 IF (D(I) OR L)=0 THEN PRINT "| @ ";: GOTO 180
160 N=D(I)-5*L: IF N>5 THEN N=5 ELSE IF N<0 THEN N=0
170 PRINT "|";L$(N);
180 NEXT I
190 PRINT "|"
200 NEXT L
210 FOR I=S TO M: PRINT "+----";: NEXT I: PRINT "+"
220 END
230 DATA " "," . "," .. ","... ","....","----"</syntaxhighlight>
 
{{out}}
 
<pre style='line-height: normal; height: 50ex;'>run
4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
Ok
run
8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
Ok
run
326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
Ok
run
886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
Ok
run
18380658207197784
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | | |....| | | | | |....| | | |
| | |....|----|....| | | |....|----|....| | |
| |....|----|----|----|....| |....|----|----|----|....| |
|....|----|----|----|----|----|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+----+----+----+----+
Ok</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let reads(v) be
$( v%0 := 0
$( let ch = rdch()
if ch = '*N' | ch = endstreamch break
v%0 := v%0 + 1
v%(v%0) := ch
$) repeat
$)
 
let digits(v) = valof
$( for i=1 to v%0
$( unless '0' <= v%i <= '9' resultis false
v%i := v%i - '0'
$)
resultis true
$)
 
let base20(v) be
$( let i = ?
for j=v%0-1 to 1 by -1
for i=1 to j
$( v%(i+1) := v%(i+1) + 10*(v%i & 1)
v%i := v%i >> 1
$)
i := 1
while v%i=0 & i<v%0 do i := i+1
for j=i to v%0 do v%(j-i+1) := v%j
v%0 := v%0-i+1
$)
 
let mayan(v) be
$( let border(n) be
$( for i=1 to n do writes("+----")
writes("+*N")
$)
let part(num, line) be
test num=0 do
writes(line=0 -> " @ ", " ")
or
$( num := num - line*5
writes(num<=0 -> " ",
num =1 -> " . ",
num =2 -> " .. ",
num =3 -> "... ",
num =4 -> "....",
"----")
$)
border(v%0)
for l=3 to 0 by -1
$( for d=1 to v%0
$( wrch('|')
part(v%d, l)
$)
writes("|*N")
$)
border(v%0)
$)
 
let start() be
$( let v = vec 1+255/BYTESPERWORD
$( writes("Number? ")
reads(v)
if v%0=0 finish
unless digits(v) loop
base20(v)
mayan(v)
$) repeat
$)</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>Number? 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
Number? 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
Number? 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
Number? 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
Number? 114847197784
+----+----+----+----+----+----+----+----+----+
| | | | | |....| | | |
| | |....| |....|----|....| | |
| |....|----|....|----|----|----|....| |
|....|----|----|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
 
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
 
/* Find base-20 digits. */
size_t base20(unsigned int n, uint8_t *out) {
/* generate digits */
uint8_t *start = out;
do {*out++ = n % 20;} while (n /= 20);
size_t length = out - start;
/* put digits in high-endian order */
while (out > start) {
uint8_t x = *--out;
*out = *start;
*start++ = x;
}
return length;
}
 
/* Write a Mayan digit */
void make_digit(int n, char *place, size_t line_length) {
static const char *parts[] = {" "," . "," .. ","... ","....","----"};
int i;
 
/* write 4-part digit */
for (i=4; i>0; i--, n -= 5)
memcpy(place + i*line_length, parts[MAX(0, MIN(5, n))], 4);
/* if digit was 0 we should put '@' in 2nd position of last line */
if (n == -20) place[4 * line_length + 1] = '@';
}
 
/* Make a Mayan numeral */
char *mayan(unsigned int n) {
if (n == 0) return NULL;
uint8_t digits[15]; /* 2**64 is 15 Mayan digits long */
size_t n_digits = base20(n, digits);
/* a digit is 4 chars wide, plus N+1 divider lines, plus a newline
makes for a length of 5*n+2 */
size_t line_length = n_digits*5 + 2;
/* we need 6 lines - four for the digits, plus top and bottom row */
char *str = malloc(line_length * 6 + 1);
if (str == NULL) return NULL;
str[line_length * 6] = 0;
/* make the cartouche divider lines */
char *ptr;
unsigned int i;
/* top and bottom row */
for (ptr=str, i=0; i<line_length; i+=5, ptr+=5)
memcpy(ptr, "+----", 5);
memcpy(ptr-5, "+\n", 2);
memcpy(str+5*line_length, str, line_length);
/* middle rows */
for (ptr=str+line_length, i=0; i<line_length; i+=5, ptr+=5)
memcpy(ptr, "| ", 5);
memcpy(ptr-5, "|\n", 2);
memcpy(str+2*line_length, str+line_length, line_length);
memcpy(str+3*line_length, str+line_length, 2*line_length);
 
/* copy in the digits */
for (i=0; i<n_digits; i++)
make_digit(digits[i], str+1+5*i, line_length);
 
return str;
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "usage: mayan <number>\n");
return 1;
}
int i = atoi(argv[1]);
if (i <= 0) {
fprintf(stderr, "number must be positive\n");
return 1;
}
char *m = mayan(i);
printf("%s",m);
free(m);
return 0;
}</syntaxhighlight>
 
{{out}}
 
<pre style='height: 50ex; line-height: normal'>$ ./mayan 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
$ ./mayan 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
$ ./mayan 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
$ ./mayan 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
$ ./mayan 287959784
+----+----+----+----+----+----+----+
| | |....| |....| | |
| | |----|....|----| | |
| |....|----|----|----|....| |
|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+</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}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
include "argv.coh";
 
# convert number to base 20
sub base20(n: uint32, out: [uint8]): (n_digits: uint8) is
n_digits := 0;
loop
[out] := (n % 20) as uint8;
n := n / 20;
out := @next out;
n_digits := n_digits + 1;
if n == 0 then break; end if;
end loop;
end sub;
 
# get the N'th line (from the top) for a Mayan digit
sub digit_line(n: uint8, line: uint8): (s: [uint8]) is
var parts: [uint8][] := {" "," . "," .. ","... ","....","----"};
if n == 0 then
if line == 3 then s := " @ ";
else s := parts[0];
end if;
else
var nn := n - 5*(3-line);
if nn > 128 then s := parts[0];
elseif nn > 5 then s := parts[5];
else s := parts[nn];
end if;
end if;
end sub;
 
# print Mayan number
sub print_mayan(n: uint32) is
sub edge(n: uint8) is
while n>0 loop
print("+----");
n := n-1;
end loop;
print_char('+');
print_nl();
end sub;
var digits: uint8[8]; # 8 digits is enough for 2**32
var size := base20(n, &digits[0]);
edge(size);
var line: uint8 := 0;
while line < 4 loop
var d: uint8 := size-1;
loop
print_char('|');
print(digit_line(digits[d], line));
if d==0 then break; end if;
d := d - 1;
end loop;
print_char('|');
print_nl();
line := line + 1;
end loop;
edge(size);
end sub;
 
sub Error() is
print("usage: mayan <number>. number must be positive");
print_nl();
ExitWithError();
end sub;
 
# read number from command line
ArgvInit();
var arg := ArgvNext();
if arg == 0 as [uint8] then Error(); end if;
var n: int32;
(n, arg) := AToI(arg);
if n <= 0 then Error(); end if;
print_mayan(n as uint32);</syntaxhighlight>
 
{{out}}
 
<pre>$ ./mayan.386 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
$ ./mayan.386 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
$ ./mayan.386 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
$ ./mayan.386 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
$ ./mayan.386 287959784
+----+----+----+----+----+----+----+
| | |....| |....| | |
| | |----|....|----| | |
| |....|----|----|----|....| |
|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Mayan numerals. Nigel Galloway: February 19th., 2021
let N=[|"│ ";"│. ";"│.. ";"│... ";"│....";"│~~~~"|]
let fN g=(fun(n)->if g=0 && n=0 then "│ Θ " else N.[let g=g-5*n in if g>4 then 5 else if g<0 then 0 else g])
let rec fG n g=match n/20L,n%20L with (0L,0L)->(g,List.length g) |(i,n)->fG i ((fN(int n))::g)
let mayan n=let n,g=fG n []
printf "┌────"; for _ in 2..g do printf "┬────"
printfn "┐"; for g in 3.. -1 ..0 do n|>List.iter(fun n->printf "%s" (n(g))); printfn "│"
printf "└────"; for _ in 2..g do printf "┴────"
printfn "┘"
[4005L;8017L;326205L;886205L]|>List.iter(fun n->printfn "%d" n; mayan n)
</syntaxhighlight>
{{out}}
<pre>
4005
┌────┬────┬────┐
│ │ │ │
│ │ │ │
│~~~~│ │ │
│~~~~│ Θ │~~~~│
└────┴────┴────┘
8017
┌────┬────┬────┬────┐
│ │ │ │.. │
│ │ │ │~~~~│
│ │ │ │~~~~│
│. │ Θ │ Θ │~~~~│
└────┴────┴────┴────┘
326205
┌────┬────┬────┬────┬────┐
│ │ │ │ │ │
│ │ │~~~~│ │ │
│ │ │~~~~│~~~~│ │
│.. │ Θ │~~~~│~~~~│~~~~│
└────┴────┴────┴────┴────┘
886205
┌────┬────┬────┬────┬────┐
│ │ │ │ │ │
│ │ │~~~~│ │ │
│ │~~~~│~~~~│~~~~│ │
│~~~~│~~~~│~~~~│~~~~│~~~~│
└────┴────┴────┴────┴────┘
</pre>
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: arrays formatting io kernel make math math.extras
sequences ;
IN: rosetta-code.mayan-numerals
 
: mayan-digit ( n -- m pair ) 20 /mod 5 /mod swap 2array ;
 
: integer>mayan ( n -- seq )
[ [ mayan-digit , ] until-zero ] { } make reverse ;
 
: ones ( n -- str ) [ CHAR: ● ] "" replicate-as ;
: fives ( n -- str ) [ "——" ] replicate "<br>" join ;
 
: numeral ( pair -- str )
dup sum zero? [ drop "Θ" ]
[ first2 [ ones ] [ fives ] bi* 2array harvest "<br>" join ]
if ;
 
: .table-row ( pair -- )
"|style=\"width:3em;vertical-align:bottom;\"|" write numeral
print ;
 
: .table-head ( -- )
"class=\"wikitable\" style=\"text-align:center;\"" print ;
 
: .table-body ( n -- ) integer>mayan [ .table-row ] each ;
 
: .mayan ( n -- )
[ "Mayan %d:\n" printf ]
[ "{|" write .table-head .table-body "|}" print ] bi ;
 
: mayan-numerals ( -- )
{ 4005 8017 326205 886205 } [ .mayan ] each ;
 
MAIN: mayan-numerals</syntaxhighlight>
{{out}}
Mayan 4005:
{|class="wikitable" style="text-align:center;"
|style="width:3em;vertical-align:bottom;"|——<br>——
|style="width:3em;vertical-align:bottom;"|Θ
|style="width:3em;vertical-align:bottom;"|——
|}
Mayan 8017:
{|class="wikitable" style="text-align:center;"
|style="width:3em;vertical-align:bottom;"|●
|style="width:3em;vertical-align:bottom;"|Θ
|style="width:3em;vertical-align:bottom;"|Θ
|style="width:3em;vertical-align:bottom;"|●●<br>——<br>——<br>——
|}
Mayan 326205:
{|class="wikitable" style="text-align:center;"
|style="width:3em;vertical-align:bottom;"|●●
|style="width:3em;vertical-align:bottom;"|Θ
|style="width:3em;vertical-align:bottom;"|——<br>——<br>——
|style="width:3em;vertical-align:bottom;"|——<br>——
|style="width:3em;vertical-align:bottom;"|——
|}
Mayan 886205:
{|class="wikitable" style="text-align:center;"
|style="width:3em;vertical-align:bottom;"|——
|style="width:3em;vertical-align:bottom;"|——<br>——
|style="width:3em;vertical-align:bottom;"|——<br>——<br>——
|style="width:3em;vertical-align:bottom;"|——<br>——
|style="width:3em;vertical-align:bottom;"|——
|}
Mayan 194481:
{|class="wikitable" style="text-align:center;"
|style="width:3em;vertical-align:bottom;"|●
|style="width:3em;vertical-align:bottom;"|●●●●
|style="width:3em;vertical-align:bottom;"|●<br>——
|style="width:3em;vertical-align:bottom;"|●●●●
|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 557 ⟶ 2,060:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 603 ⟶ 2,106:
 
=={{header|Haskell}}==
<syntaxhighlight lang ="haskell">import Data.ListBool (intercalate, transposebool)
import Data.List (intercalate, transpose)
import qualified Data.Map.Strict as M
import Control.Monad (join)
import Data.Maybe (maybe)
import Data.Bool (bool)
 
-- MAIN -------------------------- MAIN -------------------------
main :: IO ()
main =
(putStrLn . unlines) $
mayanFramed
mayanFramed <$> [4005, 8017, 326205, 886205, 1081439556, 1000000, 1000000000]
<$> [ 4005,
8017,
326205,
886205,
1081439556,
1000000,
1000000000
]
 
-- MAYAN NUMBERS --------------------- MAYAN NUMBERS ---------------------
mayanGlyph :: Int -> [[String]]
mayanGlyph =
filter (any (not . null)) .
. transpose
transpose . leftPadded . flip (showIntAtBaseS 20 mayanDigit) []
. leftPadded
. flip (showIntAtBaseS 20 mayanDigit) []
 
mayanDigit :: Int -> [String]
mayanDigit n
| 0 /= n =
replicate (rem n 5) mayaOne : join (replicate (quot n 5) [mayaFive])
concat
( replicate (quot n 5) [mayaFive]
)
| otherwise = [[mayaZero]]
 
mayanFramed :: Int -> String
mayanFramed =
("Mayan " ++<>) .
. ( (++<>) <$> show <*>
<*> ( (":\n\n" ++<>) .
. wikiTable
( M.fromList
[ ( "style",
, join concat
[ "text-align:center;",
, "background-color:#F0EDDE;",
, "color:#605B4B;",
, "border:2px solid silver;"
])
, ("colwidth", "3em;" ),
]) . ("colwidth", "3em;")
]
mayanGlyph))
)
. mayanGlyph
)
)
 
mayaZero, mayaOne :: Char
mayaZero = '\920'
 
mayaOne = '\9679'
 
Line 653 ⟶ 2,171:
mayaFive = "\9473\9473"
 
-- NUMERIC BASES --------------------- NUMERIC BASES ---------------------
-- Based on the Prelude showIntAtBase but uses an (Int -> [String])
-- (Int -> [String]) (rather than Int -> Char) function as its second argument.
-- as its second argument.
--
-- Shows a /non-negative/ 'Integral' number using the base specified by the
-- specified by the first argument, and the **String** representation specified by the second.
-- representation specified by the second.
showIntAtBaseS
showIntAtBaseS ::
:: Integral a
Integral a =>
=> a -> (Int -> [String]) -> a -> [[String]] -> [[String]]
a ->
(Int -> [String]) ->
a ->
[[String]] ->
[[String]]
showIntAtBaseS base toStr n0 r0 =
let go (n, d) r =
seq s $
case n of
0 -> r_
_ -> go (quotRem n base) r_
where
s = toStr (fromIntegral d)
r_ = s : r
in go (quotRem n0 base) r0
 
-- DISPLAY ------------------------ DISPLAY ------------------------
wikiTable :: M.Map String String -> [[String]] -> String
wikiTable opts rows
| null rows = []
| otherwise =
"{| " ++
<> foldr
( \k a ->
(\k a -> maybe a (((a ++ k ++ "=\"") ++) . (++ "\" ")) (M.lookup k opts))
[] maybe
["class", "style"] ++ a
( ((a <> k <> "=\"") <>)
'\n' :
. ( <> "\" "
intercalate
"|-\n" )
(zipWith )
(\rowM.lookup ik ->opts)
unlines)
(fmap[]
["class", ((bool"style"]
<> ( '\n' []:
(maybeintercalate
"|-\n"
( zipWith renderedRow rows (("|style=\"width:" ++)[0 . (++ "\"")).]
(M.lookup "colwidth" opts))
(0 == i) ++) .
<> ('"|' :))}\n\n"
where
row))
renderedRow row i rows=
[0 ..]) ++unlines
"|}\n\n" ( fmap
( ( bool
[]
( maybe
"|"
(("|style=\"width:" <>) . (<> "\""))
(M.lookup "colwidth" opts)
)
(0 == i)
<>
)
. ('|' :)
)
row
)
 
leftPadded :: [[String]] -> [[String]]
leftPadded xs =
let w = maximum (length <$> xs)
in ((++<>) =<< flip replicate [] . (-) w . length) <$> xs</langsyntaxhighlight>
{{Out}}
Mayan 4005:
 
{| style="text-align:center;background-color:#F0EDDE;color:#605B4B;border:2px solid silver;"
|style="width:3em;"|━━
Line 873 ⟶ 2,410:
|}
 
=={{header|J}}==
 
<syntaxhighlight lang="j">elems =: 6 4$' . .. ... ....----'
digit =: (elems{~5:<.0:>.15 10 5 0-~])`((4 4$_14{.'@')&[)@.(0&=)
mayan =: ":@(digit each@(20&#.^:_1))</syntaxhighlight>
 
{{out}}
 
<pre style='height: 50ex; line-height: normal;'> mayan 4005
+----+----+----+
| | | |
| | | |
|----| | |
|----| @ |----|
+----+----+----+
mayan 8017
+----+----+----+----+
| | | | .. |
| | | |----|
| | | |----|
| . | @ | @ |----|
+----+----+----+----+
mayan 326205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| | |----|----| |
| .. | @ |----|----|----|
+----+----+----+----+----+
mayan 886205
+----+----+----+----+----+
| | | | | |
| | |----| | |
| |----|----|----| |
|----|----|----|----|----|
+----+----+----+----+----+
mayan 717784
+----+----+----+----+----+
| | | | | |
| | |....| | |
| |....|----|....| |
|....|----|----|----|....|
+----+----+----+----+----+
mayan 2080000
+----+----+----+----+----+
| | | | | |
|... | | | | |
|----| | | | |
|----| @ | @ | @ | @ |
+----+----+----+----+----+
mayan 12345678987654321
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | . | | . | |
| | | | .. |... | |....| | .. |----|----|----| |
| | | |----|----| |----| |----|----|----|----| |
|... | @ |----|----|----| . |----|... |----|----|----|----| . |
+----+----+----+----+----+----+----+----+----+----+----+----+----+
</pre>
 
=={{header|Java}}==
Unicode characters used. See <code>Character.toChars</code>.
<syntaxhighlight lang="java">
import java.math.BigInteger;
 
public class MayanNumerals {
 
public static void main(String[] args) {
for ( long base10 : new long[] {4005, 8017, 326205, 886205, 1000000000, 1081439556L, 26960840421L, 503491211079L }) {
displayMyan(BigInteger.valueOf(base10));
System.out.printf("%n");
}
}
private static char[] digits = "0123456789ABCDEFGHJK".toCharArray();
private static BigInteger TWENTY = BigInteger.valueOf(20);
private static void displayMyan(BigInteger numBase10) {
System.out.printf("As base 10: %s%n", numBase10);
String numBase20 = "";
while ( numBase10.compareTo(BigInteger.ZERO) > 0 ) {
numBase20 = digits[numBase10.mod(TWENTY).intValue()] + numBase20;
numBase10 = numBase10.divide(TWENTY);
}
System.out.printf("As base 20: %s%nAs Mayan:%n", numBase20);
displayMyanLine1(numBase20);
displayMyanLine2(numBase20);
displayMyanLine3(numBase20);
displayMyanLine4(numBase20);
displayMyanLine5(numBase20);
displayMyanLine6(numBase20);
}
private static char boxUL = Character.toChars(9556)[0];
private static char boxTeeUp = Character.toChars(9574)[0];
private static char boxUR = Character.toChars(9559)[0];
private static char boxHorz = Character.toChars(9552)[0];
private static char boxVert = Character.toChars(9553)[0];
private static char theta = Character.toChars(952)[0];
private static char boxLL = Character.toChars(9562)[0];
private static char boxLR = Character.toChars(9565)[0];
private static char boxTeeLow = Character.toChars(9577)[0];
private static char bullet = Character.toChars(8729)[0];
private static char dash = Character.toChars(9472)[0];
private static void displayMyanLine1(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxUL);
}
for ( int j = 0 ; j < 4 ; j++ ) {
sb.append(boxHorz);
}
sb.append(i < chars.length-1 ? boxTeeUp : boxUR);
}
System.out.println(sb.toString());
}
private static String getBullet(int count) {
StringBuilder sb = new StringBuilder();
switch ( count ) {
case 1: sb.append(" " + bullet + " "); break;
case 2: sb.append(" " + bullet + bullet + " "); break;
case 3: sb.append("" + bullet + bullet + bullet + " "); break;
case 4: sb.append("" + bullet + bullet + bullet + bullet); break;
default: throw new IllegalArgumentException("Must be 1-4: " + count);
}
return sb.toString();
}
 
private static void displayMyanLine2(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxVert);
}
switch ( chars[i] ) {
case 'G': sb.append(getBullet(1)); break;
case 'H': sb.append(getBullet(2)); break;
case 'J': sb.append(getBullet(3)); break;
case 'K': sb.append(getBullet(4)); break;
default : sb.append(" ");
}
sb.append(boxVert);
}
System.out.println(sb.toString());
}
private static String DASH = getDash();
private static String getDash() {
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < 4 ; i++ ) {
sb.append(dash);
}
return sb.toString();
}
 
private static void displayMyanLine3(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxVert);
}
switch ( chars[i] ) {
case 'B': sb.append(getBullet(1)); break;
case 'C': sb.append(getBullet(2)); break;
case 'D': sb.append(getBullet(3)); break;
case 'E': sb.append(getBullet(4)); break;
case 'F': case 'G': case 'H': case 'J': case 'K':
sb.append(DASH); break;
default : sb.append(" ");
}
sb.append(boxVert);
}
System.out.println(sb.toString());
}
 
private static void displayMyanLine4(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxVert);
}
switch ( chars[i] ) {
case '6': sb.append(getBullet(1)); break;
case '7': sb.append(getBullet(2)); break;
case '8': sb.append(getBullet(3)); break;
case '9': sb.append(getBullet(4)); break;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'J': case 'K':
sb.append(DASH); break;
default : sb.append(" ");
}
sb.append(boxVert);
}
System.out.println(sb.toString());
}
 
private static void displayMyanLine5(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxVert);
}
switch ( chars[i] ) {
case '0': sb.append(" " + theta + " "); break;
case '1': sb.append(getBullet(1)); break;
case '2': sb.append(getBullet(2)); break;
case '3': sb.append(getBullet(3)); break;
case '4': sb.append(getBullet(4)); break;
case '5': case '6': case '7': case '8': case '9':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'J': case 'K':
sb.append(DASH); break;
default : sb.append(" ");
}
sb.append(boxVert);
}
System.out.println(sb.toString());
}
 
private static void displayMyanLine6(String base20) {
char[] chars = base20.toCharArray();
StringBuilder sb = new StringBuilder();
for ( int i = 0 ; i < chars.length ; i++ ) {
if ( i == 0 ) {
sb.append(boxLL);
}
for ( int j = 0 ; j < 4 ; j++ ) {
sb.append(boxHorz);
}
sb.append(i < chars.length-1 ? boxTeeLow : boxLR);
}
System.out.println(sb.toString());
}
 
}
</syntaxhighlight>
{{out}}
<pre>
As base 10: 4005
As base 20: A05
As Mayan:
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║────║ ║ ║
║────║ θ ║────║
╚════╩════╩════╝
 
As base 10: 8017
As base 20: 100H
As Mayan:
╔════╦════╦════╦════╗
║ ║ ║ ║ ∙∙ ║
║ ║ ║ ║────║
║ ║ ║ ║────║
║ ∙ ║ θ ║ θ ║────║
╚════╩════╩════╩════╝
 
As base 10: 326205
As base 20: 20FA5
As Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║ ║────║────║ ║
║ ∙∙ ║ θ ║────║────║────║
╚════╩════╩════╩════╩════╝
 
As base 10: 886205
As base 20: 5AFA5
As Mayan:
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║────║ ║ ║
║ ║────║────║────║ ║
║────║────║────║────║────║
╚════╩════╩════╩════╩════╝
 
As base 10: 1000000000
As base 20: FCA0000
As Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║ ║ ║
║────║ ∙∙ ║ ║ ║ ║ ║ ║
║────║────║────║ ║ ║ ║ ║
║────║────║────║ θ ║ θ ║ θ ║ θ ║
╚════╩════╩════╩════╩════╩════╩════╝
 
As base 10: 1081439556
As base 20: GHJKJHG
As Mayan:
╔════╦════╦════╦════╦════╦════╦════╗
║ ∙ ║ ∙∙ ║∙∙∙ ║∙∙∙∙║∙∙∙ ║ ∙∙ ║ ∙ ║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
║────║────║────║────║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╝
 
As base 10: 26960840421
As base 20: 111555111
As Mayan:
╔════╦════╦════╦════╦════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║ ∙ ║ ∙ ║ ∙ ║────║────║────║ ∙ ║ ∙ ║ ∙ ║
╚════╩════╩════╩════╩════╩════╩════╩════╩════╝
 
As base 10: 503491211079
As base 20: KD71017DK
As Mayan:
╔════╦════╦════╦════╦════╦════╦════╦════╦════╗
║∙∙∙∙║ ║ ║ ║ ║ ║ ║ ║∙∙∙∙║
║────║∙∙∙ ║ ║ ║ ║ ║ ║∙∙∙ ║────║
║────║────║ ∙∙ ║ ║ ║ ║ ∙∙ ║────║────║
║────║────║────║ ∙ ║ θ ║ ∙ ║────║────║────║
╚════╩════╩════╩════╩════╩════╩════╩════╩════╝
</pre>
 
=={{header|JavaScript}}==
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 1,092 ⟶ 2,956:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
Mayan 4005:
Line 1,266 ⟶ 3,130:
|}
 
=={{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 1,306 ⟶ 3,279:
 
testmayan()
</syntaxhighlight>
</lang>
<h4> Version 2, using local wiki style table formatting: translation of style code from the Perl 6Raku 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 1,326 ⟶ 3,299:
 
testmayan()
</syntaxhighlight>
</lang>
{{out}}
 
Line 1,395 ⟶ 3,368:
| style= "border: 2px solid DarkOrange; border-radius: 13px; border-bottom: 2px solid DarkOrange; vertical-align: bottom; text-align: center; padding: 10px;" | ●●<br>───
|}
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[MakeLengthFive, MayanNumeral]
MakeLengthFive[ci_String] := Module[{c},
c = If[EvenQ[StringLength[ci]], ci <> " ", ci];
While[StringLength[c] < 5, c = " " <> c <> " "];
c
]
MayanNumeral[n_Integer?Positive] := Module[{nums, q, r, c},
nums = IntegerDigits[n, 20];
Row[Table[
{q, r} = QuotientRemainder[m, 5];
If[{q, r} =!= {0, 0},
c = Prepend[ConstantArray["-----", q], StringJoin[ConstantArray[".", r]]];
c = Join[ConstantArray["", 4 - Length[c]], c];
c
,
c = {"", "", "", "\[Theta]"}
];
Column[MakeLengthFive /@ c, Frame -> True]
,
{m, nums}
], Spacer[1]]
]
MayanNumeral[4005]
MayanNumeral[8017]
MayanNumeral[326205]
MayanNumeral[886205]
MayanNumeral[1337]</syntaxhighlight>
{{out}}
Outputs a graphical representation of the cartouches.
 
=={{header|Nim}}==
{{trans|Go}}
Free adaptation of the Go version.
<syntaxhighlight lang="nim">
import algorithm
 
type Border = enum UL = "╔", UC = "╦", UR = "╗", LL = "╚", LC = "╩", LR = "╝", HB = "═", VB = "║"
 
const
 
Mayan = [" ", " ∙ ", " ∙∙ ", "∙∙∙ ", "∙∙∙∙"]
 
M0 = " Θ "
M5 = "────"
 
type
Digit = range[0..19]
Numeral = array[4, string]
MayanNumber = seq[Numeral]
 
 
func toBase20(n: Natural): seq[Digit] =
## Return "n" expressed as a sequence of base 20 digits.
result.add(n mod 20)
var n = n div 20
while n != 0:
result.add n mod 20
n = n div 20
result.reverse()
 
 
func toMayanNumeral(d: Digit): Numeral =
## Return the Numeral representing a base 20 digits.
 
result = [Mayan[0], Mayan[0], Mayan[0], Mayan[0]]
if d == 0:
result[3] = M0
return
 
var d = d
for i in countdown(3, 0):
if d >= 5:
result[i] = M5
dec d, 5
else:
result[i] = Mayan[d]
break
 
 
proc draw(mayans: MayanNumber) =
## Draw the representation fo a mayan number.
 
let idx = mayans.high
 
stdout.write UL
for i in 0..idx:
for j in 0..3: stdout.write HB
if i < idx: stdout.write UC else: echo UR
 
for i in 1..4:
stdout.write VB
for j in 0..idx: stdout.write mayans[j][i-1], VB
stdout.write '\n'
 
stdout.write LL
for i in 0..idx:
for j in 0..3: stdout.write HB
if i < idx: stdout.write LC else: echo LR
 
 
when isMainModule:
 
import sequtils, strutils
 
for n in [4005, 8017, 326205, 886205, 1081439556]:
echo "Converting $1 to Mayan:".format(n)
let digits = n.toBase20()
let mayans = digits.mapIt(it.toMayanNumeral)
mayans.draw()
echo ""</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|Perl}}==
{{trans|Perl 6Raku}}
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use ntheory qw/fromdigits todigitstring/;
 
my $t_style = '"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"';
Line 1,433 ⟶ 3,560:
}
 
print join "\n<br>\n", @output;</langsyntaxhighlight>
{{out}}
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
Line 1,486 ⟶ 3,613:
|}
 
=={{header|Perl 6PL/M}}==
<syntaxhighlight lang="plm">/* MAYAN NUMERALS IN PL/M
Just a matter of converting to base twenty, then divmod 5 each digit and map to the appropriate glyph. Most of this is display code to deal with the cartouche requirement.
THIS PROGRAM RUNS UNDER CP/M AND TAKES THE NUMBER ON THE COMMAND LINE */
100H:
/* CP/M CALLS */
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
 
/* CP/M COMMAND LINE */
I actually spent a little time looking into what exactly a Mayan cartouche was supposed to look like. The classic Mayan cartouche was kind of a rounded rectangle with three little semi-circles underneath. Kind of looks like a picture frame. In general, they were only used when expressing significant "holy" dates in the Mayan calender.
DECLARE CL$PTR ADDRESS INITIAL (80H), CMD$LEN BASED CL$PTR BYTE;
DECLARE CMD$PTR ADDRESS INITIAL (81H), CMD$LINE BASED CMD$PTR BYTE;
 
/* THE PIPE AND AT SYMBOLS ARE NOT INCLUDED IN THE PL/M CHARSET */
These don't particularly resemble the Mayan cartouche, more like mahjong tiles actually. It would have been ''so'' much easier and more compact though if I could have put all the styling into a CSS file instead of inlining it, but oh well, it was entertaining to do.
DECLARE PIPE LITERALLY '7CH', AT LITERALLY '40H';
 
/* PRINT BORDER FOR N DIGITS */
<lang perl6>my $t-style = '"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"';
BORDER: PROCEDURE (N);
my $c-style = '"border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;'~
DECLARE (I, N) BYTE;
'border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;'~
DO I=1 TO N;
'vertical-align: bottom;width: 3.25em;"';
CALL PRINT(.'+----$');
END;
CALL PRINT(.('+',13,10,'$'));
END BORDER;
 
/* PRINT LINE FOR GIVEN DIGIT */
sub mayan ($int) { $int.polymod(20 xx *).reverse.map: *.polymod(5) }
DIGIT$LINE: PROCEDURE (LINE, DIGIT);
DECLARE (I, LINE, DIGIT, UPB) BYTE;
DECLARE PARTS (6) ADDRESS;
PARTS(0) = .(PIPE,' $'); PARTS(1) = .(PIPE,' . $');
PARTS(2) = .(PIPE,' .. $'); PARTS(3) = .(PIPE,'... $');
PARTS(4) = .(PIPE,'....$'); PARTS(5) = .(PIPE,'----$');
IF DIGIT = 0 THEN DO;
IF LINE = 3 THEN CALL PRINT(.(PIPE,' ',AT,' $'));
ELSE CALL PRINT(PARTS(0));
END;
ELSE DO;
UPB = 15-LINE*5;
IF DIGIT < UPB THEN CALL PRINT(PARTS(0));
ELSE IF DIGIT >= UPB+5 THEN CALL PRINT(PARTS(5));
ELSE CALL PRINT(PARTS(DIGIT-UPB));
END;
END DIGIT$LINE;
 
/* PRINT LINE GIVEN DIGITS */
sub display ($num, @digits) {
LINE: PROCEDURE (L, DIGITS, NDIGITS);
join "\n", "\{| style=$t-style", "|+ $num",
DECLARE DIGITS ADDRESS;
'|-', (|@digits.map: {"| style=$c-style | $_"}), '|}'
DECLARE (L, I, D BASED DIGITS, NDIGITS) BYTE;
}
DO I=0 TO NDIGITS-1;
CALL DIGIT$LINE(L, D(I));
END;
CALL PRINT(.(PIPE,13,10,'$'));
END LINE;
 
/* CHECK FOR ARGUMENT */
my @output = <4005 8017 326205 886205 1081439556 503491211079>.map:
IF CMD$LEN < 2 THEN DO;
{ display $_, .&mayan.map: { (join '<br>', '●' x .[0], '───' xx .[1]) || 'Θ' } }
CALL PRINT(.'NO INPUT$');
CALL EXIT;
END;
 
/* PREPROCESS COMMAND LINE - TURN EACH ASCII DIGIT INTO 0-9 */
say @output.join: "\n<br>\n";</lang>
DECLARE (I, J) BYTE;
DO I = 1 TO CMD$LEN-1;
CMD$LINE(I) = CMD$LINE(I) - '0';
IF CMD$LINE(I) > 9 THEN DO;
/* ERROR MESSAGE FOR INVALID INPUT */
CALL PRINT(.'INVALID DIGIT IN INPUT$');
CALL EXIT;
END;
END;
 
/* CONVERT TO BASE 20 DIGIT BY DIGIT */
{{out}}
J = CMD$LEN-2;
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
DO WHILE J > 0;
|+ 4005
DO I = 1 TO J;
|-
CMD$LINE(I+1) = CMD$LINE(I+1) + 10*(CMD$LINE(I) AND 1);
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───
CMD$LINE(I) = CMD$LINE(I) / 2;
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | Θ
END;
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───
J = J - 1;
|}
END;
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 8017
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 326205
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 886205
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 1081439556
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●<br>───<br>───<br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 503491211079
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
|}
 
/* FIND FIRST NONZERO DIGIT */
=={{header|Phix}}==
J = 1;
{{trans|Perl 6}}
DO WHILE CMD$LINE(J) = 0 AND J < CMD$LEN-1;
Three-way output controlled by the first two constants.
J = J + 1;
<lang Phix>-- demo\rosetta\Mayan_numerals.exw
END;
constant as_html = true, -- false == nasty ascii
inline_css = true -- also uses wiki tables ({| etc) if false
 
/* PRINT CARTOUCHES */
string html = ""
DECLARE SIZE BYTE;
SIZE = CMD$LEN-J;
CALL BORDER(SIZE);
DO I=0 TO 3;
CALL LINE(I, .CMD$LINE(J), SIZE);
END;
CALL BORDER(SIZE);
 
CALL EXIT;
constant t_style = "border-collapse: separate; text-align: center; border-spacing: 3px 0px;",
EOF</syntaxhighlight>
c_style = "border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;"&
{{out}}
"border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;"&
<pre style='height:50ex;'>A>MAYAN 4005
"vertical-align: bottom;width: 3.25em;",
+----+----+----+
dot = "&#x25cf;",
| | | bar = "&#x2500;&#x2500;&#x2500;", |
| | | zero = "&#x0398;", |
|----| | |
digits = {" 0 "," . "," .. ","... ","...."}
|----| @ |----|
+----+----+----+
 
A>MAYAN 8017
function to_seq(atom a)
+----+----+----+----+
sequence s = {}
| while| true do | | .. |
| | s| = prepend(s,remainder(a,20)) |----|
| | a| = floor(a/20) |----|
| . | @ | @ if a=0 then exit end if|----|
+----+----+----+----+
end while
return s
end function
 
A>MAYAN 326205
procedure show_mayan(atom a)
+----+----+----+----+----+
sequence s = to_seq(a)
| | | | | |
if not as_html then
| | |----| | |
string tb = join(repeat('+',length(s)+1),"------"),
| | |----|----| |
ln = join(repeat('|',length(s)+1)," ")
| .. | @ |----|----|----|
sequence res = {tb,ln,ln,ln,ln,tb}
+----+----+----+----+----+
for i=1 to length(s) do
integer si = s[i], l = 5, m = i*7-4
while true do
res[l][m..m+3] = digits[min(si+1,5)]
si -= 5
if si<=0 then exit end if
l -= 1
end while
end for
printf(1,"%d\n%s\n\n",{a,join(res,"\n")})
else
for i=1 to length(s) do
sequence res = repeat("",4)
integer si = s[i], l = 4
while true do
res[l] = iff(si>=5?bar:iff(si?join(repeat(dot,si),""):zero))
si -= 5
if si<=0 then exit end if
l -= 1
end while
s[i] = join(res,"<br>")
end for
if inline_css then
html &= sprintf(" <table>\n <caption>%d</caption>\n <tr>\n",a)
for i=1 to length(s) do
html &= sprintf(" <td>%s</td>\n",{s[i]})
end for
html &= " </tr>\n </table>\n"
else
html &= sprintf("{| style=\"%s\"\n|+ %d\n|-\n",{t_style,a})
for i=1 to length(s) do
html &= sprintf("| style=\"%s\" | %s\n",{c_style,s[i]})
end for
html &= "|}\n"
end if
end if
end procedure
 
A>MAYAN 886205
constant html_header = """
+----+----+----+----+----+
<!DOCTYPE html>
| | | | | |
<html lang="en">
| | |----| | |
<head>
| |----|----|----| |
<meta charset="utf-8" />
|----|----|----|----|----|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+----+----+----+----+----+
<title>Mayan numerals</title>
<style>
table {%s}
td { %s }
</style>
</head>
<body>
<h2>Mayan numerals</h2>
""",
wiki_header = """
The following is intended to be pasted into the rosettacode wiki, or similar<br>
""",
html_footer = """
</body>
</html>
"""
 
A>MAYAN 18380658207197784
constant tests = {4005, 8017, 326205, 886205, 26960840421, 126524984376952}
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| | | |....| | | | | |....| | | |
| | |....|----|....| | | |....|----|....| | |
| |....|----|----|----|....| |....|----|----|----|....| |
|....|----|----|----|----|----|....|----|----|----|----|----|....|
+----+----+----+----+----+----+----+----+----+----+----+----+----+</pre>
 
=={{header|Phix}}==
for i=1 to length(tests) do show_mayan(tests[i]) end for
{{trans|Raku}}
 
Three-way output controlled by the first two constants.
if as_html then
<!--<syntaxhighlight lang="phix">(notonline)-->
string filename = "Mayan_numerals.html"
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Mayan_numerals.exw</span>
integer fn = open(filename,"w")
<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>
if inline_css then
<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>
printf(fn,html_header,{t_style,c_style})
<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>
else
printf(fn,wiki_header)
<span style="color: #004080;">string</span> <span style="color: #000000;">html</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
end if
puts(fn,html)
<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>
if inline_css then
<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>
puts(fn,html_footer)
<span style="color: #008000;">"border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;"</span><span style="color: #0000FF;">&</span>
end if
<span style="color: #008000;">"vertical-align: bottom;width: 3.25em;"</span><span style="color: #0000FF;">,</span>
close(fn)
<span style="color: #000000;">dot</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x25cf;"</span><span style="color: #0000FF;">,</span>
if inline_css then
<span style="color: #000000;">bar</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x2500;&#x2500;&#x2500;"</span><span style="color: #0000FF;">,</span>
system(filename)
<span style="color: #000000;">zero</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"&#x0398;"</span><span style="color: #0000FF;">,</span>
else
<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>
printf(1,"See %s\n",{filename})
{} = wait_key()
<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>
end if
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
else
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
?"done"
<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>
{} = wait_key()
<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 if</lang>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<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>
<span style="color: #000000;">si</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">5</span>
<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>
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<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>
<span style="color: #008080;">else</span>
<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>
<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>
<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>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<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>
<span style="color: #000000;">si</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">5</span>
<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>
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</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: #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>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</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;">" &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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" &lt;/tr&gt;\n &lt;/table&gt;\n"</span>
<span style="color: #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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">html</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">"|}\n"</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">html_header</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Mayan numerals&lt;/title&gt;
&lt;style&gt;
table {%s}
td { %s }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Mayan numerals&lt;/h2&gt;
"""</span><span style="color: #0000FF;">,</span>
<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;
"""</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">html_footer</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
&lt;/body&gt;
&lt;/html&gt;
"""</span>
<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>
<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>
<span style="color: #008080;">if</span> <span style="color: #000000;">as_html</span> <span style="color: #008080;">then</span>
<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>
<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>
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
<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>
<span style="color: #008080;">else</span>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<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>
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">inline_css</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">system</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">else</span>
<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>
<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>
<span style="color: #008080;">else</span>
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
<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 1,761 ⟶ 3,944:
<br>
{{out}}
With inline_css set to true. As noted on the perl6Raku entry, this is much neater, but does not display nicely on this page.<br>
<small>
(These captions are centred; to exactly match the above just add a simple caption {text-align: left;} in the style section.)
Line 1,901 ⟶ 4,084:
| .... | .... | .. | .... | .... | .... | .... | .... | .. | .... | .... |
+------+------+------+------+------+------+------+------+------+------+------+
</pre>
 
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">#START_X=-4 : #START_Y=2
Dim pl$(5)
pl$(0)=" Θ " : pl$(1)=" • " : pl$(2)=" •• "
pl$(3)="••• " : pl$(4)="••••" : pl$(5)="‒‒‒‒"
If OpenConsole() : EnableGraphicalConsole(1) : Else : End 1 : EndIf
 
Procedure.s Dec2Mayan(wert.i)
result$=""
If wert=0 : result$="0;" : EndIf
While wert : result$=Str(wert%20)+";"+result$ : wert/20 : Wend
ProcedureReturn result$
EndProcedure
 
Procedure PutMayan(may$)
Shared pl$()
X=#START_X+6 : Y=#START_Y
For i=1 To CountString(may$,";")
m=Val(StringField(may$,i,";"))
yp=Y+4
If m=0 : ConsoleLocate(X,yp) : Print(pl$(0)) : X+5 : Continue : EndIf
While m
If m-5>=0
ConsoleLocate(X,yp) : Print(pl$(5)) : yp-1 : m-5
ElseIf m-4>=0
ConsoleLocate(X,yp) : Print(pl$(4)) : yp-1 : m-4
ElseIf m-3>=0
ConsoleLocate(X,yp) : Print(pl$(3)) : yp-1 : m-3
ElseIf m-2>=0
ConsoleLocate(X,yp) : Print(pl$(2)) : yp-1 : m-2
ElseIf m-1>=0
ConsoleLocate(X,yp) : Print(pl$(1)) : yp-1 : m-1
EndIf
Wend
X+5
Next
EndProcedure
 
Procedure MayanNumerals(may$)
X=#START_X : Y=#START_Y
m.i=CountString(may$,";")
For i=1 To m
X+5
ConsoleLocate(X,Y) : Print("╔════╗")
ConsoleLocate(X,Y+1) : Print("║ ║")
ConsoleLocate(X,Y+2) : Print("║ ║")
ConsoleLocate(X,Y+3) : Print("║ ║")
ConsoleLocate(X,Y+4) : Print("║ ║")
ConsoleLocate(X,Y+5) : Print("╚════╝")
Next
X=#START_X
For i=1 To m
X+5
If i<m
ConsoleLocate(X+5,Y) : Print("╦")
ConsoleLocate(X+5,Y+5) : Print("╩")
EndIf
Next
PutMayan(may$)
EndProcedure
 
Repeat
ConsoleLocate(0,0) : Print(LSet(" ",60))
ConsoleLocate(0,0) : Print("MAYAN: ? ") : i$=Input()
ClearConsole() : If i$="" : End : EndIf
j$=Dec2Mayan(Val(i$)) : MayanNumerals(j$)
ConsoleLocate(0,#START_Y+7) : Print("Dezimal = "+i$)
ConsoleLocate(0,#START_Y+8) : Print("Vigesimal= "+j$)
ForEver</syntaxhighlight>
{{out}}
<pre>MAYAN: ?
╔════╦════╦════╗
║ ║ ║ ║
║ ║ ║ ║
║‒‒‒‒║ ║ ║
║‒‒‒‒║ Θ ║‒‒‒‒║
╚════╩════╩════╝
 
Dezimal = 4005
Vigesimal= 10;0;5;
 
MAYAN: ?
╔════╦════╦════╦════╗
║ ║ ║ ║ •• ║
║ ║ ║ ║‒‒‒‒║
║ ║ ║ ║‒‒‒‒║
║ • ║ Θ ║ Θ ║‒‒‒‒║
╚════╩════╩════╩════╝
 
Dezimal = 8017
Vigesimal= 1;0;0;17;
 
MAYAN: ?
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║‒‒‒‒║ ║ ║
║ ║ ║‒‒‒‒║‒‒‒‒║ ║
║ •• ║ Θ ║‒‒‒‒║‒‒‒‒║‒‒‒‒║
╚════╩════╩════╩════╩════╝
 
Dezimal = 326205
Vigesimal= 2;0;15;10;5;
 
MAYAN: ?
╔════╦════╦════╦════╦════╗
║ ║ ║ ║ ║ ║
║ ║ ║‒‒‒‒║ ║ ║
║ ║‒‒‒‒║‒‒‒‒║‒‒‒‒║ ║
║‒‒‒‒║‒‒‒‒║‒‒‒‒║‒‒‒‒║‒‒‒‒║
╚════╩════╩════╩════╩════╝
 
Dezimal = 886205
Vigesimal= 5;10;15;10;5;
</pre>
 
=={{header|Python}}==
{{Works with|Python|3.7}}
<langsyntaxhighlight Pythonlang="python">'''Mayan numerals'''
 
from functools import (reduce)
 
 
# MAYAN NUMERALS ---------------------- MAYAN NUMERALS --------------------
 
# mayanNumerals :: Int -> [[String]]
Line 1,957 ⟶ 4,255:
 
 
# TEST --------------------------- TEST -------------------------
 
# main :: IO ()
Line 1,971 ⟶ 4,269:
 
 
# BOXES -------------------------- BOXES -------------------------
 
# wikiTable :: Dict -> [[a]] -> String
Line 1,988 ⟶ 4,286:
return lambda rows: '{| ' + reduce(
lambda a, k: (
a + k + '="' + opts[k] + '" ' if k in opts else a(
k in opts
) else a
),
['class', 'style'],
Line 1,994 ⟶ 4,294:
) + '\n' + '\n|-\n'.join(
'\n'.join(
('|' if (0 != i and ('cell' not in opts)) else (
0 != i and ('cell' not in opts)
) else (
'|style="' + colWidth() + cellStyle() + '"|'
)) + (
Line 2,003 ⟶ 4,305:
 
 
# GENERIC ------------------------- GENERIC ------------------------
 
# cssFromDict :: Dict -> String
Line 2,009 ⟶ 4,311:
'''CSS string from a dictinary of key-value pairs'''
return reduce(
lambda a, k: a + k + ':' + dct[k] + '; ', dct.keys(), ''
dct.keys(),
''
)
 
 
# showIntAtBase :: Int -> (Int -> String) -> Int -> String -> String
# -> Int -> String -> String
def showIntAtBase(base):
'''String representation of an integer in a given base,
using a supplied function for the string representation
representation of digits.
'''
def wrap(toChr, n, rs):
Line 2,035 ⟶ 4,340:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
Mayan numeral representations of various integers:
Line 2,115 ⟶ 4,420:
|style="width:3em; vertical-align: bottom;"|Θ
|}
 
=={{header|Raku}}==
(formerly Perl 6)
 
Just a matter of converting to base twenty, then divmod 5 each digit and map to the appropriate glyph. Most of this is display code to deal with the cartouche requirement.
 
I actually spent a little time looking into what exactly a Mayan cartouche was supposed to look like. The classic Mayan cartouche was kind of a rounded rectangle with three little semi-circles underneath. Kind of looks like a picture frame. In general, they were only used when expressing significant "holy" dates in the Mayan calender.
 
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" line>### 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;'~
'border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;'~
'vertical-align: bottom;width: 3.25em;"';
my $joiner = '<br>';
 
sub display ($num, @digits) { join "\n", "\{| style=$t-style", "|+ $num", '|-', (|@digits.map: {"| style=$c-style | $_"}), '|}' }
 
### Logic ###
 
sub mayan ($int) { $int.polymod(20 xx *).reverse.map: *.polymod(5) }
 
my @output = <4005 8017 326205 886205 16160025 1081439556 503491211079>.map: {
display $_, .&mayan.map: { [flat '' xx 3, '●' x .[0], '───' xx .[1], ('Θ' if !.[0,1].sum)].tail(4).join: $joiner }
}
 
say @output.join: "\n$joiner\n";
</syntaxhighlight>
 
{{out}}
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 4005
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 8017
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 326205
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 886205
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 16160025
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 1081439556
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●<br>───<br>───<br>───
|}
<br>
{| style="border-collapse: separate; text-align: center; border-spacing: 3px 0px;"
|+ 503491211079
|-
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>●●●<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>●●<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>Θ
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br><br>●
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br><br>●●<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | <br>●●●<br>───<br>───
| style="border: solid black 2px;background-color: #fffff0;border-bottom: double 6px;border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;vertical-align: bottom;width: 3.25em;" | ●●●●<br>───<br>───<br>───
|}
 
 
 
Or, plain old text mode. Not as pretty, but still serviceable.
 
<syntaxhighlight lang="raku" line>### Formatting ###
use Terminal::Boxer;
my $joiner = "\n";
 
sub display ($num, @digits) { "$num\n" ~ dd-box( :6cw, :4ch, @digits ) }
 
### Logic ###
 
sub mayan ($int) { $int.polymod(20 xx *).reverse.map: *.polymod(5) }
 
my @output = <4005 8017 326205 886205 16160025 1081439556 503491211079>.map: {
display $_, .&mayan.map: { [flat '' xx 3, '●' x .[0], '────' xx .[1], ('Θ' if !.[0,1].sum)].tail(4).join: $joiner }
}
 
say @output.join: $joiner;</syntaxhighlight>
 
{{out}}
<pre style="font-family: consolas, inconsolata, monospace; line-height: normal;">4005
╔══════╦══════╦══════╗
║ ║ ║ ║
║ ║ ║ ║
║ ──── ║ ║ ║
║ ──── ║ Θ ║ ──── ║
╚══════╩══════╩══════╝
 
8017
╔══════╦══════╦══════╦══════╗
║ ║ ║ ║ ●● ║
║ ║ ║ ║ ──── ║
║ ║ ║ ║ ──── ║
║ ● ║ Θ ║ Θ ║ ──── ║
╚══════╩══════╩══════╩══════╝
 
326205
╔══════╦══════╦══════╦══════╦══════╗
║ ║ ║ ║ ║ ║
║ ║ ║ ──── ║ ║ ║
║ ║ ║ ──── ║ ──── ║ ║
║ ●● ║ Θ ║ ──── ║ ──── ║ ──── ║
╚══════╩══════╩══════╩══════╩══════╝
 
886205
╔══════╦══════╦══════╦══════╦══════╗
║ ║ ║ ║ ║ ║
║ ║ ║ ──── ║ ║ ║
║ ║ ──── ║ ──── ║ ──── ║ ║
║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║
╚══════╩══════╩══════╩══════╩══════╝
 
16160025
╔══════╦══════╦══════╦══════╦══════╦══════╗
║ ║ ║ ║ ║ ║ ║
║ ║ ║ ║ ║ ║ ║
║ ║ ║ ║ ║ ║ ║
║ ──── ║ ● ║ Θ ║ Θ ║ ● ║ ──── ║
╚══════╩══════╩══════╩══════╩══════╩══════╝
 
1081439556
╔══════╦══════╦══════╦══════╦══════╦══════╦══════╗
║ ● ║ ●● ║ ●●● ║ ●●●● ║ ●●● ║ ●● ║ ● ║
║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║
║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║
║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║ ──── ║
╚══════╩══════╩══════╩══════╩══════╩══════╩══════╝
 
503491211079
╔══════╦══════╦══════╦══════╦══════╦══════╦══════╦══════╦══════╗
║ ●●●● ║ ║ ║ ║ ║ ║ ║ ║ ●●●● ║
║ ──── ║ ●●● ║ ║ ║ ║ ║ ║ ●●● ║ ──── ║
║ ──── ║ ──── ║ ●● ║ ║ ║ ║ ●● ║ ──── ║ ──── ║
║ ──── ║ ──── ║ ──── ║ ● ║ Θ ║ ● ║ ──── ║ ──── ║ ──── ║
╚══════╩══════╩══════╩══════╩══════╩══════╩══════╩══════╩══════╝
</pre>
 
=={{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 2,129 ⟶ 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 2,182 ⟶ 4,669:
║────║────║ Θ ║ ∙ ║────║ Θ ║────║ ∙ ║────║────║ Θ ║ ∙ ║────║ Θ ║────║ ∙ ║
╚════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╩════╝
</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}}==
<syntaxhighlight lang="rust">const ONE: &str = "●";
const FIVE: &str = "——";
const ZERO: &str = "Θ";
 
fn main() {
println!("{}", mayan(4005));
println!("{}", mayan(8017));
println!("{}", mayan(326_205));
println!("{}", mayan(886_205));
println!("{}", mayan(69));
println!("{}", mayan(420));
println!("{}", mayan(1_063_715_456));
}
 
fn mayan(dec: i64) -> String {
let mut digits = vec![];
let mut num = dec;
while num > 0 {
digits.push(num % 20);
num /= 20;
}
digits = digits.into_iter().rev().collect();
let mut boxes = vec!["".to_string(); 6];
let n = digits.len();
for (i, digit) in digits.iter().enumerate() {
if i == 0 {
boxes[0] = "┏━━━━".to_string();
if i == n - 1 {
boxes[0] += "┓";
}
} else if i == n - 1 {
boxes[0] += "┳━━━━┓";
} else {
boxes[0] += "┳━━━━";
}
for j in 1..5 {
boxes[j] += "┃";
let elem = 0.max(digit - (4 - j as i64) * 5);
if elem >= 5 {
boxes[j] += &format!("{: ^4}", FIVE);
} else if elem > 0 {
boxes[j] += &format!("{: ^4}", ONE.repeat(elem as usize % 15));
} else if j == 4 {
boxes[j] += &format!("{: ^4}", ZERO);
} else {
boxes[j] += &" ";
}
if i == n - 1 {
boxes[j] += "┃";
}
}
if i == 0 {
boxes[5] = "┗━━━━".to_string();
if i == n - 1 {
boxes[5] += "┛";
}
} else if i == n - 1 {
boxes[5] += "┻━━━━┛";
} else {
boxes[5] += "┻━━━━";
}
}
 
let mut mayan = format!("Mayan {}:\n", dec);
for b in boxes {
mayan += &(b + "\n");
}
mayan
}</syntaxhighlight>
{{out}}
<pre>
Mayan 4005:
┏━━━━┳━━━━┳━━━━┓
┃ ┃ ┃ ┃
┃ ┃ ┃ ┃
┃ —— ┃ ┃ ┃
┃ —— ┃ Θ ┃ —— ┃
┗━━━━┻━━━━┻━━━━┛
 
Mayan 8017:
┏━━━━┳━━━━┳━━━━┳━━━━┓
┃ ┃ ┃ ┃ ●● ┃
┃ ┃ ┃ ┃ —— ┃
┃ ┃ ┃ ┃ —— ┃
┃ ● ┃ Θ ┃ Θ ┃ —— ┃
┗━━━━┻━━━━┻━━━━┻━━━━┛
 
Mayan 326205:
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ ┃ ┃ ┃ ┃ ┃
┃ ┃ ┃ —— ┃ ┃ ┃
┃ ┃ ┃ —— ┃ —— ┃ ┃
┃ ●● ┃ Θ ┃ —— ┃ —— ┃ —— ┃
┗━━━━┻━━━━┻━━━━┻━━━━┻━━━━┛
 
Mayan 886205:
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ ┃ ┃ ┃ ┃ ┃
┃ ┃ ┃ —— ┃ ┃ ┃
┃ ┃ —— ┃ —— ┃ —— ┃ ┃
┃ —— ┃ —— ┃ —— ┃ —— ┃ —— ┃
┗━━━━┻━━━━┻━━━━┻━━━━┻━━━━┛
 
Mayan 69:
┏━━━━┳━━━━┓
┃ ┃ ┃
┃ ┃ ┃
┃ ┃●●●●┃
┃●●● ┃ —— ┃
┗━━━━┻━━━━┛
 
Mayan 420:
┏━━━━┳━━━━┳━━━━┓
┃ ┃ ┃ ┃
┃ ┃ ┃ ┃
┃ ┃ ┃ ┃
┃ ● ┃ ● ┃ Θ ┃
┗━━━━┻━━━━┻━━━━┛
 
Mayan 1063715456:
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ ● ┃ ┃ ┃ ┃ ┃ ┃ ● ┃
┃ —— ┃ ●● ┃ ┃ ┃ ┃ ●● ┃ —— ┃
┃ —— ┃ —— ┃●●● ┃ ┃●●● ┃ —— ┃ —— ┃
┃ —— ┃ —— ┃ —— ┃●●●●┃ —— ┃ —— ┃ —— ┃
┗━━━━┻━━━━┻━━━━┻━━━━┻━━━━┻━━━━┻━━━━┛
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./fmt" for Conv
 
var ul = "╔"
var uc = "╦"
var ur = "╗"
var ll = "╚"
var lc = "╩"
var lr = "╝"
var hb = "═"
var vb = "║"
 
var mayan= [
" ",
" ∙ ",
" ∙∙ ",
"∙∙∙ ",
"∙∙∙∙"
]
 
var m0 = " Θ "
var m5 = "────"
 
var dec2vig = Fn.new { |n| Conv.itoa(n, 20).map { |c| Conv.atoi(c, 20) }.toList }
 
var vig2quin = Fn.new { |n|
if (n >= 20) Fiber.abort("Cant't convert a number >= 20.")
var res = [mayan[0], mayan[0], mayan[0], mayan[0]]
if (n == 0) {
res[3] = m0
return res
}
var fives = (n/5).floor
var rem = n % 5
res[3-fives] = mayan[rem]
for (i in 3...3-fives) res[i] = m5
return res
}
 
var draw = Fn.new { |mayans|
var lm = mayans.count
System.write(ul)
for (i in 0...lm) {
for (j in 0..3) System.write(hb)
if (i < lm - 1) {
System.write(uc)
} else {
System.print(ur)
}
}
for (i in 1..4) {
System.write(vb)
for (j in 0...lm) {
System.write(mayans[j][i-1])
System.write(vb)
}
System.print()
}
System.write(ll)
for (i in 0...lm) {
for (j in 0..3) System.write(hb)
if (i < lm - 1) {
System.write(lc)
} else {
System.print(lr)
}
}
}
 
var numbers = [4005, 8017, 326205, 886205, 1081439556]
for (n in numbers) {
System.print("Converting %(n) to Mayan:")
var vigs = dec2vig.call(n)
var mayans = vigs.map { |vig| vig2quin.call(vig) }.toList
draw.call(mayans)
System.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|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 2,193 ⟶ 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 2,253 ⟶ 5,059:
╚════╩════╩════╩════╩════╩════╩════╝
</pre>
The Perl6Raku numerals look so good, let's copy them.
{{trans|Perl6Raku}}
<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 2,276 ⟶ 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