g | x | w | all
Bytes Lang Time Link
006Husk240909T085050Zint 21h
006Pyth240909T083556Zint 21h
004Thunno 2230813T103807ZThe Thon
007J230413T122238Zsouth
048Nibbles230413T121330ZDominic
049Scala230413T115736Z138 Aspe
015Excel220421T141836ZEngineer
032x86 32bit machine code220505T194148Zuser3604
058C gcc220430T185803ZnaffetS
005Halfwit220421T132258ZKevin Cr
007Pip220413T201755ZnaffetS
009Burlesque220413T093659ZDeathInc
046Ruby220410T031200Zoeuf
057Java JDK220408T214316ZUnmitiga
014MATLAB/Octave220408T211403Zelementi
005Vyxal220406T230608ZnaffetS
009jq220407T193453ZnaffetS
456λ2d220408T102935Zjonatjan
007J220407T195838ZnaffetS
014R220407T192945ZRui Barr
00405AB1E220407T000711ZnaffetS
014Julia 1.0220407T131318ZMarcMush
006BQN220407T100603ZDominic
035MathGolf220407T093332ZKevin Cr
005Japt v2.0a0 m220407T071044ZShaggy
011APL+WIN220406T165223ZGraham
009Wolfram Language Mathematica220407T050604ZRoman
216LOLCODE220407T024509ZnaffetS
023PARI/GP220407T011843Zalephalp
016Desmos220407T005857ZAiden Ch
060C clang220406T232510Za stone
022Ruby220406T225945ZnaffetS
028Red220406T221451Zchunes
032JavaScript Node.js220406T213522ZYouserna
023Factor + math.unicode220406T214454Zchunes
007TIBasic220406T214102ZYouserna
048Jelly220406T212348ZJonathan
018Haskell220406T185751ZnaffetS
032Python220406T185211Zpxeger
007Charcoal220406T183833ZNeil

Husk, 6 bytes

m≠/4Σ¹

Try it online!

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

Try it online!

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÷_

Try it online!

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.

Attempt This Online!

-~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.

Try it online!

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}

ColumnA     ColumnB


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.

Screenshot

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.

Try it online!

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]);}

Try it online!

-3 bytes thanks to ceilingcat

Halfwit, 5 bytes

kJ>+<k+N+N

Try it online.

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)

Pip, 9 7 bytes

$+a/4-a

Attempt This Online!

-2 bytes thanks to DLosc

Burlesque, 9 bytes

J++4./j?-

Try it online!

J   # Duplicate
++  # Sum
4./ # Divide by 4
j   # Swap
?-  # Subtract from each

Ruby, 46 bytes

i=gets.split.map(&:to_i);i.map{|n|p i.sum/4-n}

Attempt This Online!

Java (JDK), 57 bytes

a->a.stream().map(x->a.stream().mapToInt(i->i).sum()/4-x)

Try it online!

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ḭ$-

Try it Online!

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

jq, 20 9 bytes

add/4-.[]

Attempt This Online!

-11 bytes 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"}

full program

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

J, 7 bytes

-~4%~+/

Attempt This Online!

R, 14 bytes

\(x)sum(x)/4-x

Try it online!

Uses the new lambda, \, introduced in R 4.1.

05AB1E, 9 4 bytes

O4÷α

Try it online!

-5 bytes thanks to Kevin Cruijssen

Julia 1.0, 14 bytes

!l=sum(l/4).-l

Try it online!

BQN, 8 6 bytes

Edit: -2 bytes thanks to ovs

-+´÷⟜4

Try it at BQN online REPL

    ÷⟜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. ;)

Try it online.

With strict input of space-delimited values it would be 5 bytes instead:

ê_Σ¼,

Try it online.

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)

Japt v2.0a0 -m, 5 bytes

aWx÷4

Try it

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←⎕

Try it online! Thanks to Dyalog APL Classic

Wolfram Language (Mathematica), 9 bytes

Tr@#/4-#&

Try it online!

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

Try it online!

PARI/GP, 23 bytes

a->[vecsum(a)/4-t|t<-a]

Attempt This Online!

Desmos, 16 bytes

f(l)=l.total/4-l

Try It On Desmos!

Try It On Desmos! - Prettified

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.

Ruby, 22 bytes

->a{a.map{a.sum/4-_1}}

Attempt This Online!

Red, 28 bytes

func[v][v -((sum v)/ 4)* -1]

Try it online!

JavaScript (Node.js), 34 32 bytes

a=>a.map(e=>eval(a.join`+`)/4-e)

Attempt This Online!

-2 bytes thanks to Steffan

Factor + math.unicode, 23 bytes

[ dup Σ 4 / swap n-v ]

Try it online!

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_

Try it online!

...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_

Try it online!

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

Haskell, 18 bytes

map=<<(-).(/4).sum

Attempt This Online!

Python, 32 bytes

lambda a:[sum(a)/4-x for x in a]

Attempt This Online!

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.