Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Hot answers tagged

11

J, 1 byte Courtesy of ngn { Try it online! 'tis called Catalogue…


10

Rust, 1210 1200 bytes use std::collections::HashMap as H;type I=i64;type E=Vec<(I,I)>;fn d(g:&E)->bool{let mut s:Vec<(E,Vec<I>)>=vec![];for e in g{let(v,w)=e;let f=(*v,*w);let z=|x|s.iter().position(|p|p.1.contains(x));match(z(v),z(w)){(Some(i),Some(j))=>{if i!=j{let mut p=s.remove(i);let q=s.remove(j-(i<j)as usize);p.0.extend(...


8

Julia 1.0, 62 bytes f(n,p,q=1:n-1)=[(x,y,z) for x=q,y=q,z=q if (x^p+y^p)%n==z^p%n] Try it online!


8

Wolfram Language (Mathematica), 37 36 bytes Tr[Csc[i=Pi/#2]^2Sin[2i#]-Cot@i#]/4& Try it online! Takes input in the order l, n. Uses the same approach as in the reference and many other implementations. Mathematica's trigonometric and arithmetic functions will automatically vectorize, and Tr returns the sum of the elements of a one-dimensional list. ...


8

Ruby, 79 .. 66 65 bytes ->n,f{(f*2+[w=-1]*n).sum{|z|(w**z*=b=2r/n).imag/(1-w**b).real}/4} Try it online! Loosely based on the reference implementation: The area of the original polygon (ABCDEFGH) is a If we cut instead of folding, we get a new convex polygon (ABEFH), we call the area of this polygon b The difference between a and b is the area of the ...


8

Haskell, 7 bytes mapM id Try it online! Built-in, 8 bytes sequence Try it online! Less boring, 33 bytes Out-golfed by xnor's answer. Go upvote that instead! f[]=[[]] f(h:t)=[i:j|i<-h,j<-f t] Try it online!


7

05AB1E, 15 10 bytes -2 bytes by Kevin Cruijssen -3 bytes by Grimmy <L3ãʒImÆ¹Ö Try it online! Returns a triples in the format [z,y,x]. Explanation: <L | Push the interval [1,n) 3ã | Push the triple cartesian product [1,n) x [1,n) x [1,n) | E.g. with n = 3, the list begins as follows: ...


7

C# (Visual C# Interactive Compiler), 20 bytes a=>b=>(char)(a+b>>1) Try it online!


6

APL (Dyalog Unicode), 19 bytes {⍸0=⍵|-/¨⍺*⍨⍳3⍴⍵-1} The triples are returned in the format x z y. Try it online! Explanation {⍸0=⍵|-/¨⍺*⍨⍳3⍴⍵-1} ⍝ n is our right argument, ⍵, and p is our left, ⍺. 3⍴⍵-1 ⍝ First, we get a triple of (n-1, n-1, n-1). ⍳ ⍝ Then we get the Cartesian product of three range[1, n-1). ...


6

Octave, 60 42 41 40 bytes I was just looking for an excuse to use nlfilter, too bad the solution was too long:) Now we compute the vectors of the sides of the polygon using d=x-x(:,[2:end,1])). Then d * d' computes all pairwise dot products. We are only interested if consecutive dot products are all zero, therefore we check whether the first superdiagonal ...


6

Jelly, 4 bytes OSHỌ Try it online! Explanation OSHỌ Main Link: takes (a, b) O (ord(a), ord(b)) S sum; ord(a) + ord(b) H halve; (ord(a) + ord(b)) / 2 Ọ chr


6

x86-16 ASM, IBM PC DOS, 13 12 bytes Binary (xxd): 00000000: a182 0002 c4d0 e8b4 0ecd 10c3 ............ Listing: A1 0082 MOV AX, [0082H] ; load two chars into AH and AL from command line 02 C4 ADD AL, AH ; AL = AL + AH D0 E8 SHR AL, 1 ; AL = AL / 2 B4 0E MOV AH, 0EH ; BIOS tty output ...


6

JavaScript (ES7),  87 83 82 79  72 bytes Saved 2 bytes thanks to @Shaggy Saved 7 bytes thanks to @GB's insight Takes input as (n)(list). Derived from the reference implementation. with(Math)f=n=>a=>a.map(v=>n+=sin(2*v*T)/sin(T)**2,n/=-tan(T=PI/n))&&n/4 Try it online! Given the number of sides \$n\$ and the folding values \$F_1\...


6

Haskell, 23 bytes foldr((<*>).map(:))[[]] Try it online! Without using mapM or sequence or the like.


6

Python 3, 56 bytes def f(M,*l):M and[f(M[1:],*l,x)for x in M[0]]or print(l) Try it online! No itertools. This is one of those weird functions that prints. Thanks to Unrelated String for -2 bytes with def.


5

Jelly, 13 bytes *ŒH§%³E Ṗṗ3çƇ A full program accepting command line arguments n p which prints a list representation of the results (Do note that the empty list is represented as no output). Try it online! How? *ŒH§%³E - Link 1: evaluate a triple: [x, y, z], p * - exponentiate [x^p, y^p, z^p] ŒH - split into halves [[x^...


5

APL (Dyalog Unicode), 16 bytes ×/0=4○∘×2÷/2-/,⍨ Try it online! Accepts the input as a list of complex numbers, e.g. 1j2 means \$ 1 + 2i \$ which represents the point \$ (1,2) \$. The result is 1 if the given polygon is rectilinear, 0 otherwise. How it works ×/0=4○∘×2÷/2-/,⍨ ,⍨ Concatenate self, so that all angles can be tested ...


5

JavaScript (ES6),  56  52 bytes Returns a Boolean value. a=>![...a,1].some(x=>t>0/x?1:(t+=x-1)*x<0?t=0:0,t=0) Try it online! Commented The accumulator \$t\$ is decremented whenever an empty slot is encountered. For each non-zero value \$x\$, we update \$t\$ to \$max(t+x-1,0)\$. The test fails if we reach a non-empty slot (or the ...


5

Keg -ir -oc, 5 2 bytes (SBCS) Works in all 3 test cases. +½ Try it online! Explanation -ir will *not* try to evaluate the input + Add them ½ Halve the value -oc Output all as a character, if possible Implicit print. The output is print nice by default. ```


5

Poetic, 163 bytes software inside a computer a robot+a man+a keypad+a plan=a PC still,P.C.this,P.C.that?i await a day i crush a PC resist P.C,Google,or an Apple i do Linux,i suppose Try it online! Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols. (I actually use PC myself. 😉)


5

K (oK), 8 bytes Solution: `c$.5*+/ Try it online! Explanation: Sum, multiply by 0.5 and convert to ASCII. `c$.5*+/ / the solution +/ / sum (add-over) .5* / multiply by 0.5 `c$ / convert to ASCII


5

R, 56 37 bytes intToUtf8(mean(utf8ToInt(scan(,"")))) Try it online! Description x is the concatenation of the two inputs, e.g. "ac" or "gz". utf8ToInt() converts the inputs into two ASCII numbers. floor(mean()) takes the truncated average. intToUtf8() converts the average into its ASCII character.


5

Bash, 56 bytes printf \\x$(printf %x $[`printf "(%d+%d)/2" \'$1 \'$2`]) Try it online!


4

JavaScript (ES6),  174  171 bytes (d,o,f,v,g=(f,V=v)=>f?V.map(v=>f+`(${v})`):V)=>f+f&&v+v?(d<'»'?f[1]?f.map(f=>g(f).join``):g(f[0]):v.map((_,i)=>v.map((_,j)=>g(f[j],[v[i++%v.length]])).join``)).join(o):'' Try it online! Commented ( d, // d = direction o, /...


4

python3, 3982 2183 1866 1821 1677, ~14s from functools import* #let's start with the comments. I'll exclude them from total count #from functools I need only reduce #I've been coding in python2 for 5 years so I'm used to built-in reduce much #and it's very handy here g=range #just keep it in mind while reading) ranGe -> g #and we're getting rid of classes ...


4

Python 3, 150 133 122 bytes (thanks to Delta and Alexey Burdin for further golfing this) SymPy's mpmath module is a great way to handle this problem. All math functions (exp, log, euler, gamma and quad for integration) are run in high precision. lambda c:gamma(1/c+1)+l(c)-euler*(1-1/c)-1-quad(lambda t:l(.5+5*exp(-9*((-l(t))**(1/c)))),[0,1]) from mpmath ...


4

GAP, 63 bytes Filtered(Tuples([1..n-1],3),i->(i[1]^p+i[2]^p-i[3]^p) mod n=0); For example: gap> n:=4; p:=3; 4 3 gap> Filtered(Tuples([1..n-1],3),i->(i[1]^p+i[2]^p-i[3]^p) mod n=0); [ [ 1, 2, 1 ], [ 1, 3, 2 ], [ 2, 1, 1 ], [ 2, 2, 2 ], [ 2, 3, 3 ], [ 3, 1, 2 ], [ 3, 2, 3 ] ]


4

Jelly, 7 bytes ;`_ƝḋƝẸ Try it online! Outputs \$0\$ if rectilinear, \$1\$ otherwise -2 bytes thanks to Jonathan Allan!


4

Jelly, 10 bytes ŒṗfƑƇL=¥Ƈ⁵ Try it online! A full program that takes the total, token values and number of arguments as its arguments. Returns a list of lists of token values. Explanation Œṗ | Integer partition (of first argument) Ƈ | Keep only those which: Ƒ | - are invariant when: f | - filtered to only include ...


4

J, 17 bytes (+/<.@%#)&.(3&u:) Try it online! (+/<.@%#) truncated average... &. "Under", which applies a transform, then the verb it modifies -- truncated avg in this case -- then the inverse transform.... 3&u: convert to ascii byte integer. That is, it converts each letter to its ascii number, gets the truncated average of those, ...


Only top voted, non community-wiki answers of a minimum length are eligible