| Bytes | Lang | Time | Link |
|---|---|---|---|
| 181 | Pascal | 240728T160000Z | Kai Burg |
| 049 | Vyxal | 210910T112419Z | emanresu |
| 078 | J | 160330T080740Z | Leaky Nu |
| 112 | Python 3 | 160101T142146Z | Sherlock |
| 159 | C# | 160105T200951Z | Yytsi |
| 092 | PowerShell | 160105T194032Z | AdmBorkB |
| 126 | Python | 160101T171813Z | TanMath |
| 103 | JavaScript ES6 | 160101T022016Z | Conor O& |
| 065 | Japt | 160101T184900Z | nicael |
| 069 | CJam | 160101T041809Z | lynn |
| 084 | PHP >= 5.6 | 160101T160850Z | insertus |
| 119 | R | 160101T151956Z | plannapu |
| 054 | Pyth | 160101T081500Z | Jakube |
| 065 | Pyth | 160101T015924Z | Maltysen |
| 096 | Milky Way 1.6.1 | 160101T015750Z | Zach Gat |
| 085 | MATL | 160101T030209Z | Luis Men |
| 075 | CJam | 160101T020211Z | Zach Gat |
Pascal, 181 B
This complete program require a processor supporting features of Extended Pascal as defined by ISO standard 10206, in particular the time‑related routines and data type.
program z(output);var t:timeStamp;begin
getTimeStamp(t);write(subStr('Monkey RoosterDog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat ',t.year mod 12*7+1,7))end.
Long:
program chineseZodiacOfTheYear(output);
const
animal = 'Monkey RoosterDog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat ';
var
now: timeStamp;
begin
getTimeStamp(now);
writeLn(output, trim(subStr(animal, now.year mod 12 * 7 + 1, 7)))
end.
See also: RosettaCode task
Vyxal, 49 bytes
`⌊ẇ ₃¼ Roos≠∴ •∞ Ḣ⟩ ₀⌊ Ox ṗȦ ₈Ė ėɾ Ċṅ ½√`⌈kD⌊12%i
`...` # Compressed string of names
⌈ # Split on spaces
kD⌊ # Current year
12% # Modulo 12
i # Index into list of names
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
Python 3, 126 116 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]
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]);}}
Readable / ungolfed version
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]);
}
}
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.
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]
JavaScript ES6, 106 105 104 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.
CJam, 69 bytes
"SKiN<lEz=2)aFBY8H[$h-0|4=K`T2Cp%-a)o6"132b26b'`f+'`/et0==(eu\
Contains a bunch of unprintables. Try it here.
PHP >= 5.6, 84 bytes
Very straight forward:
<?=[Monkey,Rooster,Dog,Pig,Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat][date(Y)%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.
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
Pyth - 65 bytes
@c." y=CÅQ¯@îR
°©ÀáëªfÞ#[õNqÀN8Ô'¼ô,n7˶~fB").d3
@ Modular indexing
c ) Split string, use default of spaces
."ajs&^asd" Packed string to compress space separated zodicas
.d3 Current year
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>
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)
CJam, 82 80 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.