26
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.
Challenge
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.
Examples
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.
1@TimmyD. Rule 7 is a may rule, so you don't have to follow it if you don't want to. I suspect date-time functions will be useful for parsing of input dates and formatting of output dates. YMMV. – Digital Trauma – 2015-11-12T19:47:42.120
5Rule 7 is a May rule. It can be safely ignored this month (and for the next half year). – Martin Ender – 2015-11-13T15:25:20.390
Realistically, I think a family would check at each birthday, counting years as integers and not trying to sum up the days (with 0.25 to complicate matter). – edc65 – 2015-11-14T15:16:52.430
@edc65 Who ever let reality get in the way of a good PPCG challenge? ;-) – Digital Trauma – 2015-11-14T20:57:58.727