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

New answers tagged

1

Perl 6, 102 bytes {[~] <ΡΣΤΥΦΧΨΩϠ ΙΚΛΜΝΞΟΠϘ ΑΒΓΔΕϜΖΗΘ>>>.&{('',|$^b.comb)[$_/100*10**$++%*]}} Try it online!


0

ink, 55 33 55 bytes =l(n) ~temp i=2 {n-1:C}EC<> -(k){i<n: ~i++ C<>->k }->-> Try it online! Starts by printing C if input is not 1, then EC, then prints C another n-2 times.


0

Zsh, 54 bytes eval {autoload,}' is-at-least $'{1\ $2,2\ $1}';<<<$?;' Try it online! Try a test suite! This evals to the following eight statements: autoload is-at-least $1 $2 # loads the "is-at-least" function <<<$? # success, prints 0 autoload is-at-least $2 $1 # redundant <<<$? ...


0

Gol><>, 7 bytes I:P*2,h Courtesy of JoKing Try it online! 8 bytes I::*+2,h Try it online!


1

ink, 53 bytes =e(n) ~temp o=0 -(i)~o+=n%2 ~n=n/2 {n:->i}{1-o%2}->-> Try it online! Counts bits.


1

Forth (gforth), 41 bytes : f 1 swap 63 for 0 d2* m+ next + 2 mod ; Try it online! A function with signature ( u -- 0-or-1 ), that is, one that takes a cell-sized integer from the stack and gives a 0 (not evil) or 1 (evil) on the stack. gforth's native boolean is -1 (true) and 0 (false), but any nonzero value is recognized as true, just like many other ...


0

Runic Enchantments, 8 bytes i:1+*2,@ Try it online! Nothing exciting here, reads input multiplies it with itself+1, divides by 2, and outputs. Kind of feel that I should have anticipated this sort of 1-input-1-output mathematical operation and made a MathFunc (A) operation for it ("its factorial, but addition!"), but I didn't.


0

MyLang, 7 bytes MyLang is backwards-compatible with Deadfish~ and is designed to make Deadfish~ relatively easier to program in. Unlike the existing Deadfish derivatives which extend the memory in addition to the arithmetic operators, this derivative only adds one numeric accumulator to the existing Deadfish accumulator. (Here we call the first accumulator ...


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

C# (Visual C# Interactive Compiler), 277 bytes (w,h,d)=>{var z=new int[w+h<<1].Select((_,i)=>i<w?(i,-1,3):i<w+h?(w,i-w,0):(i-=w+w)<h?(h+~i,h,1):(-1,h+h+~i,2)).ToList();z.ForEach(x=>{var(a,b,c)=x;do{try{c^=d[(a,b)]<48?1:3;}catch{}a+=~-c%2;b+=(c-2)%2;}while(a>=0&a<w&b>=0&b<h);Print(z.FindIndex(l=>l.Item1==...


0

Forth (gforth), 31 bytes : f dup s>f fsqrt f>s dup * = ; Try it online! The input is a positive signed single-cell integer (0 <= n < 2^63 for 64-bit systems). To support full unsigned integer range, do 0 d>f instead of s>f. Using floats turns out to be shorter than a loop. How it works : f ( n -- f ) \ Takes a positive signed int and ...


1

Python 2, 317 300 298 290 bytes def f(w,h,B): A=[w*[-1]for c in' '*h];p=w+h for x,y,c in B:A[y][x]=c<'0' for i in range(2*p): x,y,d=[[[(0,2*p+~i,0),(w+p+~i,h-1,1)][i<w+p],(w-1,i-w,3)][i<p],(i,0,2)][i<w] while w>x>=0<=y<h:d^=1+A[y][x];x+=[1,0,0,-1][d];y+=[0,-1,1,0][d] print[[y+w,2*p+~y][x<0],[w+p+~x,x][y<h]][0<...


2

Python 3, 84 bytes lambda*M:len({x/y for x,y in zip(*[sorted(abs(3*x-sum(l))for x in l)for l in M])})<2 Try it online! Takes input as 3 complex numbers. Outputs True for similar, False for dissimilar. The first test case fails due to a float precision issue with two extremely close float values being unequal; the challenge allows this. This uses a bit ...


1

Keg, 3 bytes (SBCS) Ï⅀. Keg, 5 bytes (SBCS) Ï∑+). Explanation: Ï# Range from input to 0. The 0 will not affect the summation. ∑+# Apply all stack: add. )# We have to complete the braces if we want to output as an integer. .#Output as an integer TIO


6

JavaScript (ES6),  218 215 213  212 bytes Takes input as (w,h,o) where \$o\$ is an object whose keys are the coordinates of the bumpers in 'x,y' format and whose values are either '/' or '\'. (w,h,o)=>(A=[...Array(w+h<<1)].map((_,n)=>(p=n-w)<0?[n,-1,3]:p<h?[w,p]:(p-=w)<h?[h+~p,h,1]:[-1,2*h+~p,2])).map(g=([x,y,d])=>A.every((...


1

Forth (gforth), 80 bytes Refactored reffu's solution. : d { n } 0 n 1 do n i mod 0= i * - loop ; : f 2dup <> -rot 2dup d swap d d= * ; Try it online! How it works : d { n -- divsum } \ Takes a number and gives its divisor sum (excluding self) \ Store n as a local variable 0 n 1 do \ Push 0 (sum) and loop through 1 to ...


2

Brachylog, 2 bytes &ṅ Brachylog implicitly inputs from the left and outputs from the right. & ignores anything to the left and passes the input to the function rightwards. ṅ constrains each side of it to be negated versions of each other. Try it online


1

Charcoal, 46 bytes ≔EAEιΣXEλ⁻ν§§ι⊕μξ²θUMθ×⟦⌊ι⌈ιΣι⟧Σ§θ¬κ⬤⊟θ⁼駧θ⁰κ Try it online! Link is to verbose version of code. Outputs - for similar, nothing for dissimilar. Accepts triangles in any N-dimensional space. Explanation: ≔EAEιΣXEλ⁻ν§§ι⊕μξ²θ Input the two triangles and calculate the squared lengths of their sides. UMθ×⟦⌊ι⌈ιΣι⟧Σ§θ¬κ Calculate the ...


1

Wolfram Language (Mathematica), 38 bytes Equal@@Sort/@PolygonAngle/@Polygon/@#& Try it online! Takes a list containing two lists of coordinates. Checks if the two triangles' angles are equal. As PolygonAngle was introduced in version 12.0, this code does not (yet) work on TIO.


1

Ruby, 87 82 77 bytes ->*a{a.map!{|a,b,c|(w=[a-b,b-c,a-c].map &:abs).map{|x|x/w.sum}.sort}.uniq!=a} Try it online! Given the 2 triangles as vectors of 3 complex numbers, calculate length of the three sides as distance between points, then normalize and check if the result is the same.


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!


5

Jelly, 9 bytes ṁ4IAṢ)÷/E A monadic Link accepting a list of two triangles - lists of complex numbers (coordinates on the Cartesian plane). Similar triangles yield 1, dissimilar ones yield 0. Try it online! (includes footer to translate from coordinate pairs for ease of use) Or see the test-suite. How? ṁ4IAṢ)÷/E - Link: list [[a, b, c], [d, e, f]] ...


1

Julia 1.0, 65 bytes !x=sort(abs.(diff(push!(x,x[1])))) g(a,b,z=!a./!b)=all(z.≈z[1]) Revised to not abuse the "any input structure" statement, as people seemed down on that. Found extra golfing, so it's only 1 byte longer. The input is two vectors of complex numbers. ! is a helper function that appends the first element to the end of each input list and ...


0

Zsh, 156 122 116 bytes s(){m= for a b x y;m+=($[(a-x)**2+(b-y)**2]) n+=(${(n)m})} s $=1 s $=2 ((r=(n[1]+0.)/n[4],r*n[5]-n[2]||r*n[6]-n[3])) Try it online! Try it online! Try it online! Saves 34 bytes by abusing "any structure" for input. Given a pair of triangles: [[1,2],[3,4],[5,6]] and [[7,8],[9,10],[11,12]] The input should be the two strings: '1 2 ...


2

APL+WIN, 40 bytes Prompts for the co-ordinates of each triangle as a 4 x 2 matrix with first row repeated as last row. Confirmed with OP that this is compliant with the input rules 0=+/2-/(y[⍋y←⍎c])÷x[⍋x←⍎c←'+/(-2-⌿⎕)*2'] Try it online! Courtesy of Dyalog Classic


2

Brachylog, 23 21 bytes {{{⊇Ċ-^₂}ᶠ}ᵐz+ᵐo}ᵐz/ᵛ -2 bytes thanks to Unrelated String A predicate that only accepts similar triangles. Note that for negative values you have to type _1 instead of -1 Try it online!


2

J, 39 34 32 bytes 1=[:#@~.%&([:/:~#:@3 5 6|@-/@#]) Try it online! Takes input as 3 complex numbers for each triangle. For each triangle, we get each possible pair of points using a boolean mask filter. Ie, #:@3 5 6 translates 3, 5, and 6 to their binary representations, and each row selects one possible pair: 0 1 1 1 0 1 1 1 0 We then get the ...


4

05AB1E, 11 bytes Port of Luis Mendo's MATL answer. Outputs 1 for similar, 0 otherwise. vyĆüαnO{}/Ë Try it online!


11

MATL, 15 12 bytes ,i4:)d|S]/da The program inputs two 3×1 vectors of complex numbers representing the coordinates; and outputs 0 for similar, 1 for not similar. Try it online! Or verify all test cases. Explanation The code checks if the side lengths, sorted for each triangle, are proportional between the two triangles. , % Do twice i % ...


3

Python 3, 85 bytes lambda a:len({i/j for i,j in zip(*[sorted(map(abs,[p-q,q-r,r-p]))for p,q,r in a])})<2 Try it online! -17 bytes thanks to FlipTack -7 bytes thanks to tsh Takes a list of lists of coordinates represented by complex numbers as input. Calculates the distances between all points in each set and sorts by magnitude. Then, it checks for ...


3

JavaScript (ES7),  122 120 117  112 bytes Takes input as (a)(b), where both parameters are in the format used in the challenge. Returns false for similar or true for dissimilar. a=>b=>(g=a=>a.map((c,i)=>(h=j=>(c[j]-a[-~i%3][j])**2)(0)+h(1)).sort((a,b)=>a-b))(a).some((x,i)=>a-(a=x/g(b)[i])) Try it online! Commented a => ...


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

T-SQL, 116 bytes WITH t AS(SELECT 2n UNION ALL SELECT n+1FROM t WHERE n<5e4) SELECT*FROM z,t WHERE p%n=0AND n<p OPTION(MAXRECURSION 0) There is an Oracle SQL answer here, but couldn't find a Microsoft T-SQL version for this classic question. Notes: Line break is for readability only. Returns no rows if prime, returns 1 or more rows otherwise. ...


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.


0

Shakespeare Programming Language, 300 bytes (whitespace added for readability) h.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck] Ajax:You cat. Puck:Listen tothy.Remember you! Scene V:. Puck:You is the sum ofyou a pig. Ajax:You is the product ofyou I.Be a cat worse I?If so,let usScene V. Puck:Recall! Ajax:You is the remainder of the quotient betweenthe ...


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.


1

Python 3, 44 bytes i=0;print(i) while 1:i+=1;print(i);print(-i) Try it online!


0

Python 3, 161 bytes i,t,u,v,a,c,f=int(input()),1000,676,26,ord('A'),chr,lambda x:c(a+x//v)+c(a+x%v) m,n=i%t,i//t e,o=n%u,n//u print('-'.join([f(o),(3-len(str(m)))*'0'+str(m),f(e)])) Try it online!


0

Python 3, 73 bytes def f(l):s=[n-i for i,n in enumerate(l)];return max(s.count(i)for i in s) Try it online! This works by subtracting the index from each number in the list and finding the greatest frequency in the list.


1

Julia 1.0, 86 bytes i->(join('A'.+digits(i÷1000,base=26,pad=4))string(i%1000,pad=3)*'-')[[4;3;8;5:8;2;1]] Try it online!


0

brainfuck, 29 bytes ,<,[>[>+>+<<-]>[<+>-]<<-]>>>. Try it online! Input and output as character codes. (Example: 5*7=35) Code: [Tape: Y, X, temp, solution] ,<, input X and Y [ while Y greater than 0 >[>+>+<<-] add X to temp and solution >[<+>-] ...


1

International Phonetic Esoteric Language, 4 bytes (WIP language) ɪɪθo No TIO interpreter yet, but is runnable by cloning the repository above, and calling python3 main.py "code here". ɪɪθo ɪ ; push int ɪ ; push int θ ; pop, pop, push a * b o ; pop, print


0

Japt -h, 9 bytes í- ò¦ mÊn Try it


1

05AB1E, 7 6 bytes ∞-γ€gZ Try it online! Thanks to @Kevin Cruijssen for -1 byte Code: ∞ push endless list [1, 2, 3, 4, 5, ...] - subtract that from input γ group by equal elements €g push lengths of each group Z push max length implicitly print top of stack


0

Kotlin, 93 bytes {i:Int->val c={v:Int->'A'+i/v/1000%26} ""+c(17576)+c(676)+"-%03d-".format(i%1000)+c(26)+c(1)} Try it online!


Top 50 recent answers are included