The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

1

C# (Visual C# Interactive Compiler) Without leading 0s, 104, 103 bytes (s,e,n)=>new int[(e-s).Days+1].Select((x,i)=>s.AddDays(i)).Where(x=>$"{x:yyyMd}".Distinct().Count()>=n) Try it online! With leading 0s, 106 105 bytes (s,e,n)=>new int[(e-s).Days+1].Select((x,i)=>s.AddDays(i)).Where(x=>$"{x:yyyMMdd}".Distinct().Count()>=n) Try ...


0

Kotlin, 119 bytes fun f(a:LocalDate,b:LocalDate,c:Long)=a.datesUntil(b.plusDays(1)).filter{it.toString().chars().distinct().count()==c+1} Without leading 0s, takes in two java.time.LocalDate and a Long, returns a Stream of LocalDates


1

Ruby -rdate, 54 bytes Takes 2 Date objects and a number as input, and returns a list of Date objects as output. Handles leap years and uses leading zeroes. ->a,b,n{(a..b).select{|d|d.to_s.chars.uniq.size==n+1}} Try it online!


1

Java (JDK), 86 bytes (s,e,n)->s.datesUntil(e.plusDays(1)).filter(d->(""+d).chars().distinct().count()==n+1) Try it online! I chose to use leading 0s. Credits -24 thanks to Kevin Cruijssen who didn't know he could golf away that much :p


1

PHP, 90 bytes for([,$s,$e,$n]=$argv;$s<=$e;)$n-count(count_chars($d=date(Ymd,86400*$s++),1))||print$d._; Try it online! This is with leading 0s. Inputs are command arguments ($argv) and dates are Unix timestamps in days (basically standard seconds / 86400), I used this format as we don't need the time in this challenge and it allowed me to golf 1 more ...


5

R, 81 bytes function(s,e,n,x=seq(s,e,1))x[lengths(sapply(strsplit(paste(x),""),unique))==n+1] Try it online! Uses R’s native date format and has leading zeros on day and month.


2

Python 3.8 (pre-release), 84 bytes -6 bytes thanks to Gloweye lambda s,e,n:[d for i in range((e-s).days+1)if-len(set(d:=str(s+type(e-s)(i))))==~n] An unnamed function which returns a list of strings (counting/including leading zeros) that accepts three arguments: s, the start - a datetime.date object; e, the end - a datetime.date object; and n, the ...


1

JavaScript (ES6), 91 bytes Takes input as (n)(end)(start), where the dates are expected as Unix timestamps in milliseconds. Returns a space-separated list of dates in format yyyy-mm-dd. Leading 0s are included. n=>b=>g=a=>a>b?'':(new Set(d=new Date(a).toJSON().split`T`[0]).size+~n?'':d+' ')+g(a+864e5) Try it online!


2

Japt, 23 bytes Takes the date inputs as Unix timestamps, outputs an array of strings with formatting and leading 0s dependent on your locale. Would be 1 byte shorter in Japt v2 but there seems to be a bug when converting Date objects to strings. òV864e5@ÐX s7Ãf_¬â ʶWÄ Try it òV864e5@ÐX s7Ãf_¬â ʶWÄ :Implicit input of integers U=s,V=e & W=n òV ...


3

Red, 93 bytes func[a b n][until[if n = length? exclude d: rejoin[a/4"-"a/3"-"a/2]"-"[print d]b < a: a + 1]] Try it online! Without leading 0s for days/months. Too bad that Red converts internally 09-10-2019 to 9-Oct-2019 - that's why I need to extract the day/month/year individually.


Top 50 recent answers are included