Skip to main content
8 votes

Sum-of-four-squares grid

sed 4.2.2 -r, 1303 1252 1201 1053 838 764 710 681 629 615 bytes ...
guest4308's user avatar
  • 1,215
8 votes

Calculate the sum of numbers in a rectangle

Python 3.8 (pre-release),  99   79   74   73   70   68  67 bytes -20 bytes by removing the auxiliary t lambda, since it was only used once. -5 bytes thanks to ...
squareroot12621's user avatar
8 votes

Calculate the sum of numbers in a rectangle

Python, 61 59 bytes f=lambda a,b,c,d:c<d and((c+b)**3-b)/6+b*c-f(b,a,c+(b<a),d) Attempt This Online! Takes top incl, bottom excl, left incl, right excl. How? ...
Albert.Lang's user avatar
  • 3,724
7 votes

Shift right by half a trit

Python 3, 55 bytes f=lambda n,c=1:n>c and f(n,c*3)or[0,(n+c)//3,n-c][n//c] Try it online! The termination condition n>c ...
xnor's user avatar
  • 146k
7 votes

Calculate the sum of numbers in a rectangle

Python 3, 75 bytes Just wanted to see how far a closed formula can go. Uses the same inclusive bounds as in the question, in slightly different order. ...
ovs's user avatar
  • 60.1k
6 votes

Shift right by half a trit

Jelly,  13  10 bytes -3 bytes porting Dominic van Essen's implementation of my approach. b3ḢḂȧ%3¬)S Try it online! Or see the test-suite. How? ...
Jonathan Allan's user avatar
6 votes

Calculate the sum of numbers in a rectangle

JavaScript (Node.js), 55 bytes f=(x,y,X,Y)=>X?x<X&&f(y,x,Y)+f(x+1,y,X,Y):x-(y+=x)*~y/2 Try it online!
l4m2's user avatar
  • 26k
6 votes
Accepted

How many ways can you make change?

Jelly, 15 14 bytes ŒṗịŒp€ẎṢ€Qɓ;Ṭ} Try it online! Oh yeah... Given n on the left and the objects (with no 0 list!) on the right, outputs the nth collection of ...
Unrelated String's user avatar
5 votes

Shift right by half a trit

JavaScript (Node.js), 34 bytes f=n=>n<2?0:!(n/3^f(1+f(--n)))+f(n) Try it online! Self is slow, but can save states to fasten JavaScript (Node.js), 47 bytes ...
l4m2's user avatar
  • 26k
5 votes

Sum-of-four-squares grid

05AB1E, 50 49 bytes ∞Íonîü2íε`U0LsãεXô}Σ˜O]í€`.Δ[D˜g5‹#2δô2ô€øOOn}OOQ Brute-force. Generates all \$2^k\times 2^k\$ sized matrices consisting of 0s and 1s, and will ...
Kevin Cruijssen's user avatar
5 votes

Sum-of-four-squares grid

Pyth, 48 bytes M?Gho_SsNmsCMc2sgLtGdfqHs*VTT^UhH4]]Hgf>2eSsgTQZ Try it online! Can run up to about 30 before timing out online. Try a more performant, 5 byte ...
CursorCoercer's user avatar
5 votes

How many ways can you make change?

JavaScript (V8), 80 bytes Expects (list_of_lists)(n) without any list for weight 0. Outputs by printing comma-separated strings. ...
Arnauld's user avatar
  • 195k
5 votes

How many ways can you make change?

Charcoal, 52 bytes ⊞υ⊞OEθκωFυ≡§I⁻↨E§ι±¹§θκ¹η⁰0…⮌ι¹-¿⊖Lι⊞⊞OυΦιλ⊞Oι⁺⊟ι§ι⁰ Attempt This Online! Link is to verbose version of code. Takes the collection as a ...
Neil's user avatar
  • 174k
4 votes

Shift right by half a trit

Setanta, 65 bytes gniomh(n){s:=1nuair-a s*3<=n s*=3toradh(n|0&n/s<2&(n+s)//3)|n-s} try-setanta.ie link Explanation ...
bb94's user avatar
  • 3,628
4 votes

Shift right by half a trit

Nekomata + -n, 10 bytes R~3DᵉlhÖ*ž Attempt This Online! A port of @Dominic van Essen's implementation of @Jonathan Allan's ...
alephalpha's user avatar
  • 49.3k
4 votes

Calculate the sum of numbers in a rectangle

Python 3, 73 bytes lambda a,b,c,d:(e:=c-a)*(f:=d-b)*(e*e+f*f+3*(~a-b-c-d)**2-12*(a+c)-17)/24 Try it online! I tried golfing a closed formula (independently of ovs)...
xnor's user avatar
  • 146k
4 votes

How many ways can you make change?

05AB1E, 18 bytes FĆ}¹Åœèε.«âεS{]€`Ù Inputs in the order \$n,objectLists\$, including an empty list at index 0. Assumes the objects are always single characters (...
Kevin Cruijssen's user avatar
3 votes

Rabinowitz-Wagon \$\pi\$ formula

R, 74 61 bytes `~`=\(n,m=1)`if`(m>n,1,(a=n~m+1)[1]*(2*m+1)+m*a*0:1)*1:2^!m-1 Attempt This Online! Recursive approach to construct the Rabinowitz-Wagon formula ...
Dominic van Essen's user avatar
3 votes

Factoriadic Fraction Addition

Wolfram Language (Mathematica), 71 bytes If[#==0,{},{a=⌊++j#⌋,##&@@#0[j#-a]}]&@Tr[Tr[i=j=1;#/++i!&/@#]&/@#]& Try it online! Input ...
att's user avatar
  • 21.3k
3 votes

Dijkstra's Challenge

Uiua, 11 bytes ⧻⊚×⊸=/+°⍉°⊡ Try it online! Explanation ...
janMakoso's user avatar
  • 101
3 votes

Cubic Concatenation

Excel, 23 Bytes An anonymous workbook function that takes input from a vertical array at A1# and outputs to the calling cell ...
Taylor Raine's user avatar
  • 8,686
3 votes

Cubic Concatenation

ARBLE, 21 bytes a^3+b^3+c^3-(a..b..c) 0 for truthy, non-zero for falsey. Try it online! Run all tests!
ATaco's user avatar
  • 10.9k
3 votes

Shift right by half a trit

R, 41 40 bytes `?`=\(n)`if`(n<2,0,(k=?n-1)+!n%/%3-?1+k) Attempt This Online! Port of @l4m2's JS answer. Slightly ungolfed: ...
pajonk's user avatar
  • 17.8k
3 votes

Shift right by half a trit

05AB1E, 15 bytes _+3Bć©3αì®i¨}3ö Try it online or verify all test cases. Explanation: ...
Kevin Cruijssen's user avatar
3 votes

Shift right by half a trit

Nibbles, 18 nibbles (9 bytes) ,|,$~*%$3- 2/`@3 Attempt This Online! An implementation of Jonathan Allan's approach of counting elements of A003605 up to ...
Dominic van Essen's user avatar
3 votes

Sum-of-four-squares grid

Charcoal, 101 bytes Nθ≔⦃⁰⟦0⟧¹⟦1⟧⦄ηW∧¬§ηθη«≔⦃⦄η≔EιλζFζFζFζFζ«≔ΣX⟦νμλκ⟧²ε≔⁺E§ιν⁺ιμπE§ιλ⁺ικπδ¿∨¬§ηε‹ΣΣδΣΣ§ηε§≔ηεδ»»§ηθ Attempt This Online! Link is to verbose ...
Neil's user avatar
  • 174k
3 votes

Calculate the sum of numbers in a rectangle

Desmos, 49 bytes f(a,b,c,d)=∑_{x=a}^b∑_{y=c}^d((x+y)^2+3x+y)/2 Order: inclusiveLeftX, inclusiveRightX, inclusiveTopY, inclusiveBottomY Try it online
Lucenaposition's user avatar
3 votes

Calculate the sum of numbers in a rectangle

Jelly,  11  9 bytes -2 thanks to Unrelated String (use of the table hyper, þ, to avoid separately taking the Cartesian product with ...
Jonathan Allan's user avatar
3 votes

Calculate the sum of numbers in a rectangle

Haskell, 53 48 47 bytes -5 bytes thanks to xnor -1 byte thanks to Wheat Wizard ♦ f a b c d=sum$do i<-[a..c];j<-[b..d];j:[1..i+j] Try it online! The code ...
DPD-'s user avatar
  • 391
3 votes

How many ways can you make change?

Nekomata, 6 bytes Ṗ@ᵐ~oũ Attempt This Online! A port of @Unrelated String's Jelly answer, but much shorter thanks to Nekomata's non-determinism. ...
alephalpha's user avatar
  • 49.3k

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