Mayan calendar: Difference between revisions
Content deleted Content added
Python 3.6 code for mayan calendar solving task |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 213: | Line 213: | ||
2020-03-01 |
2020-03-01 |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
<syntaxhighlight lang="fortran"> |
|||
<lang Fortran> |
|||
PROGRAM MAYA_DRIVER |
PROGRAM MAYA_DRIVER |
||
IMPLICIT NONE |
IMPLICIT NONE |
||
Line 375: | Line 375: | ||
END SUBROUTINE maya_time |
END SUBROUTINE maya_time |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 390: | Line 390: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 491: | Line 491: | ||
fmt.Printf("%s %2d %-8s %4s %-9s %-14s %s\n", dt, n, s, d, m, lc, l) |
fmt.Printf("%s %2d %-8s %4s %-9s %-14s %s\n", dt, n, s, d, m, lc, l) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 511: | Line 511: | ||
Implementation: |
Implementation: |
||
< |
<syntaxhighlight lang="j">require 'types/datetime' |
||
NB. 1794214= (0 20 18 20 20#.13 0 0 0 0)-todayno 2012 12 21 |
NB. 1794214= (0 20 18 20 20#.13 0 0 0 0)-todayno 2012 12 21 |
||
Line 535: | Line 535: | ||
round=: [:;:inv tsolkin;haab;'G',&":1+9|] |
round=: [:;:inv tsolkin;haab;'G',&":1+9|] |
||
gmt=: >@(fmtDate;round;longcount)@todayno</ |
gmt=: >@(fmtDate;round;longcount)@todayno</syntaxhighlight> |
||
J's <tt>todayno</tt> counts days from January 1, 1800. And, each of these date formatting routines expects a number generated by todayno, with hard coded offsets, if necessary, to make this work. (The lord of night number uses an offset of zero, in this context.) |
J's <tt>todayno</tt> counts days from January 1, 1800. And, each of these date formatting routines expects a number generated by todayno, with hard coded offsets, if necessary, to make this work. (The lord of night number uses an offset of zero, in this context.) |
||
Line 542: | Line 542: | ||
Task examples: |
Task examples: |
||
< |
<syntaxhighlight lang="j"> gmt 2004 6 19 |
||
June 19, 2004 |
June 19, 2004 |
||
4 Ben 16 Sotz’ G7 |
4 Ben 16 Sotz’ G7 |
||
Line 575: | Line 575: | ||
March 1, 2019 |
March 1, 2019 |
||
3 Imix’ 14 K’ayab G2 |
3 Imix’ 14 K’ayab G2 |
||
13.0.5.13.1</ |
13.0.5.13.1</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="julia">using Dates |
||
const Tzolk´in = [ |
const Tzolk´in = [ |
||
Line 632: | Line 632: | ||
rpad(haab(date), 15), nightlord(date)) |
rpad(haab(date), 15), nightlord(date)) |
||
end |
end |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Gregorian Long Count Tzolk´in Haab´ Nightlord |
Gregorian Long Count Tzolk´in Haab´ Nightlord |
||
Line 649: | Line 649: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">sacred = {"Imix\[CloseCurlyQuote]", "Ik\[CloseCurlyQuote]", |
||
"Ak\[CloseCurlyQuote]bal", "K\[CloseCurlyQuote]an", "Chikchan", |
"Ak\[CloseCurlyQuote]bal", "K\[CloseCurlyQuote]an", "Chikchan", |
||
"Kimi", "Manik\[CloseCurlyQuote]", "Lamat", "Muluk", "Ok", |
"Kimi", "Manik\[CloseCurlyQuote]", "Lamat", "Muluk", "Ok", |
||
Line 715: | Line 715: | ||
longcountdata = LongCount /@ data; |
longcountdata = LongCount /@ data; |
||
lotndata = LordOfTheNight /@ data; |
lotndata = LordOfTheNight /@ data; |
||
{DateObject /@ data, tzolkindata, haabdata, longcountdata, lotndata} // Transpose // Grid</ |
{DateObject /@ data, tzolkindata, haabdata, longcountdata, lotndata} // Transpose // Grid</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Sat 19 Jun 2004 4 Ben 16 Sotz' 12.19.11.6.13 G7 |
<pre>Sat 19 Jun 2004 4 Ben 16 Sotz' 12.19.11.6.13 G7 |
||
Line 728: | Line 728: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="nim">import math, strformat, times |
||
const |
const |
||
Line 791: | Line 791: | ||
for date in testDates: |
for date in testDates: |
||
let dateStr = date.format("YYYY-MM-dd") |
let dateStr = date.format("YYYY-MM-dd") |
||
echo &"{dateStr:14} {date.toLongDate:16} {tzolkin(date):9} {haab(date):14} {nightLord(date)}"</ |
echo &"{dateStr:14} {date.toLongDate:16} {tzolkin(date):9} {haab(date):14} {nightLord(date)}"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 810: | Line 810: | ||
The module <code>Math::BaseArith</code> provides mixed-radix conversion via the <code>encode</code> routine (named as in '''APL'''). |
The module <code>Math::BaseArith</code> provides mixed-radix conversion via the <code>encode</code> routine (named as in '''APL'''). |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use utf8; |
use utf8; |
||
Line 888: | Line 888: | ||
printf "%10s %2s %-9s %4s %-10s %-14s G%d\n", |
printf "%10s %2s %-9s %4s %-10s %-14s G%d\n", |
||
$date, mayan_calendar_round($date), join('.',mayan_long_count($date)), lord($date); |
$date, mayan_calendar_round($date), join('.',mayan_long_count($date)), lord($date); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> Gregorian Tzolk’in Haab’ Long Lord of |
<pre> Gregorian Tzolk’in Haab’ Long Lord of |
||
Line 906: | Line 906: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 984: | Line 984: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,005: | Line 1,005: | ||
{{works with|Python|3.6}} |
{{works with|Python|3.6}} |
||
< |
<syntaxhighlight lang="python"> |
||
import datetime |
import datetime |
||
Line 1,076: | Line 1,076: | ||
long, round = g2m(date) |
long, round = g2m(date) |
||
print(date, long, round) |
print(date, long, round) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,093: | Line 1,093: | ||
{{works with|Rakudo|2018.12}} |
{{works with|Rakudo|2018.12}} |
||
<lang |
<syntaxhighlight lang="raku" line>my @sacred = <Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok |
||
Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>; |
Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>; |
||
Line 1,164: | Line 1,164: | ||
printf "%10s %2s %-9s %4s %-10s %-14s %6s\n", Date.new($date), |
printf "%10s %2s %-9s %4s %-10s %-14s %6s\n", Date.new($date), |
||
flat mayan-calendar-round($date), mayan-long-count($date).join('.'), lord($date); |
flat mayan-calendar-round($date), mayan-long-count($date).join('.'), lord($date); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> Gregorian Tzolk’in Haab’ Long Lord of |
<pre> Gregorian Tzolk’in Haab’ Long Lord of |
||
Line 1,183: | Line 1,183: | ||
{{libheader|Wren-date}} |
{{libheader|Wren-date}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/date" for Date |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 1,262: | Line 1,262: | ||
var l = lord.call(date) |
var l = lord.call(date) |
||
Fmt.lprint("$s $2d $-8s $4s $-9s $-14s $s", [dt, n, s, d, m, lc, l]) |
Fmt.lprint("$s $2d $-8s $4s $-9s $-14s $s", [dt, n, s, d, m, lc, l]) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,283: | Line 1,283: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="zkl">var [const] |
||
sacred=T("Imix'","Ik'","Ak'bal","K'an","Chikchan","Kimi","Manik'","Lamat","Muluk","Ok", |
sacred=T("Imix'","Ik'","Ak'bal","K'an","Chikchan","Kimi","Manik'","Lamat","Muluk","Ok", |
||
"Chuwen","Eb","Ben","Hix","Men","K'ib'","Kaban","Etz'nab'","Kawak","Ajaw"), |
"Chuwen","Eb","Ben","Hix","Men","K'ib'","Kaban","Etz'nab'","Kawak","Ajaw"), |
||
Line 1,331: | Line 1,331: | ||
if(rem<=0) rem=9 + rem; |
if(rem<=0) rem=9 + rem; |
||
"G%d".fmt(rem) |
"G%d".fmt(rem) |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">println(" Gregorian Tzolk'in Haab' Long Lord of"); |
||
println(" Date # Name Day Month Count the Night"); |
println(" Date # Name Day Month Count the Night"); |
||
println("---------- -------- ------------- -------------- ---------"); |
println("---------- -------- ------------- -------------- ---------"); |
||
Line 1,348: | Line 1,348: | ||
longCount(ymd).concat("."), |
longCount(ymd).concat("."), |
||
lord(ymd))); |
lord(ymd))); |
||
});</ |
});</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |