85 votes
Accepted

Extending OEIS: Counting Diamond Tilings

Algebra, graph theory, Möbius inversion, research, and Java The symmetry group of the hexagon is the dihedral group of order 12, and is generated by a 60 degree rotation and a mirror flip across a ...
user avatar
  • 42.8k
51 votes

Absolute Sums of Sidi Polynomial Coefficients

Python 2, 43 bytes f=lambda n,k=1:k/n or n*f(n,k+1)+k*f(n-1,k) Try it online! A different approach Ever since I posted this challenge, I tried to come up with a ...
user avatar
  • 207k
34 votes

Print all colorings of a 3x3 grid

Mathematica, 25 bytes Image/@{0,1}~Tuples~{3,3} Gives an array with all the grids as images, which is also directly displayed on screen: (Cropped so as not to ...
user avatar
34 votes

How many partitions do I have?

Mathematica, 11 bytes PartitionsP Explanation ¯\_(ツ)_/¯
user avatar
  • 4,640
31 votes

Anaglot Polygrams

34 Languages, 19 bytes, Score: 38,832,018,459,912,437,760,000 Here is a quick answer I threw together to show that it is possible to get an answer scoring better than 1. ...
user avatar
  • 88.8k
28 votes

Every word from babab to zyzyz

Mathematica, 72 65 61 bytes Print@@@Tuples@{a=##/(b=#5#9#15#21#25#)&@@Alphabet[],b,a,b,a} For testing, I recommend replacing ...
user avatar
27 votes

Catalan Numbers

C, 78 52 39 34 33 bytes Even more C magic (thanks xsot): c(n){return!n?:(4+6./~n)*c(n-1);} ?: is a GNU extension. This time ...
user avatar
26 votes

Concentric rings on a snub square tiling

Ruby, 26 bytes ->n{~-n*12-496/4**n%4+1/n} Try it online! Revised version adding 1/n and subtracting ...
user avatar
25 votes

Bernoulli Numbers

Mathematica, 40 28 23 22 bytes Using the famous formula n*ζ(1−n)=−Bn, where ζ is the Riemann Zeta function. If[#>0,-Zeta[1-#]#,1]& The same length: <...
user avatar
25 votes

Catalan Numbers

Jelly, 4 bytes Ḥc÷‘ Try it online! How it works ...
user avatar
  • 207k
25 votes

The square root of the square root of the square root of the…

APL (Dyalog Unicode), 39 bytes +/⊢{∨/⍺⍵<⍵0:0⋄⍺=0:1⋄+/∊∇¨/⍺(⍵*2)-⊂⍳⍺}¨⍳ Try it online! A tacit function containing an inner dfn to use recursion. Does not use ...
user avatar
  • 62.9k
24 votes

Sticky polyhexes

Haskell, 320…236 230 bytes ...
user avatar
  • 6,236
23 votes

Compute the multinomial coefficient

Jelly, 7 6 bytes ;_/!:/ Look ma, no Unicode! This program takes a single list as input, with n at its first index. Try it online! or verify all test cases at ...
user avatar
  • 207k
23 votes

Brute-force the switchboard

Haskell, 25 24 23 17 bytes mapM$min"^v".pure Try it online! -1 byte thanks to @H.PWiz -1 byte thanks to @nimi Returns a list of strings. The TIO has 2 extra ...
user avatar
  • 3,916
21 votes

Don't repeat yourself in Rock-Paper-Scissors

Ruby, 39 bytes ->n{(?P*n..?S*n).grep_v /[^RPS]|(.+)\1/} This hilariously inefficient function generates all strings of length N that lie alphabetically ...
user avatar
  • 21.8k
20 votes
Accepted

The Combinatorics of Transistor

CJam (56 bytes) q~4@:Nm*:$_&{:+1$\-N),&},f{1$1$:+-\0-:(_e`0f=+++:m!:/}:+ Online demo This is an optimised version of the reference implementation I ...
user avatar
  • 42.8k
20 votes

Count sums of two squares

Python (59 57 56 bytes) lambda n:0**n+sum((-(n%(x-~x)<1))**x*4for x in range(n)) Online demo As with my CJam answer, this uses Möbius inversion and runs in ...
user avatar
  • 42.8k
20 votes

Partitioning the grid into triangles

Haskell, 60 55 54 52 bytes After a drawing and programming a lot of examples, it occured to me that this is the same as the problem of the rooks: On a \$(n+1) \times (n+1)\$ chessboard, how many ...
user avatar
  • 43.1k
19 votes

Stuffing primes in a box

Smalltalk, 1098 primes First off, nice hard question - as evidenced by the lack of non-trivial responses thus far. I had a solution cooking at work, but had to wait for the long weekend to have time ...
user avatar
19 votes

Deranged !Combinatorics: Compute the Subfactorial

Funciton, 336 bytes Byte count assumes UTF-16 encoding with BOM. ...
user avatar
19 votes

Counting universal n-ary logic gates

Python 3.8 (pre-release), 287 282 242 bytes -5 bytes thanks to @Dialfrost ...
user avatar
  • 6,705
18 votes

Combinatorial products of unique primes

Pure Bash, 32 bytes eval echo \$[{1,${1// /\}*{1,}}] Reads input list (single space separated) passed as a command-line arg. Three different shell expansions are ...
user avatar
18 votes

A penny saved is a penny

Haskell, 37 34 bytes s#l@(c:d)|s>=c=(s-c)#l+s#d s#_=0^s Usage example: 26 # [1,5,10,25] -> ...
user avatar
  • 35.3k
17 votes

Code-Golf: Permutations

Python, 52 Input is a set. Output is a list of lists. f=lambda a:[p+[x]for x in a for p in f(a-{x})]or[[]] This is shorter than the answer that does all the work ...
user avatar
  • 30.9k
17 votes
Accepted

Generate all combinations of given list of elements, sorted

Jelly, 1 byte TryItOnline Cartesian power built-in atom, as a dyadic link with left argument the items and right argument the count, or as a full program with ...
user avatar
17 votes

Converge to a number

Jelly, 9 bytes DLḶU⁵*xDÄ Try it online! ...
user avatar
  • 66k
17 votes

Enumerate all pure sets

Python, 43 bytes f=lambda x:[f(i)for i in range(x)if x>>i&1] Attempt This Online! Outputs the \$ n \$th set, starting at \$ 0 \$. One way of creating a sequence of all pure sets is to encode ...
user avatar
  • 21.5k
16 votes
Accepted

Print all colorings of a 3x3 grid

K, 11 bytes (3 3#)'!9#2 Output example: ...
user avatar
  • 4,932
16 votes

Count sums of two squares

Python 2, 44 bytes f=lambda n,x=1:+(x>n)or(n%x<1)-f(n,x+2)/4<<2 This is almost the same as xsot's solution (which is based on Peter Taylor's solution)...
user avatar
16 votes

Super permutations

Scratch 3.0, 65 blocks / 637 632 bytes Look at y'all, having fun with your fancy shmancy permutation functions/map tools. Well, not I! No, not I! When using Scratch, one has to do things themselves! ...
user avatar
  • 22.1k

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