# For a given period, getting the smallest list of dates, using jokers

Consider a date formatted in YYYY-MM-DD. You can use the joker * at the end of the date string. E.g. 2016-07-2* describes all the dates from 2016-07-20 to 2016-07-29.

Now, consider a period represented by a start date and an end date.

The algorithm must find the smallest possible list of dates representing the period.

Let's use an exemple. For the following period:

• start date: 2014-11-29
• end date: 2016-10-13

The algorithm must return an array containing the following list of dates:

• 2014-11-29
• 2014-11-30
• 2014-12-*
• 2015-*
• 2016-0*
• 2016-10-0*
• 2016-10-10
• 2016-10-11
• 2016-10-12
• 2016-10-13
• The winning objective(s) are ambiguous. I suggest changing it to codegolf (i.e. solve the task in the fewest bytes possible) and always require answers to output the smallest list of dates. Commented Nov 9, 2016 at 10:22
• Maybe it's simply not the best site for this, it is more a question (i.e. "I can't find this algorithm in Ruby on Rails") than a challenge "for fun". I'm rather new here... Commented Nov 9, 2016 at 10:28
• I suggest you try stackoverflow and then ask it as a question rather than a challenge. If rephrased, the challenge is still interesting in my opinion and deserves a chance (as code golf). Commented Nov 9, 2016 at 10:36
• Yeah, I think finding the algorithm is still fun and challenging, but I was not interested in the code-golf side... Well I rephrased it, changed the tags, and now I'm gonna ask stackoverflow while still following this post. Thanks! Commented Nov 9, 2016 at 10:39
• Follow-up: I posted on Stackoverflow yesterday, but today I had a working code in Ruby (it doesn't "jokerize" months, but almost there): stackoverflow.com/questions/40506639/… Commented Nov 10, 2016 at 17:19

for($a=($f=strtotime)($argv[1]);!$p=$a>$z=$f($argv[2]);$a+=86400){$x=$z<$e=$f(Dec31,$a);(101<$q=date(md,$a))?$q-1001|$x?:$a=$e+$p="1*":($x?($t=$f(IX30,$a))>$z?:$a=$t+$p="0*":$a=$e+$p="*");$p?:($q%100>1|$z<($t=$f(date(Ymt,$a)))?$q%10>0&$q%100>1|$z<($t=min($t,$a+777600))?:$a=$t+$p="m-$q[2]*":$a=$t+$p="m-*");echo date("Y-".($p?:"m-d"),$a)," ";}  takes input from command line arguments. Run with -nror test it online. notes • prints Y-m-3* for Y-m-30; add 7 bytes to fix: Insert |$a==$t after 777600)). • throws warnings in PHP 7.1; add 5 bytes to fix: Replace +$p with +!\$p.