6
1
Donald Knuth was born in 1938, on the 20th day of Capricorn.
The first day of Capricorn is the 22nd December.
Donald Knuth was born on the 10th of January (1938).
The challenge
Write a program or function which takes three inputs about a person (any other specified order is fine):
- Their (calendar) year of birth (an integer)
- Their sign of the zodiac (a string)
- may be whichever you choose from the following, so long as it is consistent:- all lower case except the first character;
- all lower case; or
- all upper case.
- The (1-based) day of the zodiac period on which they were born (an integer)
...and provides two outputs (the other order is fine if specified):
- The day of the month on which they were born (an integer)
- Their month of birth (an integer)
More details
If your answer were a function, F
, then for Donald Knuth we would run F(1938, 'Capricorn', 20)
and receive the output (10, 1)
For the purposes of this challenge you do not need to shift the zodiac due to the shift between the Gregorian calendar and the tropical year, but you do need to account correctly for leap years.
February has 29
days rather than 28
on leap years.
A year is usually a leap year if it is divisible by 4
- the exceptions are when it is divisible by 100
but not 400
(so, 1600
and 2000
were, whereas 1700
, 1800
, and 1900
were not).
For reference the names of the signs of the zodiac and their inclusive ranges are:
Aries 21 March – 20 April
Taurus 21 April – 21 May
Gemini 22 May – 21 June
Cancer 22 June – 22 July
Leo 23 July – 22 August
Virgo 23 August – 23 September
Libra 24 September – 23 October
Scorpio 24 October – 22 November
Sagittarius 23 November – 21 December
Capricorn 22 December – 20 January
Aquarius 21 January – 19 February
Pisces 20 February – 20 March
This is code-golf, so the shortest code in bytes is the aim.
No loopholes, yada yada; you know the drill.
Test cases
Charles Babbage F(1791, 'Capricorn', 5) --> (26, 12)
George Boole F(1815, 'Scorpio', 10) --> ( 2, 11)
Herman Hollerith F(1860, 'Pisces', 10) --> (29, 2)
Vannevar Bush F(1890, 'Pisces', 20) --> (11, 3)
Howard H. Aiken F(1900, 'Pisces', 17) --> ( 8, 3) - note 1900 was not a leap year
Donald Knuth F(1938, 'Capricorn', 20) --> (10, 1)
<Future Famed> F(2000, 'Pisces', 17) --> ( 7, 3) - note 2000 was a leap year
Would it be OK to output the birth date as a string (such as "1791-12-26") rather than the birthday? Or the birthday as a string (such as "12-26")? – Arnauld – 2016-09-05T21:52:43.393
@Arnauld The output is strictly specified as two integers, so if you utilise any date utilities you'll have to pull them out. (I just saw the deleted comment, so just to clarify: the input is the calendar year of birth) – Jonathan Allan – 2016-09-05T21:56:47.650