This week, another programming challenge, but this time considerably tougher than the previous.
His Imperial Majesty, Xórgü of House Nand, decrees that the martian imperial court is in need of a new calendar. The current martian calendar counts 668 days, but it accumulates errors. The martian year, according to His Imperial Majesty’s most illustrious astronomers, is in fact 668.60 (martian) days long.
Martians really like prime numbers, so the emperor decrees that the new calendar must be such that:
- It has a prime number of months, more than 10, less than 18,
- Every month as a prime number of days,
- Months must have about the same number of days,
- Months must be at least 3 weeks long, that is, at least three martian weeks of 13 days (they have 13 fingers, you see), but at most five,
- Months, in calendar order, must have non-decreasing number of days
The calendar is to start at year 1, corresponding to the birth year of Emperor Xórgü.
Your task is therefore:
- To find a simple rule for leap years (those with leap days; also known as intercalar or epagomenal days),
- To determine how to organize the year in months, with the rules decreed by the emperor,
- To write a routine that converts a martian date (day, month, year) to an integer (days since Xórgü) and one that takes an integer and produces a martian date,
You can neglect year 0 and negative dates. Dates before year 1 are decreed to not exist.
You must also show that your code works correctly for all dates (say the first million (martian) years).