I was recently adding up the ages of myself and my wife and kids and realised that at some point in the not-too-distant future our ages will all add up to exactly 100 years.
For an input consisting of a combined (total) age and a list of birth dates, output the date on which the combined ages all add up to the given total.
- Input combined age (in years) will be a positive integer
- Input list of birth dates will be a list (whatever format is convenient for your language) of dates that must contain numerical representation of Day, Month and Year. Number of days since a specific epoch is not acceptable. You may assume the list of input dates is sorted in chronological order.
- Output will be a single date in the same format as input dates
- For the purposes of the combined age, 1 year is considered to be exactly 365.25 days
- For some inputs, it will be impossible to find a date after all the birth dates when they all add up to the combined age. For instance consider two birth dates that are 20 years apart, but we want a combined of 10 years. In that case, the output would be the 10th birthday of the older birth date. In other words, individual ages are considered to be 0 for all dates before that individual's birth date
- The output will be the first date on which the combined ages add up to at least the input age
- You may use built-in date-time functions
- You must support dates going back as far as 1970/01/01.
Here I'm giving all dates in YYYY/MM/DD format, but you may whatever format you like.
Input Output 10 2000/01/01 2010/01/01 100 1975/03/05,1978/07/23,2008/11/12,2012/12/20 2018/11/22 100 1975/03/06,1978/07/23,2008/11/12,2012/12/20 2018/11/23 100 1975/03/09,1978/07/23,2008/11/12,2012/12/20 2018/11/23 100 1975/03/10,1978/07/23,2008/11/12,2012/12/20 2018/11/24 3 1990/08/01,1995/07/02 1993/08/01 50 1975/03/05,1978/07/23,2008/11/12,2012/12/20 2001/11/13
Note that in the last two examples, the output date lies within the range of input dates, as per rule 5.