7 kyu

Chinese Zodiac

646 of 2,218AcesOfGlory

Description:

The Chinese zodiac is a repeating cycle of 12 years, with each year being represented by an animal and its reputed attributes. The lunar calendar is divided into cycles of 60 years each, and each year has a combination of an animal and an element. There are 12 animals and 5 elements; the animals change each year, and the elements change every 2 years. The current cycle was initiated in the year of 1984 which was the year of the Wood Rat.

Since the current calendar is Gregorian, I will only be using years from the epoch 1924. For simplicity I am counting the year as a whole year and not from January/February to the end of the year.

Task

Given a year, return the element and animal that year represents ("Element Animal"). For example I'm born in 1998 so I'm an "Earth Tiger".

animals (or $animals in Ruby) is a preloaded array containing the animals in order:

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

elements (or $elements in Ruby) is a preloaded array containing the elements in order:

["Wood", "Fire", "Earth", "Metal", "Water"]

Tell me your zodiac sign and element in the comments. Happy coding :)

Fundamentals
Arrays

Stats:

CreatedAug 7, 2016
PublishedAug 7, 2016
Warriors Trained4192
Total Skips131
Total Code Submissions7882
Total Times Completed2218
Python Completions646
JavaScript Completions1092
Ruby Completions59
CoffeeScript Completions11
C# Completions193
Java Completions294
Haskell Completions14
Total Stars75
% of votes with a positive feedback rating90% of 322
Total "Very Satisfied" Votes263
Total "Somewhat Satisfied" Votes53
Total "Not Satisfied" Votes6
Ad
Contributors
  • AcesOfGlory Avatar
  • user5036852 Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • tobeannouncd Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad