| Bytes | Lang | Time | Link |
|---|---|---|---|
| 006 | Husk | 240909T085050Z | int 21h |
| 006 | Pyth | 240909T083556Z | int 21h |
| 004 | Thunno 2 | 230813T103807Z | The Thon |
| 007 | J | 230413T122238Z | south |
| 048 | Nibbles | 230413T121330Z | Dominic |
| 049 | Scala | 230413T115736Z | 138 Aspe |
| 015 | Excel | 220421T141836Z | Engineer |
| 032 | x86 32bit machine code | 220505T194148Z | user3604 |
| 058 | C gcc | 220430T185803Z | naffetS |
| 005 | Halfwit | 220421T132258Z | Kevin Cr |
| 007 | Pip | 220413T201755Z | naffetS |
| 009 | Burlesque | 220413T093659Z | DeathInc |
| 046 | Ruby | 220410T031200Z | oeuf |
| 057 | Java JDK | 220408T214316Z | Unmitiga |
| 014 | MATLAB/Octave | 220408T211403Z | elementi |
| 005 | Vyxal | 220406T230608Z | naffetS |
| 009 | jq | 220407T193453Z | naffetS |
| 456 | λ2d | 220408T102935Z | jonatjan |
| 007 | J | 220407T195838Z | naffetS |
| 014 | R | 220407T192945Z | Rui Barr |
| 004 | 05AB1E | 220407T000711Z | naffetS |
| 014 | Julia 1.0 | 220407T131318Z | MarcMush |
| 006 | BQN | 220407T100603Z | Dominic |
| 035 | MathGolf | 220407T093332Z | Kevin Cr |
| 005 | Japt v2.0a0 m | 220407T071044Z | Shaggy |
| 011 | APL+WIN | 220406T165223Z | Graham |
| 009 | Wolfram Language Mathematica | 220407T050604Z | Roman |
| 216 | LOLCODE | 220407T024509Z | naffetS |
| 023 | PARI/GP | 220407T011843Z | alephalp |
| 016 | Desmos | 220407T005857Z | Aiden Ch |
| 060 | C clang | 220406T232510Z | a stone |
| 022 | Ruby | 220406T225945Z | naffetS |
| 028 | Red | 220406T221451Z | chunes |
| 032 | JavaScript Node.js | 220406T213522Z | Youserna |
| 023 | Factor + math.unicode | 220406T214454Z | chunes |
| 007 | TIBasic | 220406T214102Z | Youserna |
| 048 | Jelly | 220406T212348Z | Jonathan |
| 018 | Haskell | 220406T185751Z | naffetS |
| 032 | Python | 220406T185211Z | pxeger |
| 007 | Charcoal | 220406T183833Z | Neil |
Husk, 6 bytes
m≠/4Σ¹
The same logic as in other answers as well as my Pyth answer.
Commented:
¹ # duplicate the argument
Σ # sum up the input list
/4 # divide it by 4
m≠ # map the absolute difference for the whole sum and each partial sum (this is second use of the argument)
Pyth, 6 bytes
m-/sQ4
Takes a list of partial sums and outputs the list of the individual apples' weights.
The solution is pretty basic: sum up the whole list, divide by 4, then get the differences with each input sum.
Commented:
sQ # sum up the input list Q
/ 4 # divide by 4
m- # from the result subtract each input value (by mapping)
Thunno 2, 4 bytes
S4÷_
Explanation
S4÷_ # Implicit input
S # Sum the list
4÷ # Floor divide by 4
_ # Subtract input from this
# Implicit output
J, 7 bytes
-~4%~+/
Nothing new here.
-~4%~+/
+/ NB. sum
4%~ NB. divide result by 4
-~ NB. subtract result by input, vectorized
Nibbles, 4 bytes (8 nibbles)
+/+$4*~
+ # sum of
$ # the input
/ # divided by
4 # 4
+ # added to
# (implicitly) each element of input
* # multiplied by
~ # -1
Scala, 49 bytes
saved many bytes, but it run so slow.
val f:List[Int]=>List[Int]=a=>a.map(x=>a.sum/4-x)
Excel, 15 bytes
=SUM(A1#)/4-A1#
Input is in cell A1 as an array. For instance, ={798;794;813;806;789}
Excel, 19 bytes
=SUM(A1:A5)/4-A1:A5
Input is in the cells A1:A5. Doesn't rely on array input. Output is wherever the formula is. It's not a very interesting solution.
x86 32-bit machine code, 32 bytes
00000000: 87ca 31c0 6a05 5903 448a fce2 fac1 e802 ..1.j.Y.D.......
00000010: 6a05 5950 2b44 8afc 8944 8afc 58e2 f4c3 j.YP+D...D..X...
Assembly
section .text
global func
func: ;void func(int *ecx);
; int *edx=ecx; int eax=0;
xchg ecx, edx
xor eax,eax
; for(ecx=5;ecx>0;ecx--)eax+=edx[ecx-1]
push 0x5
pop ecx
add:
add eax, [edx + 4*ecx-4]
loop add
; eax = eax / 4
shr eax, 2
; for(ecx=5;ecx>0;ecx--)edx[ecx-1]=eax-edx[ecx-1];
push 0x5
pop ecx
sub:
push eax
sub eax, [edx + 4*ecx-4]
mov [edx + 4*ecx-4], eax
pop eax
loop sub
; return
ret
Takes a pointer to an array of 5 integers in ECX (fastcall convention), and modifies the array in place with the results.
C (gcc), 61 58 bytes
n,i;f(int*a){for(i=10;i--;)i>4?n+=a[i%5]:(a[i]=n/4-a[i]);}
-3 bytes thanks to ceilingcat
Halfwit, 5 bytes
kJ>+<k+N+N
Inputs as a list of BigInts.
Explanation:
kJ # Sum the (implicit) input-list
>+< # Push compressed BigInt 4n
k+ # Integer-divide the sum by this 4
N+N # Subtract the values in the (implicit) input-list from this value:
N # Negate the value
+ # Add it to each value in the (implicit) input-list
N # Negate each value in the list
# (after which the result is output implicitly)
Burlesque, 9 bytes
J++4./j?-
J # Duplicate
++ # Sum
4./ # Divide by 4
j # Swap
?- # Subtract from each
MATLAB/Octave, 14 bytes
@(x)sum(x)/4-x
Try it online!
Basically the same algorithm everyone else uses, as lambda function.
Vyxal, 9 7 6 5 bytes
∑4ḭ$-
Explanation
∑4ḭ$-
# (implicit input)
∑ # Sum
4ḭ # Divide the sum by four
$- # Swap and subtract
-2 bytes thanks to a stone arachnid
-1 byte thanks to ovs
λ-2d, 456 squares
the program can be imported in the playground with the following JSON file
{"41,13":"entry","41,18":"entry","41,23":"entry","41,28":"entry","41,32":"entry","42,13":"end_s","42,18":"end_s","42,23":"end_s","42,28":"end_s","42,32":"end_s","43,13":"end_e","43,18":"end_e","43,23":"end_e","43,28":"end_e","43,32":"end_e","39,15":"wire_nw","39,20":"wire_nw","39,25":"wire_nw","39,30":"wire_nw","39,34":"wire_nw","38,15":"wire_ne","38,20":"wire_ne","38,25":"wire_ne","38,30":"wire_ne","38,34":"wire_ne","44,13":"frame_tl","44,18":"frame_tl","44,23":"frame_tl","44,28":"frame_tl","44,32":"frame_tl","45,13":"wire_we","45,18":"wire_we","45,23":"wire_we","45,28":"wire_we","45,32":"wire_we","46,13":"wire_we","46,18":"wire_we","46,23":"wire_we","46,28":"wire_we","46,32":"wire_we","47,13":"wire_we","47,18":"wire_we","47,23":"wire_we","47,28":"wire_we","47,32":"wire_we","47,15":"wire_we","47,20":"wire_we","47,25":"wire_we","47,30":"wire_we","47,34":"wire_we","46,15":"wire_we","46,20":"wire_we","46,25":"wire_we","46,30":"wire_we","46,34":"wire_we","45,15":"wire_we","45,20":"wire_we","45,25":"wire_we","45,30":"wire_we","45,34":"wire_we","48,13":"wire_sw","48,18":"wire_sw","48,23":"wire_sw","48,28":"wire_sw","48,32":"wire_sw","48,15":"wire_nw","48,20":"wire_nw","48,25":"wire_nw","48,30":"wire_nw","48,34":"wire_nw","44,15":"wire_ne","44,20":"wire_ne","44,25":"wire_ne","44,30":"wire_ne","44,34":"wire_ne","44,14":"wire_ns","44,19":"wire_ns","44,24":"wire_ns","44,29":"wire_ns","44,33":"wire_ns","48,14":"wire_ns","48,19":"wire_ns","48,24":"wire_ns","48,29":"wire_ns","48,33":"wire_ns","42,14":"wire_nw","42,19":"wire_nw","42,24":"wire_nw","42,29":"wire_nw","42,33":"wire_nw","41,14":"wire_we","41,19":"wire_we","41,24":"wire_we","41,29":"wire_we","41,33":"wire_we","40,14":"wire_we","40,19":"wire_we","40,24":"wire_we","40,29":"wire_we","40,33":"wire_we","38,14":"wire_sw","38,19":"wire_sw","38,24":"wire_sw","38,29":"wire_sw","38,33":"wire_sw","39,14":"func_call","39,19":"func_call","39,24":"func_call","39,29":"func_call","39,33":"func_call","39,13":"joint_nsw","39,18":"joint_nsw","39,23":"joint_nsw","39,28":"joint_nsw","38,13":"wire_we","38,18":"wire_we","38,23":"wire_we","38,28":"wire_we","37,13":"wire_se","37,18":"wire_se","37,23":"wire_se","37,28":"wire_se","37,14":"wire_nswe","37,19":"wire_nswe","37,24":"wire_nswe","37,29":"wire_nswe","37,17":"wire_nw","37,22":"wire_nw","37,27":"wire_nw","37,32":"wire_nw","36,17":"wire_se","36,22":"wire_se","36,27":"wire_se","36,32":"wire_se","37,15":"wire_ns","37,20":"wire_ns","37,25":"wire_ns","37,30":"wire_ns","36,15":"wire_nw","36,20":"wire_nw","36,25":"wire_nw","36,30":"wire_nw","36,34":"wire_nw","35,15":"wire_ne","35,20":"wire_ne","35,25":"wire_ne","35,30":"wire_ne","35,34":"wire_ne","35,14":"wire_sw","35,19":"wire_sw","35,24":"wire_sw","35,29":"wire_sw","35,33":"wire_sw","36,14":"func_call","36,19":"func_call","36,24":"func_call","36,29":"func_call","36,33":"func_call","36,13":"joint_nsw","36,18":"joint_nsw","36,23":"joint_nsw","36,28":"joint_nsw","35,13":"wire_we","35,18":"wire_we","35,23":"wire_we","35,28":"wire_we","34,13":"wire_se","34,18":"wire_se","34,23":"wire_se","34,28":"wire_se","34,14":"wire_nswe","34,19":"wire_nswe","34,24":"wire_nswe","34,29":"wire_nswe","34,17":"wire_nw","34,22":"wire_nw","34,27":"wire_nw","34,32":"wire_nw","33,17":"wire_se","33,22":"wire_se","33,27":"wire_se","33,32":"wire_se","34,15":"wire_ns","34,20":"wire_ns","34,25":"wire_ns","34,30":"wire_ns","33,15":"wire_nw","33,20":"wire_nw","33,25":"wire_nw","33,30":"wire_nw","33,34":"wire_nw","32,15":"wire_ne","32,20":"wire_ne","32,25":"wire_ne","32,30":"wire_ne","32,34":"wire_ne","32,14":"wire_sw","32,19":"wire_sw","32,24":"wire_sw","32,29":"wire_sw","32,33":"wire_sw","33,14":"func_call","33,19":"func_call","33,24":"func_call","33,29":"func_call","33,33":"func_call","33,13":"joint_nsw","33,18":"joint_nsw","33,23":"joint_nsw","33,28":"joint_nsw","32,13":"wire_we","32,18":"wire_we","32,23":"wire_we","32,28":"wire_we","31,13":"wire_se","31,18":"wire_se","31,23":"wire_se","31,28":"wire_se","31,14":"wire_nswe","31,19":"wire_nswe","31,24":"wire_nswe","31,29":"wire_nswe","31,17":"wire_nw","31,22":"wire_nw","31,27":"wire_nw","31,32":"wire_nw","30,17":"wire_se","30,22":"wire_se","30,27":"wire_se","30,32":"wire_se","31,15":"wire_ns","31,20":"wire_ns","31,25":"wire_ns","31,30":"wire_ns","30,15":"wire_nw","30,20":"wire_nw","30,25":"wire_nw","30,30":"wire_nw","30,34":"wire_nw","29,15":"wire_ne","29,20":"wire_ne","29,25":"wire_ne","29,30":"wire_ne","29,34":"wire_ne","29,14":"wire_sw","29,19":"wire_sw","29,24":"wire_sw","29,29":"wire_sw","29,33":"wire_sw","30,14":"func_call","30,19":"func_call","30,24":"func_call","30,29":"func_call","30,33":"func_call","30,13":"joint_nsw","30,18":"joint_nsw","30,23":"joint_nsw","30,28":"joint_nsw","29,13":"wire_we","29,18":"wire_we","29,23":"wire_we","29,28":"wire_we","28,13":"wire_se","28,18":"wire_se","28,23":"wire_se","28,28":"wire_se","28,14":"wire_nswe","28,19":"wire_nswe","28,24":"wire_nswe","28,29":"wire_nswe","28,17":"wire_nw","28,22":"wire_nw","28,27":"wire_nw","28,32":"wire_nw","27,17":"wire_se","27,22":"wire_se","27,27":"wire_se","27,32":"wire_se","28,15":"wire_ns","28,20":"wire_ns","28,25":"wire_ns","28,30":"wire_ns","27,14":"func_call","27,19":"func_call","27,24":"func_call","27,29":"func_call","27,33":"func_call","27,13":"joint_nsw","27,18":"joint_nsw","27,23":"joint_nsw","27,28":"joint_nsw","26,13":"wire_se","26,18":"wire_se","26,23":"wire_se","26,28":"wire_se","26,14":"wire_ns","26,19":"wire_ns","26,24":"wire_ns","26,29":"wire_ns","26,15":"wire_ns","26,20":"wire_ns","26,25":"wire_ns","26,30":"wire_ns","26,16":"wire_ne","26,21":"wire_ne","26,26":"wire_ne","26,31":"wire_ne","27,16":"wire_we","27,21":"wire_we","27,26":"wire_we","27,31":"wire_we","29,16":"wire_we","29,21":"wire_we","29,26":"wire_we","29,31":"wire_we","30,16":"wire_we","30,21":"wire_we","30,26":"wire_we","30,31":"wire_we","32,16":"wire_we","32,21":"wire_we","32,26":"wire_we","32,31":"wire_we","33,16":"wire_we","33,21":"wire_we","33,26":"wire_we","33,31":"wire_we","35,16":"wire_we","35,21":"wire_we","35,26":"wire_we","35,31":"wire_we","36,16":"wire_we","36,21":"wire_we","36,26":"wire_we","36,31":"wire_we","39,16":"wire_sw","39,21":"wire_sw","39,26":"wire_sw","39,31":"wire_sw","39,17":"wire_ns","39,22":"wire_ns","39,27":"wire_ns","39,32":"wire_ns","38,16":"wire_we","38,21":"wire_we","38,26":"wire_we","38,31":"wire_we","28,16":"wire_nswe","28,21":"wire_nswe","28,26":"wire_nswe","28,31":"wire_nswe","31,16":"wire_nswe","31,21":"wire_nswe","31,26":"wire_nswe","31,31":"wire_nswe","34,16":"wire_nswe","34,21":"wire_nswe","34,26":"wire_nswe","34,31":"wire_nswe","37,16":"wire_nswe","37,21":"wire_nswe","37,26":"wire_nswe","37,31":"wire_nswe","28,33":"wire_we","31,33":"wire_we","34,33":"wire_we","37,33":"wire_we","39,12":"num_7","40,12":"num_8","41,12":"num_9","36,11":"num_8","37,11":"num_0","38,11":"num_6","33,12":"num_8","34,12":"num_1","35,12":"num_3","30,11":"num_7","31,11":"num_9","32,11":"num_4","28,12":"num_9","29,12":"num_8","27,12":"num_7","30,12":"wire_ns","36,12":"wire_ns","27,15":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,20":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,25":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,30":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,34":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"53,12":"func_def","55,12":"func_def","57,12":"func_def","59,12":"func_def","61,12":"func_def","54,12":"end_s","58,12":"end_s","56,12":"end_s","60,12":"end_s","62,12":"end_s","63,12":"end_e","54,11":"label","55,11":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"53,11":"wire_se","54,13":"joint_nse","55,16":"op_plus","57,16":"op_plus","59,16":"op_plus","61,16":"op_plus","55,15":"func_call","57,15":"func_call","59,15":"func_call","61,15":"func_call","56,13":"wire_nswe","58,13":"wire_nswe","61,13":"wire_we","60,13":"wire_nswe","62,13":"wire_nswe","59,13":"wire_we","57,13":"wire_we","55,13":"wire_we","55,14":"wire_sw","54,14":"wire_ne","56,15":"wire_nw","58,15":"wire_nw","60,15":"wire_nw","57,14":"wire_sw","59,14":"wire_sw","60,14":"func_call","61,14":"wire_sw","56,14":"func_call","58,14":"func_call","62,14":"func_call","62,15":"wire_nw","63,14":"wire_sw","63,15":"wire_ns","63,16":"func_call","63,17":"op_div","64,16":"wire_nw","64,15":"func_call","64,14":"num_4","65,15":"wire_sw","65,16":"func_call","65,17":"op_minus","66,16":"wire_nw","66,14":"func_call","67,14":"wire_nw","66,13":"wire_sw","67,12":"wire_sw","66,15":"wire_ns","67,13":"wire_ns","63,13":"wire_we","64,13":"wire_we","65,13":"wire_we","64,12":"wire_we","65,12":"wire_we","66,12":"wire_we"}
the function in itself is the right structure, the left one being 5 calls to the function with the 5 arguments in differents orders
js equivalent
a=798
b=794
c=813
d=806
e=789
f=v=>w>=>x=>y=>z=>((v+w+x+y+z)/4)-v
f(a)(b)(c)(d)(e)
f(b)(c)(d)(e)(a)
f(c)(d)(e)(a)(b)
f(d)(e)(a)(b)(c)
f(e)(a)(b)(c)(d)
Language explanation can be found in the playground by loading the cheatsheet example, or in the release blog post
BQN, 8 6 bytes
Edit: -2 bytes thanks to ovs
-+´÷⟜4
÷⟜4 # divide each of the input values by 4
+´ # and then fold the 'plus' function across them
- # using the negative of the input as a list of starting values
# (so effectively we start the fold using each negative input value
# in parallel as a starting value)
MathGolf, 3 (or 5) bytes
Σ¼,
No idea why MathGolf has a single-byte a//4 builtin, but it's pretty useful here. ;)
With strict input of space-delimited values it would be 5 bytes instead:
ê_Σ¼,
Explanation:
# Optional for stricter space-delimited input:
ê # Push the inputs as integer-array
_ # Duplicate it
Σ # Sum the values together
¼ # Integer-divide it by 4
, # Subtract each value in the list from this sum//4
# (after which the entire stack is output implicitly)
APL+WIN, 13 11 bytes
-2 bytes thanks to att
Prompts for an vector of total weight minus each apple in turn
(+/w÷4)-w←⎕
LOLCODE, 216 bytes
HOW IZ I f YR a
I HAS A s ITZ 0
IM IN YR l UPPIN YR i TIL BOTH SAEM i 5
s R SUM OF s a'Z SRS i
IM OUTTA YR l
IM IN YR l UPPIN YR i TIL BOTH SAEM i 5
VISIBLE DIFF OF QUOSHUNT OF s 4 a'Z SRS i
IM OUTTA YR l
IF U SAY SO
C (clang), 60 bytes
b,c;f(*a){for(b=c=0;b<5;c+=a[b++]);for(;b--;a[b]=c/4-a[b]);}
Try it online! Takes an array of 5 integers and modifies the array in-place.
Factor + math.unicode, 23 bytes
[ dup Σ 4 / swap n-v ]
Explanation
! { 798 794 803 816 789 }
dup ! { 798 794 803 816 789 } { 798 794 803 816 789 }
Σ ! { 798 794 803 816 789 } 4000
4 ! { 798 794 803 816 789 } 4000 4
/ ! { 798 794 803 816 789 } 1000
swap ! 1000 { 798 794 803 816 789 }
n-v ! { 202 206 197 184 211 }
TI-Basic, 7 bytes
sum(Ans)/4-Ans
Takes input in Ans. Output is stored in Ans and displayed.
Jelly, 4? 8 bytes
With a strict interpretation of Rule 1 (can't take as a program argument due to the "single line" part) - a full program that reads from STDIN and writes to STDOUT:
ɠḲVµS÷4_
...or with site default IO instead - a monadic Link that accepts a list of five numbers and yields a list of five numbers:
S÷4_
How?
ɠḲVµS÷4_ - Main Link: no arguments
ɠ - read a line from STDIN
Ḳ - split that at spaces
V - evaluate that as Jelly code -> list of the five four-apple-weights, W
µ - start a new monadic chain - f(W)
S - sum W
4 - four
÷ - divide -> sum(W)/4
_ - subtract W (vectorises) -> [sum(W)/4-w1, sum(W)/4-w2, sum(W)/4-w3, sum(W)/4-w4, sum(W)/4-w5]
- implicit print
Charcoal, 7 bytes
I⁻÷Σθ⁴θ
Try it online! Link is to verbose version of code. Explanation:
θ Input list
Σ Take the sum
÷ Integer divided by
⁴ Literal integer `4`
⁻ Vectorised subtract
θ Input list
I Cast to string
Implicitly print
9 bytes for a version that works with two or more apples, not just five:
I⁻÷Σθ⊖Lθθ
Try it online! Link is to verbose version of code.



