Skip to main content
38 votes

Chicken McNugget Numbers

Python, 27 bytes lambda n:0x82492cb6dbf>>n&1 Try it online!
Anders Kaseorg's user avatar
29 votes

Chicken McNugget Numbers

Python 3, 24 bytes lambda n:0<=n--n%3*20!=3 Try it online! Explanation With 6 and 9 ...
Leaky Nun's user avatar
  • 49.8k
28 votes

11 = (1+2+3+4+5) - (1+2+3) + (6) - (4)

Mathematica, 79 bytes Min[2#/(d=Divisors@#~Cases~_?OddQ)+d]-2⌊(2#)^.5+.5⌋+⌈Sqrt[8#+1]~Mod~1⌉& Explanation I couldn't be bothered to implement the algorithm ...
Martin Ender's user avatar
19 votes
Accepted

Yo boy, must it sum

Brachylog, 7 bytes ~+ℕᵐ.↔ᵐ Try it online! Surprisingly not that slow. Explanation ...
Fatalize's user avatar
  • 38.9k
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] -> ...
nimi's user avatar
  • 35.9k
16 votes

Sum of five cubes

Brachylog, 18 bytes ∧5~lLȧᵐ≥₁∧L^₃ᵐ.+?∧ Try it online! Explanation We basically describe the problem, with the additional constraint that we want the output ...
Fatalize's user avatar
  • 38.9k
15 votes

A penny saved is a penny

Mathematica, 35 22 bytes Thanks to miles for suggesting FrobeniusSolve and saving 13 bytes. Length@*FrobeniusSolve Evaluates ...
Martin Ender's user avatar
15 votes

Sum of five cubes

Brachylog, 11 bytes Thanks Fatalize for saving one byte ~+l₅≥₁.√₃ᵐ∧ Try it online! Firstly ~+ enforces that the output (<...
H.PWiz's user avatar
  • 11.6k
14 votes

Number of coins needed to make change

JavaScript (ES7),  36  35 bytes Similar to other answers. Using a Black Magic formula instead of a lookup table. f=n=>n&&(n%10)**29%3571%4+f(n/10|0) ...
Arnauld's user avatar
  • 193k
14 votes

Number of coins needed to make change

Husk, 11 9 8 bytes Edit: -1 byte thanks to caird coinheringaahing ṁo⌈½ṁB5d Try it online! ...
Dominic van Essen's user avatar
13 votes
Accepted

A penny saved is a penny

Jelly (fork), 2 bytes æf This relies on a branch of Jelly where I was working on implementing Frobenius solve atoms so unfortunately you cannot try it online. ...
miles's user avatar
  • 16.9k
13 votes
Accepted

How many partitions do I have?

Pyth, 3 bytes l./ Try it here! or Try a test Suite. The answer took much longer to format than writing the code itself :P. How? Pyth is the right tool for the job....
Mr. Xcoder's user avatar
  • 42.4k
13 votes

Non-sums of distinct positive powers

APL(Dyalog Unicode), 26 bytes SBCS ⊢{z~∊(⊢,+)\⍺*⍨z←⍳!⍵}!×2*×⍨ Try it on APLgolf! This only works theoretically in multiple ways. The upper bound used (factorial of ...
Bubbler's user avatar
  • 77k
12 votes

List all ordered partitions of n

Haskell, 37 bytes f 0=[[]] f n=[a:x|a<-[1..n],x<-f$n-a] xnor saved two bytes.
lynn's user avatar
  • 68.8k
12 votes

A penny saved is a penny

Pyth, 8 bytes /sM{yS*E Raw brute force, too memory intensive for actual testing. This is O(2mn), where n is the number of coins and m is the target sum. Takes ...
PurkkaKoodari's user avatar
11 votes

Yo boy, must it sum

Python 2, 82 79 bytes f=lambda n:min([f(n-k)+[k]for k in range(1,n+1)if`k`==`k`[::-1]]or[[]],key=len) Try it online!
Dennis's user avatar
  • 210k
11 votes

Display a number in Toki Pona

Python 2, 81 bytes lambda n:n/100*'ale '+n/20%5*'mute '+n/5%4*'luka '+n%5/2*'tu '+n%5%2*'wan'or'ala' Try it online! The naive approach is surprisingly effective. ...
dingledooper's user avatar
  • 22.7k
10 votes

List all ordered partitions of n

Python, 56 bytes f=lambda n:[x+[n-i]for i in range(n)for x in f(i)]or[[]] A recursive solution: The ordered partitions of n ...
xnor's user avatar
  • 145k
10 votes

List all ordered partitions of n

Python 2, 61 bytes f=lambda n,s='1,':1/n*[eval(s)]or f(n-1,'1+'+s)+f(n-1,'1,'+s) This isn't the shortest, but I really like the method because it's so weird. ...
xnor's user avatar
  • 145k
10 votes

Fewest operations to 100

JavaScript (ES6), 153 176 bytes EDIT: In non-strict mode, JS interprets 0-prefixed numerical expressions as octal (e.g. 017 is parsed as 15 in decimal). This is a ...
Arnauld's user avatar
  • 193k
10 votes

How many partitions do I have?

Emojicode 0.5, 204 201 bytes 🐋🚂🍇🐖🅰️➡🚂🍇🍊⬅🐕1🍇🍎1🍉🍮s 0🔂k⏩0🐕🍇🍦t➖🐕k🍮r t🔂i⏩1 t🍇🍊😛🚮t i 0🍇🍮➕r i🍉🍉🍮➕s✖r🅰️k🍉🍎➗s🐕🍉🍉 Try it online! -3 bytes ...
Maya's user avatar
  • 5,693
10 votes

Sum of combinations with repetition

Python 2, 46 45 bytes thanks to xnor for -1 byte f=lambda n:n>0and f(n-2)+f(n-3)+f(n-5)or n==0 Try it online!
ovs's user avatar
  • 59.5k
10 votes

Sum of five cubes

Python 2, 58 57 54 bytes def f(n):k=(n**3-n)/6;return[v**3for v in~k,1-k,n,k,k] Try it online! -2 bytes, thanks to Rod -1 byte, thanks to Neil
TFeld's user avatar
  • 19.8k
10 votes
Accepted

Calculate Landau's function

05AB1E, 6 bytes Åœ€.¿Z Try it online! ...
Grimmy's user avatar
  • 15.7k
10 votes

Calculate Landau's function

Wolfram Language (Mathematica), 44 bytes Max[PermutationOrder/@Permutations@Range@#]& Try it online! Wolfram Language (Mathematica), 31 bytes @...
Roman's user avatar
  • 1,983
10 votes

Number of coins needed to make change

Haskell, 55…41 40 bytes -1 byte thanks to xnor, for using a string instead of the hard-coded list. a=0:tail[i+read[j]|i<-a,j<-"0112212233"] Try ...
Delfad0r's user avatar
  • 6,266
10 votes

AoCG2021 Day 14: Adjusting dancing program's period

Pari/GP, 59 bytes (n,m)->[[lcm(Vec(concat(p,q)))==m|q<-s]|p<-s=partitions(n)] Try it online! Let x and ...
alephalpha's user avatar
  • 48.5k
9 votes

A penny saved is a penny

JavaScript (ES6), 51 48 bytes f=(n,a,[c,...b]=a)=>n?n>0&&c?f(n-c,a)+f(n,b):0:1 Accepts coins in any order. Tries both using and not using the first ...
Neil's user avatar
  • 172k
9 votes

A penny saved is a penny

Haskell, 37 bytes s%(h:t)=sum$map(%t)[s,s-h..0] s%_=0^s Using some multiple of the first coin h decreases the required sum <...
xnor's user avatar
  • 145k

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