# Chinese Zodiac of the year

2015 was the year of the goat! In this challenge, you will figure out which animal represents the year. To avoid making this challenge to complex you won't need to calculate Chinese new year.

Because they are only 12 animals in the Zodiac, your code will need to be as short as possible.

## Examples

Your program must get the system year, the first line is just for reference

2015
Goat

1924
Rat

1923
Pig

2008
Rat


## Specification

The order of the Zodiac is:

Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig


Rat starts at 2008, Pig is 2007, Ox at 2009, etc. at the end this loops back around.

Output must be correctly capitalized.

• Is anything before 2008 is assumed to be Rat? Jan 1, 2016 at 1:36
• @ZachGates no, that's just an example. I'll update Jan 1, 2016 at 1:36
• Can it use the year in the user's timezone? Jan 1, 2016 at 1:44
• Related. Jan 1, 2016 at 2:55
• I am confused by the system year requirement. So there is no input? So in 2015, it would have printed goat, and now, it should print Monkey? Jan 1, 2016 at 4:49

# Pyth - 65 bytes

@c." y=CÅQ¯@îR

@                     Modular indexing
c           )        Split string, use default of spaces
."ajs&^asd"         Packed string to compress space separated zodicas
.d3                  Current year

• Can you add an explanation? Jan 1, 2016 at 4:43
• @TanMath its really simple, but sure Jan 1, 2016 at 6:35
• You can save at least 3 bytes by narrowing down the character space. demo Also, you might want to post the unprintable code as a hexdump and include a printable version. Jan 1, 2016 at 16:22

# Pyth, 54 bytes

@rR3c."ayÖÚ©*ÐPk<eüµÜxþ!¬Ì ¾½hÑðÙBwp"\c.d3


Try it online: Demonstration

You can replace the last 3 chars .d3 with any year number to test the other Zodiac animals.

### Explanation:

     ."ayö..."        packed string, decrypts to "monkeycroostercdogcpig..."
c         \c      split this string at "c"s
rR3                  make the first letter of each animal uppercase
.d3   current year
@                     take the correct animal of the list and print


# JavaScript ES6, 106105104 103 bytes

Saved 1 byte thanks to Maltysen, 1 byte to insertusernamehere, and 1 byte to edc65!

x=>"RatOxTigerRabbitDragonSnakeHorseGoatMonkeyRoosterDogPig".match(/.[a-z]+/g)[new Date().getYear()%12]


Pretty self explanatory.

• I feel like that string could use some btoa and atob. (You can also change the byte encoding, if that's allowed). Jan 1, 2016 at 2:43
• @ןnɟuɐɯɹɐןoɯ btoas result looks to be 1.5x or more the length of the hardcoded string. Jan 1, 2016 at 2:44
• No, use atob to encode, and btoa to decode. Jan 1, 2016 at 2:48
• You can save 1 byte: Remove the 0 as separator and use this regex to split the string: /(?=[A-Z])/. Happy New Year. :) Jan 1, 2016 at 9:49
• match(/.[a-z]+/g) instead of split (added value: split with capture is not ES6, is a FireFox only feature)(and 1 byte shorter) Jan 2, 2016 at 15:51

# CJam, 8280 75 bytes

This is was a direct port of my Milky Way answer.

"Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat"S/et0==


Saved 7 bytes thanks to NinjaBearMonkey.

• You can use S as a variable for space. Jan 1, 2016 at 2:06
• Even shorter: "Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat"S/et0== Jan 1, 2016 at 2:13

## Japt, 72 65 bytes

Mkey RooÐP Dog Pig R Ox Tig Rabb Dg Snake HÆ  Go¸gÐ i %C


Try it online!

• Umm... this is pretty good, but there's definitely some unprintables in there. Could you give us a link? Jan 1, 2016 at 20:05
• @Eth eh, didn't account that unprintable are stripped. Gonna restore it :D Jan 1, 2016 at 20:06
• BTW, instead of $[$Ð i -4 %12], you can use g(Ð i -4 %C. Jan 1, 2016 at 20:07
• @Eth ok, and i'll dispose of -4 also, by changing the element order. Jan 1, 2016 at 20:07
• @Eth Wait, your fix doesn't appear to work, outputs NaN... Jan 1, 2016 at 20:09

# MATL, 85 bytes

'Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey'YbZ'10H$XOU12X\)  Uses release 6.0.0 of the language/compiler. Works in Octave. ### Example >> matl > 'Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey'YbZ'10H$XOU12X\)
>
Monkey


### Explanation

Note that the initial string is cyclically displaced by 3 to avoid a subtraction.

'Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey'
Yb                    % split at spaces
Z'                    % number representing current date and time
10H$XO % get year as a string U % convert to number 12X\ % modulo 12, with 0 converted to 12 ) % index (and implicitly print)  # Milky Way 1.6.1, 101 96 bytes M" "\=A12n"Goat Horse Snake Dragon Rabbit Tiger Ox Rat Pig Dog Rooster Monkey"" "\;>=<&{~1-;^};!  Saved 5 bytes thanks to a reminder by Luis Mendo. ### Explanation The code modulos the system year by 12 and outputs the proper animal. ### Usage ./mw <path-to-code>  • Maybe you can avoid 2008- by rearranging the string as in my answer? Jan 1, 2016 at 3:11 • Oh, I think you already do that in your CJam answer Jan 1, 2016 at 3:27 • You're right! I can use the string from my CJam answer in reverse. Thanks for reminding me @LuisMendo Jan 1, 2016 at 3:33 # CJam, 69 bytes "SKiN<lEz=2)aFBY8H[$h-0|4=KT2Cp%-a)o6"132b26b'f+'/et0==(eu\


Contains a bunch of unprintables. Try it here.

• You can't take a year as input, it has to use the current system time. Jan 1, 2016 at 6:39
• Ah, fixed. @Maltysen
– lynn
Jan 1, 2016 at 13:09

# Python 3, 126116 112 bytes

Edit: I'm keeping the other answer because it's cool, but this is shorter.

from time import*
"Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Goat".split()[localtime().tm_year%12]


If trailing whitespace is ok, then it's 126 bytes. If not, it's 134 bytes after adding .strip() to the end of the code.

from datetime import*
"MRDPROTRDSHGoooiaxiarnoonoggt gbaaraks    ebgkstet    rioee ye     tn    r"[datetime.now().year%12::12]


# R, 119 bytes

scan(t="Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat",w="")[(format(Sys.Date(),"%Y"):1)[1]%%12+1]


format(Sys.Date(),"%Y") returns the year as a character string, (format(Sys.Date(),"%Y"):1)[1] is the shortest way i could think of to coerce it into an integer so that we can apply %% to it (the sequence generator : indeed coerces automatically to integer). +1 because R indices are 1-based and not 0-based.

# PHP >= 5.6, 84 bytes

Very straight forward:

<?=[Monkey,Rooster,Dog,Pig,Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat][date(Y)%12];


# Python 129 126 bytes

EDIT: I just learnt s.split(' ')=s.split()

Although this isn't the shortest method, here is an alternative answer to @Sherlock9's one:

from datetime import*
print 'Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat'.split()[date.today().year%12]


Try it here

• Wow. I just edited my answer and that was pretty close to what I edited it to. I'm going to try something with time next. Jan 2, 2016 at 5:42

## PowerShell, 92 bytes

(-split"Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat")[(date).Year%12]


Similar in spirit to other answers, added here only for sake of cataloging. This takes the string "Monkey ... Goat" and -splits it on spaces to create an array, which is cheaper than specifying the elements individually with ("Monkey","Rooster",...). We index into that array with the current year mod 12, which outputs the result. Nothing too fancy.

## C# 159

using System;class P{static void Main(){Console.Write("Monkey;Rooster;Dog;Pig;Rat;Ox;Tiger;Rabbit;Dragon;Snake;Horse;Goat".Split(';')[DateTime.Now.Year%12]);}}


using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Monkey;Rooster;Dog;Pig;Rat;Ox;Tiger;Rabbit;Dragon;Snake;Horse;Goat".Split(';')[DateTime.Now.Year % 12]);
}
}


# J, 78 bytes

(>;:'Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat'){~12|


Usage:

    (>;:'Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat'){~12| 2015
Goat


Explanation:

;:      separates the string into boxed array according to the spaces
>       opens the boxed array so that it becomes a normal array
x {~ y  is choose the y-th element from x.
the ~ reverses the argument, so x { y is choose the x-th element from y.
12|     is the residue when the year is divided by 12


# Vyxal, 49 bytes

⌊ẇ ₃¼ Roos≠∴ •∞ Ḣ⟩ ₀⌊ Ox ṗȦ ₈Ė ėɾ Ċṅ ½√⌈kD⌊12%i


Try it Online!

...         # Compressed  string of names
⌈        # Split on spaces
kD⌊     # Current year
12%  # Modulo 12
i # Index into list of names