# Name the Aztec year

It's time for another Mesoamerican calendar! The Xiuhnelpilli was used by the Aztecs (more properly, the Mexica) to name their years. Each year has a number and a sign. Here's part of the cycle:

Input; Output
1089; 13 Calli
1090; 1 Tochtli
1091; 2 Acatl
1092; 3 Tecpatl
1093; 4 Calli
1094; 5 Tochtli
1095; 6 Acatl
1096; 7 Tecpatl
1097; 8 Calli
1098; 9 Tochtli
1099; 10 Acatl
1100; 11 Tecpatl
1101; 12 Calli
1102; 13 Tochtli
1103; 1 Acatl
1104; 2 Tecpatl
1105; 3 Calli
1106; 4 Tochtli
1107; 5 Acatl
1108; 6 Tecpatl
1109; 7 Calli
1110; 8 Tochtli
1111; 9 Acatl
1112; 10 Tecpatl
1113; 11 Calli
1114; 12 Tochtli
1115; 13 Acatl
1116; 1 Tecpatl
1117; 2 Calli
1118; 3 Tochtli
1119; 4 Acatl
1120; 5 Tecpatl
1121; 6 Calli
1122; 7 Tochtli
1123; 8 Acatl
1124; 9 Tecpatl
1125; 10 Calli
1126; 11 Tochtli
1127; 12 Acatl
1128; 13 Tecpatl
1129; 1 Calli
1130; 2 Tochtli
1131; 3 Acatl
1132; 4 Tecpatl
1133; 5 Calli
1134; 6 Tochtli
1135; 7 Acatl
1136; 8 Tecpatl
1137; 9 Calli
1138; 10 Tochtli
1139; 11 Acatl
1140; 12 Tecpatl
1141; 13 Calli
1142; 1 Tochtli


The pattern should be clear enough: the number is counting up to 13, and the sign goes Tochtli, Acatl, Tecpatl, Calli. After 52 years the pattern repeats itself.

The program will take as input an integer between 1064 (the year the Mexica left their mythological homeland of Aztlan) and 1521 (fall of Tenochtitlan to the Spaniards), inclusive, and output the corresponding year name. It can be a single string (in which case there needs to be a space between number and sign), or a tuple (e.g. ["2", "Calli"]) of your preferred format. The sign name is always capitalised.

Handling years outside the specified range is not necessary. It's , so the shortest code wins!

Test cases

The entire example list above, plus:

Input; Output
1064; 1 Tecpatl
1521; 3 Calli

• Can we output the numbers 1-13 with 0 indexing? i.e. can I output numbers 0-12? Do I have to output the 4 strings for the signs of the years? Can I output 4 distinct numbers? Or can I just output the first two letters, e.g. "To, Ac, Te, Ca"? or maybe 4 distinct letters, one per sign? e.g. "tOchtli, Acatl, tEcpatl, Calli"?
– RGS
Commented Jun 8, 2020 at 11:20
• @RGS No and no. Otherwise this would just be modding the year twice. The goal is a sensible Aztec name for a year, and they did not count from zero. Commented Jun 8, 2020 at 11:22
• @RGS Same reasoning: no. Commented Jun 8, 2020 at 11:29
• Does case matter? Can we output all uppercase or all lowercase? Commented Jun 8, 2020 at 15:11
• @Shaggy The sign must be capitalised. So title case. Commented Jun 8, 2020 at 16:13

# Python 3, 68 62 59 bytes

Saved 6 9 bytes thanks to my pronoun is monicareinstate!!!

lambda n:((n+2)%13+1,"TCTAeaocclcaplhtaitlt l l i"[n%4::4])


Try it online!

• 62 bytes without := assignment Commented Jun 8, 2020 at 12:27
• @mypronounismonicareinstate Nice one - thanks! :-) Commented Jun 8, 2020 at 12:31
• 59 bytes with every-nth-element indexing Commented Jun 8, 2020 at 12:39
• @mypronounismonicareinstate Ah yes, very good - thanks! :D Commented Jun 8, 2020 at 13:15

# dc, 63 62 characters

[Tecpatl]0:y[Calli]1:y[Tochtli]2:y[Acatl]3:y?d2+13%1+n32P4%;yp


Explained:

[Tecpatl] 0 :y    # store the string "Tecpatl" in array y at index 0
[Calli]   1 :y    # store the string "Calli" in array y at index 1
[Tochtli] 2 :y    # store the string "Tochtli" in array y at index 2
[Acatl]   3 :y    # store the string "Acatl" in array y at index 3
d                 # duplicate it to keep a copy for later
2+ 13% 1+ n       # the usual formula: (year + 2) % 13 + 1, then print it
32 P              # print a space
4 %               # use the left copy of input for formula: year % 4
;y p              # get the value from array y at the given index, then print it


Sample run:

bash-5.0$dc -e '[Tecpatl]0:y[Calli]1:y[Tochtli]2:y[Acatl]3:y?d2+13%1+n[ ]n4%;yp' <<< 1111 9 Acatl  # perl -pl, 61 bytes $_=(($_+3)%13||13).$".(qw[Tecpatl Calli Tochtli Acatl])[_%4]  Try it online! Nothing special going on, modding the year twice, with some aligning. " is a variable which by default holds a space.

• 59 bytes Commented Jun 8, 2020 at 11:21
• As well as Arnauld's change, you can use barewords instead of qw[...] and using -n and say+($_...,$",... instead of -p saves one too! Commented Jun 8, 2020 at 14:29

# Whitespace, 344 bytes

[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S N
S _Duplicate_input][S S S T S N
_Push_2][T  S S S _Add][S S S T T   S T N
_Push_13][T S T T   _Modulo][S S S T    N
_Push_1][T  S S S _Add][T   N
S T _Print_as_integer][S S S T  S S T   N
_Push_9_tab][T  N
S S _Print_as_character][S S S T    S S N
_Push_4][T  S T T   _Modulo][S N
S _Duplicate][N
T   S S N
_If_0_Jump_to_Label_0][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   S T N
_If_0_Jump_to_Label_1][S S S T  N
_Push_1][T  S S T   _Subtract][N
T   s S S N
_If_0_Jump_to_Label_2][S S S T  T   N
_Push_3_l][S S S T  S T T   N
_Push_11_t][S S T   T   S S S N
_Push_-8_a][S S T   T   T   S N
_Push_-6_c][S S T   T   S T S S S N
_Push_-40_A][N
S S N
_Create_Label_PRINT_LOOP][S S S T   T   S T S S T   N
_Push_105][T    S S S _Add][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_PRINT_LOOP][N
S S S N
_Create_Label_0][S N
N
_Discard][S S S T   T   N
_Push_3_l][S S S T  S T T   N
_Push_11_t][S S T   T   S S S N
_Push_-8_a][S S S T T   T   N
_Push_7_p][S S T    T   T   S N
_Push_-6_c][S S T   T   S S N
_Push_-4_e][S S T   T   S T S T N
_Push_-21_T][N
S N
N
_Jump_to_Label_PRINT_LOOP][N
S S T   N
_Create_Label_1][S N
N
_Push_0_i][S S S T  T   N
_Push_3_l][S N
S _Duplicate_3_l][S S T T   S S S N
_Push_-8_a][S S T   T   S S T   T   S N
_Push_-38_C][N
S N
N
_Jump_to_Label_PRINT_LOOP][N
S S S S N
_Create_Label_2][S S S N
_Push_0_i][S S S T  T   N
_Push_3_l][S S S T  S T T   N
_Push_11_t][S S T   T   N
_Push_-1_h][S S T   T   T   S N
_Push_-6_c][S S S T T   S N
_Push_6_o][S S T    T   S T S T N
_Push_-21_T][N
S N
N
_Jump_to_Label_PRINT_LOOP]


Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer year = STDIN as integer
Print (year+2) modulo-13 + 1 as integer to STDOUT
Print '\t' as character to STDOUT
Integer temp = year modulo-4
If(temp == 0):
Push the codepoints of "ltapceT" minus 105 to the stack
If(temp-1 == 0):
Push the codepoints of "illaC" minus 105 to the stack
If(temp-2 == 0):
Push the codepoints of "ilthcoT" minus 105 to the stack
Else:
Push the codepoints of "ltacA" minus 105 to the stack
Start PRINT_LOOP:
Add 105 to the top integer on the stack
Print this integer as character with this codepoint to STDOUT
Go to the next iteration of PRINT_LOOP


Uses this Whitespace tip of mine to print the output, which will exit the program with an error as soon as we're done with printing and the stack is empty. The optimal constant 105 is generated by this Java program.

# jq (with -r switch), 57 characters

"\((.+2)%13+1) "+("Tecpatl Calli Tochtli Acatl"/" ")[.%4]


Sample run:

bash-5.0$jq -r '"\((.+2)%13+1) "+("Tecpatl Calli Tochtli Acatl"/" ")[.%4]' <<< 1111 9 Acatl  # Java 8, 63 62 bytes y->1-~-~y%13+" "+"Tecpatl Calli Tochtli Acatl".split(" ")[y%4]  -1 byte thanks to @ceilingcat. Try it online. Explanation: y-> // Method with integer parameter and String return-type 1- // Decrease 1 by: ~-~y // (-y-2) %13 // Modulo-13 +" " // Append a space +"Tecpatl Calli Tochtli Acatl".split(" ") // Split these four words as array [y%4] // And take the (0-based) year-modulo-4'th value  # 05AB1E, 30 bytes Ì13%>.•19ŠSBÿ®Ï¿¾Ñλ1Ï7qι•#™Iè‚  Explanation: Ì # Increase the (implicit) input by 2 13% # Take modulo-13 on that > # And increase it by 1 .•19ŠSBÿ®Ï¿¾Ñλ1Ï7qι• # Push compressed string "tecpatl calli tochtli acatl" # # Split it on spaces: ["tecpatl","calli","tochtli","acatl"] ™ # Titlecase each: ["Tecpatl","Calli","Tochtli","Acatl"] Iè # Index the input into it (0-based and with automatic wraparound) ‚ # Pair the two together # (after which the result is output implicitly)  See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•19ŠSBÿ®Ï¿¾Ñλ1Ï7qι• is "tecpatl calli tochtli acatl". # Jelly, 36 bytes +3ịⱮ13R,“©ȥƒị Œñ⁾<ŻĠ)?ỵ%uxÐZỵȯẏ1»Ḳ¤¤  Try it online! ### How? +3ịⱮ13R,“...»Ḳ¤¤ - Link: integer, Y +3 - add three (to Y) ¤ - nilad followed by link(s) as a nilad: 13R - range(13) = [1,2,3,4,5,6,7,8,9,10,11,12,13] ¤ - nilad followed by link(s) as a nilad: “...» - compressed string = "Tochtli Acatl Tecpatl Calli" Ḳ - split at spaces = ["Tochtli","Acatl","Tecpatl","Calli"] , - pair these together = [[1,2,3,4,5,6,7,8,9,10,11,12,13],["Tochtli","Acatl","Tecpatl","Calli"]] Ɱ - map accross (these two lists) with: ị - index into (1-based & modular)  # APL (Dyalog Unicode), 55 54 bytesSBCS {((4 7⍴'TecpatlCalli TochtliAcatl ')⌷⍨4|⍵),1+13|2+⍵}  Try it online! • @KeizerHarm thanks! Fixed :) – RGS Commented Jun 8, 2020 at 13:01 • Use brackets for 51, or 48 with cyclic indexing trick. Commented Jun 9, 2020 at 7:47 # Befunge-93, 100 bytes &:2+67+%1+.4%:#v_"ltapceT",,v <"Calli"_v#!-1:<@,,,,, < < >2!#v_"ltacA"^ ^ ,,"Tochtli"<  Try it online! Reads the year from input, and duplicates it. Adds 2, mods it with 13, adds 1 to the result and prints it. Then mods the year with 4, and using a series if if statements, selects the right name to print. • In Befunge-98 (it's going to be less obvious in 93, but probably possible as well), a more usual-ish approach is likely possible: drop the first n%4*7 characters of "TecpatlCalli TochtliAcatl" with the help of k, then print 7 more characters of it. Commented Jun 8, 2020 at 14:38 # C (gcc), 87 $$\\cdots\$$ 70 69 bytes Saved 2 bytes thanks to my pronoun is monicareinstate!!! Saved a byte thanks to ceilingcat!!! f(n){printf("%d %.7s",1-~-~n%13,"TecpatlCalli TochtliAcatl"+n%4*7);}  Try it online! • "%.7s" I did not know printf can do this. 7*(n%4) -> n%4*7 should work. Commented Jun 8, 2020 at 12:29 • @mypronounismonicareinstate Yeah, printf has lots of formatting tricks - thanks! :) Commented Jun 8, 2020 at 12:35 # J, 43 bytes Straightforward implementation. Takes a number like 1090, returns boxed tuple [1|Tochtli]. (1+13|2+]);TecpatlCalliTochtliAcatl{~4|]  Try it online! ### How it works (1+13|2+]);TecpatlCalliTochtliAcatl{~4|] 4|] x mod 4 TecpatlCalliTochtliAcatl{~ select from boxes (1+13|2+]) ((x + 2) mod 4) + 1 ; join left & right side  # Charcoal, 38 bytes ＮθＩ⊕﹪⁺²θ¹³ §⪪”(0«βxo%↔W^⊘Ｓ≧L≔Z⮌⍘｜Nº” θ  Try it online! Link is to verbose version of code. Explanation: ＮθＩ⊕﹪⁺²θ¹³  Input the year, add 2, reduce modulo 13, add 1, and print as a string, followed by a space. §⪪”(0«βxo%↔W^⊘Ｓ≧L≔Z⮌⍘｜Nº” θ  Split the compressed string Tecpatl Calli Tochtli Acatl on spaces and print the entry cyclically indexed using the year. # Ruby, 54 bytes ->y{[(y+2)%13+1,%w[Tecpatl Calli Tochtli Acatl][y%4]]}  Try it online! # Pyth, 41 bytes (h%+2Q13@c." t£>Ì<ëWÈ¶Adh|Å],%œ¯s")%Q4  Try it online! The number is calculated with 1+((x+2)%13)), x being the input. The sign is retrieved by indexing into a packed string, split on whitespace. Oddly enough, using repeated indexing for the string (like in other answers) yielded the same bytecount for me. # JavaScript, 58 57 bytes -1 byte using the numerical method from @ceilingcat used in Kevin Cruijssen's Java answer n=>[1-~-~n%13,["Tecpatl","Calli","Tochtli","Acatl"][n%4]]  Try it online! It's been a long time since I got to a question fast enough to post a Javascript answer. (July 15, 2017 appears to have been my last for one that wasn't a king of the hill challenge.) Pretty straightforward, get the right number with some basic modular arithmetic and get the sign with some array indexing mod 4. # PHP, 69 bytes fn($n)=>(($n+2)%13+1).' '.['Tecpatl','Calli','Tochtli','Acatl'][$n%4]


Try it online!

Just a port of Abigail's perl answer using Arnauld's edit suggestion, i fear.. but I had to, it's a 69

# Kotlin, 72 bytes

fun f(x:Int)=(x+2)%13+1 to "Tecpatl Calli Tochtli Acatl".split(" ")[x%4]


Try it online!