This is similar to simplifying fractions, but with Dates!
The input of your program must be of the form mm/dd
For example
3/4 //March 4
12/15 //December 15
1/1 // January 1
We assume that the input will be valid such that the months have these numbers of days in them:
January 31
February 28
March 31
April 30
May 31
June 30
July 31
August 31
September 30
October 31
November 30
December 31
Your program's job is to take the assumed valid input, and iteratively (or recursively) simplify the date, and at each iteration (including the 0th), output the date with the full name of the month as written above.
For example:
Given an input of:
12/18
Would output
December 18
June 9
February 3
An input that is already simplified only outputs itself:
11/17
Outputs:
November 17
The month names cannot come from a function in your language. The strings can be obfuscated, computed, however you like, but you cannot use a standard function like GetMonthString(4) or something, you either have to write that function, or find a way to output the month names as described.
I cannot think of any cases where the simplified date produces an illegal date, but if ever you produce an illegal date along the way, output:
Illegal Date
But if you are sure this cannot happen, you do not need to have code covering this case. The dates outputted just always need to be valid according to what was described above (it goes without saying that months and days start at 1).
The algorithm:
At each iteration you divide by the smallest number that divides numerator and denominator.
That is, you find all the numbers such that, dividing both the numerator and denominator by this number produces a new numerator and denominator that are both integers (common factors). Select the smallest one and individually divide the numerator and denominator to produce a new fraction. If the only number you can divide by is 1, then you have simplified as much as possible and you stop.
I hope this is clear.
Any language is allowed. This is Code Golf, shortest code wins!
12/18
to6/9
and not4/6
(I don't get all the iteration mess ... when I simplify a fraction I got immedialtely the resulting simplified value)? \$\endgroup\$