Jump to content

Mayan numerals: Difference between revisions

Added 11l
(Added Fōrmulæ solution)
(Added 11l)
Line 140:
:*   The Wikipedia entry:   [[https://en.wikipedia.org/wiki/Maya_numerals Mayan numerals]]
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<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()</lang>
 
{{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}}==
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.