30
\$\begingroup\$

The mean of a population \$(x_1,\dots,x_n)\$ is defined as \$\bar x=\frac1n\sum_{i=1}^n x_i\$. The (uncorrected) standard deviation of the population is defined as \$\sqrt{\frac1n\sum (x_i-\bar x)^2}\$. It measures how dispersed the population is: a large standard deviation indicates that the values are far apart; a low standard deviation indicates that they are close. If all values are identical, the standard deviation is 0.

Write a program or function which takes as input a (non-empty) list of non-negative integers, and outputs its standard deviation. But check the scoring rule, as this is not code golf!

Input/Output

Input/Output is flexible. Your answer must be accurate to at least 2 decimal places (either rounding or truncating). The input is guaranteed to contain only integers between 0 and 255, and to not be empty.

Scoring

To compute your score, convert your code to integer code points (using ASCII or whatever code page is standard for your language) and compute the standard deviation. Your score is the number of bytes in your code multiplied by the standard deviation. Lower score is better. You should therefore aim for code which at the same time (a) is short and (b) uses characters with close codepoints.

Here is an online calculator to compute your score (assuming you use ASCII).

Test cases

Input              | Output
77 67 77 67        | 5
82                 | 0
73 73 73           | 0
83 116  97 116 115 | 13.336

A word of caution about built-ins: if your language has a built-in, that's fine (and good for you if it only uses one character!). But make sure that it uses \$n\$ and not \$n-1\$ as the denominator in the formula, or else your answer won't be valid.

\$\endgroup\$
  • 2
    \$\begingroup\$ I had wondered if it would be worth it adding extra filler characters to one's code reduce the score, but it looks like that never works. It can reduce the sdev, but the score of sdev*length always goes up. \$\endgroup\$ – xnor Aug 24 at 6:33
  • 2
    \$\begingroup\$ @mypronounismonicareinstate Yes, a solution in Lenguage or Unary will achieve a score of 0. As I wrote in the Sandbox: if somebody writes code to compute the standard deviation in Unary or Lenguage, they deserve my upvote! \$\endgroup\$ – Robin Ryder Aug 24 at 6:41
  • 6
    \$\begingroup\$ Related: Calculate Standard Deviation as pure code golf \$\endgroup\$ – xnor Aug 24 at 6:57
  • 2
    \$\begingroup\$ Lenguage score 0 anyone? \$\endgroup\$ – Jonathan Allan Aug 24 at 17:33
  • 2
    \$\begingroup\$ @JonathanAllan I'm trying, Might take a while though... \$\endgroup\$ – CShark Aug 27 at 20:00

17 Answers 17

10
\$\begingroup\$

MATL, score 65.30697

tYmhZs

Try it online! Or verify all test cases.

How it works

The built-in function Zs with its default arity (1 input, 1 output) computes the corrected standard deviation:

\$\sqrt{\frac 1 {n-1}\sum (x_i-\bar x)^2}\$

The uncorrected standard deviation can be obtained with the 2-input version of Zs: 1&Zs, where 1 as second input means uncorrected. l or T could be used instead of 1 to reduce the score, but & is very far from the other characters. 2$ or H$ could be used instead of &, but $ is even farther.

So it is better to use the default version of Zs (corrected standard deviation) on the input with its mean appended. This increases the input length by 1 and contributes 0 in the numerator, which causes the corrected standard deviation to become uncorrected.

t     % Implicit input: numeric vector. Duplicate
Ym    % Mean
h     % Concatenate the input vector with its mean
Zs    % Corrected standard deviation
| improve this answer | |
\$\endgroup\$
8
\$\begingroup\$

J, 19 bytes, Score 119.8249

-~1 thanks to Bubbler

Tries to have most characters between 0x23 and 0x2F #$%&'()*+,-./, with : being a bit further away.

(+/%$)&.:*:&(-+/%#)

Try it online!

How it works

(+/%$)&.:*:&(-+/%#)
            (-+/%#) x - sum divided by length
         *:&        and squared
(+/%$)&.:           mean of that
      &.:*:         reverse square -> square root
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ score 144 by avoiding @. \$\endgroup\$ – Bubbler Aug 24 at 8:00
  • \$\begingroup\$ @Bubbler expanding is surprisingly even better! Funny scoring system. \$\endgroup\$ – xash Aug 24 at 8:03
  • 1
    \$\begingroup\$ score 119.8 by changing the leftmost # to $. Input is required to be a vector in this case. \$\endgroup\$ – Bubbler Aug 25 at 0:14
6
\$\begingroup\$

Google Sheets, Score 142.6885

=STDEVP(F:F

Google Sheets automatically closes parentheses, and using F as the input column minimizes the standard deviation. This saves one byte over Excel's uncorrected standard deviation, since Excel uses STDEV.P instead of STDEVP

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Nice idea to input in the F column to reduce the standard deviation! \$\endgroup\$ – Robin Ryder Aug 24 at 8:38
4
\$\begingroup\$

R, 34 bytes 24 bytes, score 789.5923 723.4687 722.6112

sd(c(scan()->J,mean(J)))

Try it online!

Edit: switched to a shorter formula to calculate the population sd (which I found here), which now only benefits from selecting the best variable name among the golfs outlined below for the previous version.

Edit2: score reduced by 0.8575 thanks to Robin Ryder

The (previous) ungolfed code is was: x=scan();sqrt(mean((x-mean(x))^2)) (which would have a score of 1104.484)

From this, sequential score-improving golfs are:

  • x=scan();`?`=mean;sqrt(?(x-?x)^2) = re-define mean() as a single character unary operator (score 983.8933)
  • x=scan();`?`=mean;(?(x-?x)^2)^.5 = exchange sqrt() for ()^.5 (score 918.6686)
  • H=scan();`?`=mean;(?(H-?H)^2)^.5 = exchange x for H which is the closest codepoint value to the mean of the program, thereby reducing the standard deviation (score 801.4687)
  • I=scan();`?`=mean;I=I-?I;(?I^2)^.5 = first calculate x-mean(x) separately, to reduce number of parentheses (which are at the far end of the ASCII range, and so increase the standard deviation), and re-adjust the variable name to I. Although this increases the code length by 2 characters, it reduces the score to 789.5923.

R + multicon, 15 bytes, score 273.5032

multicon::popsd

Trivial solution using built-in popsd function from multicon library.
Not installed at TIO, but you can try it at rdrr.io by copy-pasting this code:

x=c(67,77,67,77)  # data
multicon::popsd(x)
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ scan()->J rather than J<-scan() should improve your score slightly. \$\endgroup\$ – Robin Ryder Aug 24 at 11:33
  • \$\begingroup\$ Doh! I had the ASCII table sitting right in front of me trying to optimize this: why on earth didn't I realise that? Thanks a lot! \$\endgroup\$ – Dominic van Essen Aug 24 at 11:35
  • \$\begingroup\$ For external packages, we usually require that your code either includes library(multicon) or that you call multicon::popsd, i.e. you cannot assume that the package is loaded when you start R). There was a short discussion about this in the golfr chatroom in July 2019. \$\endgroup\$ – Robin Ryder Aug 24 at 11:36
  • \$\begingroup\$ Ah. I somehow thought that it was also Ok to specify the language as 'R + multicon' (rather than simply 'R' which would require extra stuff to load the packages), but I can't remember why I thought so... \$\endgroup\$ – Dominic van Essen Aug 24 at 11:44
  • \$\begingroup\$ At some point in the past I thought the same as you, but eventually got convinced by the consensus position: the language is 'R + multicon' (since you have to install both), and then you have to explicitly load the external package. \$\endgroup\$ – Robin Ryder Aug 24 at 11:53
4
\$\begingroup\$

Wolfram Language (Mathematica), Score 537.0884

A@((#-A@#)^2)^.5&;A=Mean

Try it online!

@att saved 17.6142 points

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 537.0884 \$\endgroup\$ – att Aug 25 at 20:13
3
\$\begingroup\$

Python 3, Score 680.5175

Where the golfiest solution is not the best. I doubt any non-builtin could be better but I might be wrong.

import statistics;statistics.pstdev

Try it online!

Python 3, Score 733.6818

from statistics import*;pstdev

Python 3, Score 798.5587

__import__('statistics').pstdev
| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ @Dingus These are all function submissions. These are just different ways of referring to the same function, which is the library routine that does all of the required work. \$\endgroup\$ – Neil Aug 24 at 9:40
  • \$\begingroup\$ @Dingus Providing a function is enough, even if the function is not named \$\endgroup\$ – Luis Mendo Aug 24 at 10:10
  • 1
    \$\begingroup\$ @LuisMendo No problems with anonymous functions (I often use them myself). The confusion came because I don't recall having seen just a bare function before (I'm used to seeing things like (pseudocode) lambda s: stdev(s)). But looking at that pseudocode I can see that wrapping in a lambda is redundant here. It seems obvious now, but I've learnt something. \$\endgroup\$ – Dingus Aug 24 at 11:05
  • \$\begingroup\$ @Dingus Ah, I see what you mean. That also confused me back in the day \$\endgroup\$ – Luis Mendo Aug 24 at 12:02
  • 2
    \$\begingroup\$ @JonathanAllan There was a meta discussion on this, but it was a few years ago. \$\endgroup\$ – FryAmTheEggman Aug 24 at 17:54
3
\$\begingroup\$

05AB1E, Score: 531.168 431.516 360.278 (10 15 14 bytes)

Osg/nsn-Osg/(t

Uses the 05AB1E coding page. The characters used have the codepoints [79,73,103,47,110,73,110,45,68,79,73,103,47,40,116].

Try it online or verify all test cases.

Explanation:

                # Get the arithmetic mean of the (implicit) input-list by:
O               #  Summing the (implicit) input-list
 I              #  Push input-list again
  g             #  Pop and push its length
   /            #  Divide the sum by this length
                #  (which gives a better score than the builtin `ÅA`)
    n           # Square it
     I          # Push the input again (better score than `s` or `¹`)
      n         # Square each value in the input as well
       -        # Subtract each from the squared mean
                # Take the arithmetic mean of that list again by:
        O       #  Summing it
         Ig     #  Push the input-list again, and pop and push its length
           /    #  Divide the sum by this length
            (   # Negate it
             t  # And take its square-root
                # (after which the result is output implicitly)
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES7), Score  1359 1228  1156.077

Saved 72 points thanks to @edc65

D=>D[F='map'](C=>B-=(C+E/A)**2/A,D[F](C=>E+=--A?C:9,A=B=E=0))&&B**.5

Try it online!

Character breakdown

 char. | code | count
-------+------+-------
   0   |  48  |   1
   2   |  50  |   1
   5   |  53  |   1
   9   |  57  |   1
   &   |  38  |   2
   '   |  39  |   2
   (   |  40  |   3
   )   |  41  |   3
   *   |  42  |   4
   +   |  43  |   2
   ,   |  44  |   2
   -   |  45  |   3
   .   |  46  |   1
   /   |  47  |   2
   :   |  58  |   1   <-- mean ≈ 59.43
   =   |  61  |   9
   >   |  62  |   3
   ?   |  63  |   1
   A   |  65  |   4
   B   |  66  |   3
   C   |  67  |   4
   D   |  68  |   3
   E   |  69  |   3
   F   |  70  |   2
   [   |  91  |   2
   ]   |  93  |   2
   a   |  97  |   1
   m   | 109  |   1
   p   | 112  |   1
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Better pre calculating both sum and length, avoiding 1 'map' (in fact avoiding a couple of brackets): D=>D[F='map'](C=>B-=(C+E/A)**2/A,D[F](C=>E+=--A?C:9,A=B=E=0))&&B**.5 score 1156.077 \$\endgroup\$ – edc65 Aug 27 at 7:13
  • \$\begingroup\$ @edc65 That's a great improvement. Thanks! (And nice to see you around, btw.) \$\endgroup\$ – Arnauld Aug 28 at 15:17
3
\$\begingroup\$

Arn, score = 925.3172 655.6836 602.7985 123.2274

sdev:s

Uses the builtin standard deviation function. Go to the old answer for a more interesting one

Old Answer

I don't compress it because Standard Deviation would be way higher. I have updated this answer, since I found a much shorter method (sitting at 14 bytes). Link here (this is the program the score refers to). I will leave the original program for posterity's sake

:/(+v{:*v-(:s.mean}\)/((:s)#

Try it!

Explained

$$\large\sqrt {\frac1n \sum(x_i-\bar x)^2}$$ Just made use of the formula. :/ is the sqrt prefix, :* is the square prefix, +v{:*v-(:s.mean}\ Folds with + (addition) after mapping with the block v{:*v-(:s.mean}. v is current entry, :s splits on space (no variable is provided, so it assumes the variable _, which is STDIN). Then it just divides by the length (# suffix).

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Io, score = 1454.7164672196433912

-19.58295474318379 thanks to @ManishKundu

method(:,:map(Z,(Z- :average)squared)average sqrt)

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think you can save some score by using different variable names instead of I and J, perhaps Y and Z? \$\endgroup\$ – Manish Kundu Aug 24 at 11:49
2
\$\begingroup\$

Jelly, (14 bytes), score 218.314

(218.31399405443526)

+/÷LN+*2+/÷L*.

Try it online! Or see a self-evaluation.

Bytecode: 2b 2f 1c 4c 4e 2b 2a 32 2b 2f 1c 4c 2a 2e

How?

A naive program would be _Æm²Æm½for 348.47 (subtract the mean from each, square each, take the mean of that and then square root it).

We know that to get rid of the two byte monad Æm whose code-points are quite far apart (0x0d and 0x6d) we need to either:

  • divide using ÷ (0x1c), or
  • multiply, × (0x11), and invert, İ (0xc6)

But the latter bytes are also fairly far apart, so this answer attempts to use bytes close to ÷ (0x1c).

+/÷LN+*2+/÷L*. - Link: list of numbers, A
 /             - reduce (A) by:
+              -   addition             -> sum(A)
   L           - length (A)
  ÷            - divide                 -> mean(A)
    N          - negate
     +         - add (to A, vectorised) -> [mean(A)-v for v in A]
       2       - two
      *        - exponentiate           -> [(mean(A)-v)² for v in A]
         /     - reduce by:
        +      -   addition             -> sum((mean(A)-v)² for v in A)
           L   - length (A)
          ÷    - divide                 -> sum((mean(A)-v)² for v in A)/n
             . - a half
            *  - exponentiate           -> √(sum((mean(A)-v)² for v in A)/n)
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Wolfram Language (Mathematica), 31 bytes, score 478.3451

a[a_]=RootMeanSquare[a-Mean[a]]

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 15 bytes, stddev 46.741654, score 701.12481

I₂∕ΣX⁻θ∕ΣθLθ²Lθ

Try it online! Link is to verbose version of code. Link test case is the byte values in the Charcoal code page of the code. Explanation:

         θ      Input `x`
        Σ       Summed
       ∕  Lθ    Divided by `n`
     ⁻θ         Vectorised subtracted from `x`
    X       ²   Squared
   Σ            Summed
  ∕          Lθ Divided by `n`
 ₂              Square rooted
I               Cast to string
                Implicitly printed

Note that the alternative formula for the standard deviation, \$ \sqrt{\bar{x^2}-\bar x^2} \$, while having a slightly smaller standard deviation, takes 17 bytes, and therefore results in a higher score of 755.6.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Setanta, score: 2728.508

gniomh(g){f:=0h:=0e:=fad@g le i idir(0,e){d:=g[i]f+=d h+=d*d}toradh freamh@mata((h-f*f/e)/e)}

Try it here!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 107 104 99 bytes, stddev 25.25 \$\cdots\$25.32 25.00, score 2702.01 \$\cdots\$ 2634.27 2475.426270

Saved 3 bytes and 46.95288 points thanks to ceilingcat!!!
Saved 5 bytes and 158.848632 points thanks to att!!!

E;float D,G,H;float F(F,C)int*C;{E=F;for(H=G=0;E>-F;0>E?G+=D*D:(H+=*C++))D=H/F-C[--E];G=sqrt(G/F);}

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 2475.426 \$\endgroup\$ – att Aug 26 at 20:42
  • \$\begingroup\$ @att Fantastic - thanks! :D \$\endgroup\$ – Noodle9 Aug 26 at 21:24
1
\$\begingroup\$

Lenguage, A lot of bytes, Score 0

Disclaimer: might still have bugs (currently has; b/=2 in the sqrt routine is broken)

Input: n as an ASCII-Character, then n Numbers also converted to ASCII

Output: 8 ASCII Characters, denoting a 32bit fixed point value with the decimal point between bit 15 and 16 (just interpret the 8 ASCII characters as an 32bit integer and divide by 1<<16 to get the answer)

Runtime: Honestly I didn't test the test values. It just takes way too long. I checked the first part until the square root and all the test cases work as intended, altough the runtime already is more than one hour. The sqrt was tested independently on very small numbers and still takes roughly 10 Minutes just for a square root of 9. So the total runtime is probably multiple hours...

4823022650272295266061801083527686126511909253900883549562726674269648714246325395757631028181730526680657165914975984649202998561789835690475144426297425287052242908793367211355899620936044817632765852594675066416978263132334253102088328253598740794855275751697086748479214633924687449949785644058005142341802759099447153857058592786759741204974940357242202983078863520983936102525682225931849081509795173043125338056407377823125567264136032760023897277394436223725685979175418840109424839709232310537430621283725057852839903942606820253307868340366064547751094005996330078959042731424747886732759740492257346508960210461875186912686396496291949158119672229575059601081416614823699927292905404699003495622180401107665979433065350239280491341201595292211040905750988215585533394980861571010947562272979212436380156878677555358107455702913842172057768926024565632904709145511876985927207328391419002406164023906522535504872920588293236037829238279855163765062614037427725635531833680276971688910060636831243737793267285490457681359419785222248021122765438579406489768152299757254662717053448526205691929991630457275991283379172296158591451720428058112273395671283283887343174696833365443779975384365586666934952432369741651283785833580434683594187798324312344263459284320436515815667727616498971087112872880455288174427939328679718528009727741005542540451195805239805890651408292198621684263883914001328692875683695361815821586702391559723284234585582696652698230265858165367351391055239625742208033954813584402702275079034416010629831147059667912835233782975186202183172200171589279875587916169521970329193946050030887947824067997495484239491935981059240706443498545729150286102654089272933466279075939638665793963907868892183791055151572584417358946269338790269362746018719966933277536937726360820837929120686350766027200302993650713697842160583571259200787300473521490808392855608356769006915688963926328475504167352710933344988418684147754670441674518211315333761819824573155081046679613566071467014250503476682602794881488418394078886760385734728076061823268397990474596773647756928884456341088525679713730005279703884947183820385164918461956476229197934775764636056192528034422000069690600392626402145901444160367410125796050114518434522388283418533688581214930601092010848177221906725784859139300214122353120179122669787172062222699955862899637766553249665997156759755554480125096779395108885652446397064927574339494070866590815826380555814714453226531530059674887918334561671831003648778836708277903685353220117154794037852297716677701767284898358605874459653226147044262391211624008793612330865443879651475900297951630694184955796886047985322478119913893371813145685317630532548765234272410962471129586746431266831492208317716268255955841270999646550653635242110617974743609494543344277685778546582069527004431458060633666538521061682992753338610440883113444072070159988241043170568090473348353254681238630292156163688986700649992459803845420943633357026767376816476378655139274948274674062798931982102391523335182078356916290631266795567529972647771429671234368668297829476854087332878384596647872873624018787557204509539855702010381318207515108468165167218140676866381588319249373769971268093327074380927445028157357360299882417511664474416396189772662206413891745181304720310529405179485890105586437471805314779146136214510888209606261897953280652607480038311727247920358923558216360076803341044253962174184425464197063558698976241595449183825326496705603694436435758444428488634671822569466212393019715403784767035890140826128303696111620803193770919465313656582642983637596539422984429656802262498024297867046311481184375560601711556278739038829111442140317094427050139671479447921633966732762543814861391239685333145924539196005760782428345132327022297032930234943780865185976481213601805015830257298053297033622595100022800528267772133835343930581744085165747367779301509372041200911913657823308445172009869392057989955465226007286138957057579735142677651090799118194029301042928423453219941930174801291249111739171578706296118116656199273072265494090017717233300951995193519360540407311904257173137244349431398080852910409808896086175455497066511164002626211891551688440915436609394483204283152544086204136470338334156647778220970666537185282941689015688931362525206317792055978667130488216229929383058642072796762924920883608765489799338978005959072350706044841831654791341880270814994917385798051126139020012848162319309380640764373984057411475421473009623604153933455470662724925970235512724020976760867899803559071155252940522450177725301174816045857132712901562106402444171106940316168402828963584142473058494944074181479927873771659597543696217547142329461214778672549717211501312718296437161581573515656541984447698861721508802448973507860785135827599448933466141052981435860438223533376511116904954039522972467094960654497071993967468580802204139223521537211222409054107698889774370180041601961841119515147782810802540931672635294187934315449856161866348156532703366288723250955857909936226443546375598709520781438057189622718640332664143116633481016432448200017604322116166975112543505352792319158494772685568733880559367477441500973902381899207653275406335258518716037813519156535303295642658702788760183334444614494113770117303312762820353939438769086692318176056728489807813789337737795805062202546956286490824239503455413798982927718243815298548315692444941296415661835063845769674769405978931437496279030205101463418484764289282797446517429541037199364761081325195748988024595609084990116612596956995080860754022285517463422860642640341416454605106962149281231307966535083297340730917045953052799774202136101921041240139587496845672362583280569374188126258035999365581793377262040557419799385985065804138046188785618293155990376989072179676504665903305397099522425058275154250224730851523465247450449764736540902695255017027094814718006282541437290656299314646092964430646168332844903564452567379993118370038517891181029598070820189673911636065674688922622854529826547394468803373016153558726074219239967746734152741944535809187725379075592960289849491243044910460356053553679892325305690575332396988906513336596596086091814421920095603822861772550723102367029412616412540055980260801020392532662709838644371570466743387991700101077528553177816307257917001467610642528475524318964875795610631540003742185137620304389270191109021378670424859133613414545647257585237292560556013286211718882278253829276953933317947698914481609919112230104556632406701352295335098296633093988266631470073505587642147379072510893381714508952176280362569468610727684323641471901310980721380597892116573881013413918255290317378578141780052997201105657085764166755275857072058320227440169002384096999750058241859610403530146669632877513406578610590673548649160656529150260929012373831756483218041790508413457355287443185900787700199444048531735148777558791024072412523440367723623818588101817472406377472950039041947343055537880594847463160328759187236891680320791565275119489834756997051597790163153998578395358794392468881026554467195792452486397206855356354128708107224016275794218552239953278218753515757021425950154873399445295256268165888529654686866818324

of any character. Thats \$ 10^{7168} \$ Bytes, which would require \$ 10^{7078} \$ Observable Universes or \$ 10^{7091} \$ solar-mass black holes just to contain the data. The "code" was converted from brainfuck

,[->>>>>>>>>>+>+<<<<<<<<<<<]>>>>>>>>>>[-<<<<<<<<<<,[->+>+<<]>[-<+>]>[->>>>+>+>+<<[>-]>[-<]>>[>]<[<<<
+>>+><<<[>>-<]>>[-<]>>[>]<[<<<<+>>>>+><<<<<[>>>-<]>>[-<]>>[>]<[-<<<<<+>>>>->]]]<<<<<<]>>>>>>>>>[->+<
]<[->+<]<<<<[->+<]<[->+<]<[->+<]<[->+<]>>>>>>>>]>[->>+<<]>>>>++++++[-<<<+<<<<<<<<<[[->>>>>>+<<<<<<]>
>>>>>>>>-<<<<<<<<<]>>>>>>>>>[-<<<<[->>>>+<<<]>>>[-<<<->>>>-<+<<+>>>[<-]<[->+<<<-<<<<<<<+>>>>>>>>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->>>>+<<<]>>>[-<<<->+>>+>-[<-]<[
->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]<<]>[-<<+>>>>>+<<<]>>>>>[->+<]<<[->+<]<<<<<[->+<]>>>>>>>>]<<[-]<<<[
-]<<[-]<<<<<<<<<<<<<<<<<.>.>.>.>.>.>.>.

which clocks in with about ~8000 Instructions. It was my first time actually using Brainf*ck and it took a while to see that its basically a turing machine but then my computer science degree finally paid off :D In the beginning there is a lot of trial and error going on, especially for the mean. But then it clicked and I started building state machines to do all the calculation. Here are some of the state machines I used:

Some state machines

It was all fun and games until I hit the square root; I though it would be a smaller part but it ended up getting most of the code. I adopted an algorithm by Christophe Meesen and changed some constraints to make it play nice in brainf*ck.

Development was done in VSCode for syntax highlighting and Visual Brainf*ck for Debugging

Here is code with some comments:

,                       // Read how many input terms we will get       {n_}
[                       // Copy value twice                            {0; 0; 0; 0; 0; 0; 0; 0; 0; 0; n_; n}          
    ->>>>>>>>>>+>+
    <<<<<<<<<<<
]>>>>>>>>>>

[                       // Check if n≫0 and read n values & calculate their sum
    -<<<<<<<<<<,        // read xi; decrement running counter           {xi_; 0; 0; 0; 0; 0; 0; 0; 0; 0; n—i; n}
    [->+>+<<]           // copy xi twice                                {0_; xi; xi; 0; 0; 0; 0; 0; 0; 0; n—i; n}
    >[-<+>]             // move first xi back                           {xi; 0_; xi; 0; 0; 0; 0; 0; 0; 0; n—i; n}
    >[                  // add byte to 32bit integer sum                {•; •; xi; sum{4}; sum{3}; sum{2}; sum{1}; loopbreak; carry; 0; •; •}
        ->>>>+>+>+              // add number
        <<[>-]>[-<]>>[>]<       // set(clear) carry flag for 1st byte
        [<<<+>>+>               // apply carry flag
        <<<[>>-<]>>[-<]>>[>]<   // set(clear) carry flag for 2nd byte
        [<<<<+>>>>+>            // apply carry flag
        <<<<<[>>>-<]>>[-<]>>[>]<// set(clear) carry flag for 3rd byte
        [-<<<<<+>>>>->]         // apply carry and clear all flags
        ]
        ]                       // works by trial and error; no idea how it works exactly but it passes all tests;;;
        <<<<<<
    ]                   //                                              {xi; 0; 0_; sum{4}; sum{3}; sum{2}; sum{1}; 0; 0; n—i; n}
    >>>>>>>>>
    [->+<]              // move n one right
    <[->+<]             // move n—i one right
    <<<
    <[->+<]             // move sum one right
    <[->+<]
    <[->+<]
    <[->+<]
    >>>>>>>>
]                       // now we have {x0; •••; xi; 0; 0; 0; sum{4}; sum{3}; sum{2}; sum{1}; 0; 0; 0; 0_ ; n}
// move data for Divisionmodule
>[->>+<<]
>>>>++++++

//In—Place Divisionmodule 4 src bytes {(x1); x2; x3; x4; 0; carry; temp; rem; q; flag; n; 0; bytes_}
[
    -<<<                  Decrement bytecount
    +<<<<<<<<<            Set copyflag
    [[->>>>>>+<<<<<<]     Copy Value
        >>>>>>>>>-<<<<<<<<<]  Clear copyflag
    >>>>>>>>>
    [-<<<<[->>>>+<<<]>>>[-<<<->>>   Apply carry if no copy
        >-<+<<+>                        Adjust n & remainder
        >>[<-]<[->+<<<-<<<<<<<+>>>>>>>>]if n=0; inc Q on target 
        ]>              
    ]
    <<<
    [[                    Div_
            ->+>>+>-[<-]>[>]<     Remainder
            <[-<+<[->>>+<<<]>>]   Overflow to Q
            <<<
        ]
        >>[-<<<<<<<<+>>>>>>>>] Copy back
        <<<[->>>>+<<<]>>>[-<<<-Check Carry
            >+>>+>-                Adjust n & Remainder
            [<-]<[->+<<<-<<<<<<<+>>>>>>>>] if n=0; inc Q on target
        ]                       Q_
        <<
    ]
    >[-<<+>>>>>+<<<]       Copy Remainder to Carry & n
    >>>>>[->+<]            Move Acc
    <<[->+<]
    <<<<<[->+<]
    >>>>>>>>
]<<
// Div end {x1; x2; x3; x4; d1; d2; 0; 0; 0; 0; 0; carry; 0; rem; 0; 0; n_}
// mean is guaranteed to be max 3 bytes long (math)
// we now have: inputs x1•••xi; n; mean x

// Prepare state machine for derivation sum
// {xi; 0; 0; 0; 0; (m4)0; (m3)0; (m2)0; m1; mD1; mD2; 0; 0; 0; 0; 0; c; 0; r; 0; 0; n_} to
// {xi; 0{28}; n—i; n_; m1; mD1; mD2; sum1; sum2; sum3; sum4; sumD1; sumD2; sumD3; sumD4}
<<<[-]<<[-]>>>>>                                // clear carry & rem
[->>>>>>>>>>>>+>+<<<<<<<<<<<<<]                 // move n & mean
<<<<<<<<<<<[->>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<<<]
<[->>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<<<]
<[->>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<<<]
>>>>>>>>>>>>>>>>>>>>>>>>> n—i

// state machine layout:
// {xi/o1; o2; o3; o4; o5; o6; o7; o8;
        {0; 0; 0;
            {0; 0; 0; add_tmp; carry_flag; 0; add; mul; mul_backup; carry; bytes_add(3)}
        (xi—xm)1; xim2; xim3; 0; bytes_mul(3)}
    0; xim1; xim2; xim3; 0; n—i_; n; m1; mD1; mD2; •••}
[-
    >>[-<<<+<<<+<<<<<<+>>>>>>>>>>>>]         // copy medain m1•mD2 to xim1•xim3
    <<<[->>>+<<<]
    >>>>[-<<<<+<<+<<<<<<+>>>>>>>>>>>>]
    <<<<[->>>>+<<<<]
    >>>>>[-<<<<<+<+<<<<<<+>>>>>>>>>>>>]
    <<<<<[->>>>>+<<<<<]
    <<< xim1(2nd)
        
    // xi — mean {xi; 0; f; sum; •••}; first count down: then up
    [-<<<<<<-<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>]
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<[>>+>[-<-<<->>]<[-<<[->>>+<<<]>]<]
    >>>[->>>>>>>>>>>>>>>>>>>+>>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<]
    >>>>>>>>>>>>>>>>>>>>>>>>> xim1(2nd)

    // pow multiplicator
    <<+++             // setup mul byte counter (3)
    [-  // multiplication byte loop
        // setup mul count & copy active byte
        <<<<<+++
        >>>>>>>>>[-<<<<<+<<<<<<+>>>>>>>>>>>]
        <<<<<[->>>>>+<<<<<]
        <<<< bytes_add 
        [-  // add byte loop
            <[-<<<<<<+>>>>>>]       // process carry
            <[-<+>]                 // setup counter
            <<<<<<<<<<<<[->>>>>>>+<<<<<<<] // copy target byte to temp
            >>>>>>>>>>> mul
            [-  // add multiplier loop
                >+>>>>>[-<<<<<<<+>>>>>>>]            // copy source byte to temp
                <<<<<<< add
                [- // add adder loop
                    >>>>>>>+        // restore source byte
                    <<<<<<<<<+      // set carry flag
                    <+              // add number
                    [>-]>[>]<       // clear carry flag
                    [->>>>>+<<<<<]  // apply carry if flag
                    >>
                ]>
            ]
            <<<<[-<<<<<<<+>>>>>>>]    // restore target byte from temp
            >>>>>[-<+>]>[-<+>]>[-<+>] // move substatemachine to next byte
            <
        ]
        <[-<<<<<<<<<<<+>>>>>>>>>>>]   // apply remaining carry
        <[-]
        >>>>>>[-<+>]>[-<+>]>[-<+>]>>[-<+>]     // move statemachine to next byte
        <
    ]
    <<[-]<[-]<[-]>>>>>>>>>[-]>[-]>[-] b3       // delete statemachine
    
    //In—Place Divisionmodule 8 src bytes {(x1); x2; x3; x4; d1; d2; d3; d4; 0; carry; temp; rem; q; flag; n; 0; bytes_}
    >>>[-<<+<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>]  // copy n
    <<[->>+<<]                                      // restore n
    <<<<<<<<<<<<<<<++++++++                         // set bytecount
    // same as before; just for 8 src bytes
    [-<<<+<<<<<<<<<<<<<[[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>-<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<[->>>>+<<<]>>>[-<<<->>>>-<+<<+>>>[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]>]<<<[[->+>>+>-[<-]>[>]<<[-<+<[->>>+<<<]>>]<<<]>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<[->>>>+<<<]>>>[-<<<->+>>+>-[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]<<]>[-<<+>>>>>+<<<]>>>>>[->+<]<<[->+<]<<<<<[->+<]>>>>>>>>]<<

    [-]<<<[-]<<[-]      // clear n; rem & carry
    <<<<<<<<++++++++      // move data for easy add
    // {s1; s2; s3; s4; d1; d2; d3; d4; 0; 8_; 0{22}; n—i; n; m1; mD1; mD2; sum1; sum2; sum3; sum4; sumD1; sumD2; sumD3; sumD4} to
    // {•••n—i; n; mD1—mD3; sum1—sumD4; 0{17}; s1—d4}
    [-
    <<[->>>>>>
    >>>>>>>>>>
    >>>>>>>>>> n
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>+    new d4
    <<<<<<
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<< n
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<]
    >>[-<+>]<
    ]
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>
    >> n
    
    // 32bit adding state machine
    // {s1•••s8; 0{8}; 0; add≪; carry flag; 0; add≫; carry; 0; bytes_; 0; s1•••s8}
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>++++++++
    [-
        <<<<<<<<<<
        <<<<<< s8≪
        [->>>>>>>>>>+<<<<<<<<<<]
        >>>>>>>>>>>>>> carry [-<+>]< add≫
        [-<<+<+[>-]>[>]<[->>>+<<<]>>]
        >>>>>>>>>>>> s8≫
        [-<<<<<<<<<<<<+>>>>>>>>>>>>]
        <<<<<<<<<<<<
        [-<<+<+[>-]>[>]<[->>>+<<<]>>]
        <<< add≪
        [-<<<<<<<<<<+>>>>>>>>>>]
        >>>>[-<+>]>>[-<+>]<
    ]<<<<<<<<<<<<<<<
    <<<<< n—i

    // move to next input number 
    [-<+>]>[-<+>]>[-<+>]>[-<+>]>[-<+>]
    >[-<+>]>[-<+>]>[-<+>]>[-<+>]>[-<+>]>[-<+>]>[-<+>]>[-<+>]
    <<<<<<<<<<<<
]
>[-]>[-]>[-]>[-]    // clear mean & n
>


// Square root algorithm; adopted from github com/chmike/fpsqrt ≫ sqrtF2F
// changes: b check is bound to 0 instead of 0x40 because easier
//      — q≫=8 changed to q≫=6 because otherwise the decimal point shifts two places
// { r(8)_; b(8); 0; loopflag; temp; 0; q(8); t(8); state machines}
>>>>>>>> b(0)
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++ 0x40 = 64
>>>>>>>>>+
[[-]
<<<<<<<<<    // while b≫0
1 [->>>>>>>>>>+<<<<<<<<<<]
>>>>>>>>>>[<<+>]>[>]<
[-<<<<<<<<<<+>>>>>>>>>>]
2 <<<<<<<<<[->>>>>>>>>+<<<<<<<<<]
>>>>>>>>>[<<+>]>[>]<
[-<<<<<<<<<+>>>>>>>>>]
3 <<<<<<<<[->>>>>>>>+<<<<<<<<]
>>>>>>>>[<<+>]>[>]<
[-<<<<<<<<+>>>>>>>>]
4 <<<<<<<[->>>>>>>+<<<<<<<]
>>>>>>>[<<+>]>[>]<
[-<<<<<<<+>>>>>>>]
5 <<<<<<[->>>>>>+<<<<<<]
>>>>>>[<<+>]>[>]<
[-<<<<<<+>>>>>>]
6 <<<<<[->>>>>+<<<<<]
>>>>>[<<+>]>[>]<
[-<<<<<+>>>>>]
7 <<<<[->>>>+<<<<]
>>>>[<<+>]>[>]<
[-<<<<+>>>>]
8 <<<[->>>+<<<]
>>>[<<+>]>[>]<
[-<<<+>>>]>> q(0)

>>>>>>>>[-]>[-]>[-]++++++++ t(2)   // t = q
[-
    <<<<<<<<<<[->>>>>>>>+>+<<<<<<<<<]
    >>>>>>>>>[-<<<<<<<<<+>>>>>>>>>]
    >[->+<]>
] t(7)⊕3

++++++++    // t ⊕= b
[-
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<   b(n)
    [->>>>>>>>>>
    >>>>>>>>>> t(n)
    >>>>>>>>>+>
    >>>>>>>>>>
    >>>>>+<<<<<
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<]
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>
    [-<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<+
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>]
    >
    [->+<]>
] t(7)⊕4
>>>>>++++++++
// 8 bit adder; exits on t(0)
[-<<<<<<<<<<<<<<<<[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>>[-<+>]<[-<<+<+[>-]>[>]<[->>>+<<<]>>]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<[-<<+<+[>-]>[>]<[->>>+<<<]>>]<<<[-<<<<<<<<<<+>>>>>>>>>>]>>>>[-<+>]>>[-<+>]<]<<<<<<<<<<<<<<<
✔

// r ≫= t (t ≪ r)
>>>>>>>>>++++++++ t(7)⊕2
[-
<<<<<<<<<<
<<<<<<<<<<
<<<<<<<<<<
<<<<<<< r(n)
[->>>>>>>>
>>>>>>>>>>
>>>>>>>>>> t(n)
>>>>>>>>+>>
>>>>>>>>
>>>>>>>>+
<<<<<<<<
<<<<<<<<
<<<<<<<<<< t(n)
<<<<<<<<<<
<<<<<<<<<<
<<<<<<<<]
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>[-<<<<<<
<<<<<<<<<<
<<<<<<<<<<
<<<<<<<<<<+
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>]>[->+<]>]
++++++++
<+>
// 8 bit compare ≪
// {s1•••s8;0; temp/≪ = 0; byte≪; byte≫; ≫ = 0; 0; ≪ is less; exit comp temp; exit compare; bytes_; 0(8); r1•••r8}
[-<[-<+>
    <<<<<<<<<<<<<<<<[->>>>>>>>>+>+<<<<<<<<<<] // copy s(n)
    >>>>>>>>>[-<<<<<<<<<+>>>>>>>>>]           // restore s(n)
    >>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>] // copy r(n)
    <<<<<<<<<<<<<<<
    <+>
    [-
        >+<[>-]>[>]<<       // set »=0 on 0 in byte»
        <<+>-[<-]<[<]>      // set «=0 on 0 in byte«
        [>>>[-<[-]<[-]<[-]>>>>>+>-<<<]<<<[->>>>>+>-<<<[-]<[-]<<]]
        >>>[-<[-]<[-]>>]<<+>
    ]<-[->>>>>[-]<<<<<]>
    >>>>>]
    <[->+<]>>[->+<]<[->+<]<<[->+<]>>>>
]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<[-]<<
[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<
// t(7) ⊕ 3
// if t ≪ r
[-<<<<<<<<<< t(0)
    // q = t ⊕ b
    <<<<<<<<[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>
    >>>>>>>>>>++++++++ t(7)⊕3
    [-<<<<<<<<<<[->>>>>>>>+>+<<<<<<<<<]
    >>>>>>>>>[-<<<<<<<<<+>>>>>>>>>]>[->+<]>]

    ++++++++[-
        <<<<<<<<<< t'(n)
        <<<<<<<< t(n)
        <<<<<<<<<<
        <<<<<<<<<< b(n)
        [-
            >>>>>>>>>>>>+ q(n)
            >>>>>>>> t(n)
            >>>>>>>> t'(n)
            >>>>>>>>>>
            >>>>>>>>>>
            >>>>>+<<<<<
            <<<<<<<<<<
            <<<<<<<<<<
            <<<<<<<<
            <<<<<<<<
            <<<<<<<<<<<<  
        ]
        >>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]
        >>>>>>>> t(n)
        >>>>>>>> t'(n)
        >>>>>>>>>> [->+<]>        
    ]
    >>>>>++++++++
    // 8 bit adder; exits on t'(0) = new q (q')
    [-<<<<<<<<<<<<<<<<[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>>[-<+>]<[-<<+<+[>-]>[>]<[->>>+<<<]>>]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<[-<<+<+[>-]>[>]<[->>>+<<<]>>]<<<[-<<<<<<<<<<+>>>>>>>>>>]>>>>[-<+>]>>[-<+>]<]<<<<<<<<<<<<<<<
    // move q' to q
    >>>>>>>>++++++++[-<<<<<<<<[-<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>]>>>>>>>>[-<+>]<]<<<<<<<< t(0)
    // r —= t copy t to second add reg
    >>>>>>>>>>++++++++ t(7)⊕2
    [-<<<<<<<<<<[-
        >>>>>>>> a(n)
        >>>>>>>>>>
        >>>>>>>>>>
        >>>>>> b(n⊕1)
    ]>>>>>>>>>>[->+<]>]>>>>>>>> b(1)
    [-<->]>[-<->]>[-<->]>[-<->]>[-<->]>[-<->]>[-<->]>[-<->]<<<<<<<< // build inverse
    <<<<<<<<<<<<<<<<<<<<<<<<< a(0)
    >++++++++[-
        <<<<<<<<<<
        <<<<<<<<<<
        <<<<<<<<<<
        <<<<<<<[-
            >>>>>>>>>>
            >>>>>>>>>>
            >>>>>>>>>>
            >>>>>>+<<<<<<
            <<<<<<<<<<
            <<<<<<<<<<
            <<<<<<<<<<
        ]>>>>>>>
        >>>>>>>>>>
        >>>>>>>>>>
        >>>>>>>>>>[->+<]>
    ]>>>>>>>>>>>>>>>++++++++
    // 8 bit adder; exits on bitcounter
    [-<<<<<<<<<<<<<<<<[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>>[-<+>]<[-<<+<+[>-]>[>]<[->>>+<<<]>>]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<[-<<+<+[>-]>[>]<[->>>+<<<]>>]<<<[-<<<<<<<<<<+>>>>>>>>>>]>>>>[-<+>]>>[-<+>]<]
    >>>>>>>>>+<<<<<<<<<++++++++ add missing 1 from inverse
    // 8 bit adder; exits on a(0) = r'(0) = t(7) ⊕ 1
    [-<<<<<<<<<<<<<<<<[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>>[-<+>]<[-<<+<+[>-]>[>]<[->>>+<<<]>>]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<[-<<+<+[>-]>[>]<[->>>+<<<]>>]<<<[-<<<<<<<<<<+>>>>>>>>>>]>>>>[-<+>]>>[-<+>]<]<<<<<<<<<<<<<<<
    >>>>>>>>++++++++ move r' ≫ r
    [-<[-
        <<<<<<<< t(n)
        <<<<<<<< q(n)
        <<<<<<<<<<<< b(n)
        <<<<<<<<+>>>>>>>>
        >>>>>>>>>>>>
        >>>>>>>>
        >>>>>>>>
    ]>[-<+>]<]<<<<<<< t(0)
>>>>>>>>>>] // endif t ≪ r
<<<<<<<<<< t(0)

// r = r ⊕ r
>>>>>>>>>>++++++++
[-
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<[-
        >>>>>>>>>>
        >>>>>>>>>>
        >>>>>>>>>>
        >>>>>>+>>>>>
        >>>>>>>>>>
        >>>>>>>>>>+
        <<<<<<<<<<
        <<<<<<<<<<
        <<<<< <<<<<<
        <<<<<<<<<<
        <<<<<<<<<<
        <<<<<<<<<<
    ]>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>[->+<]>
]
>>>>>>>>>>>>>++++++++
// 8 bit adder; exits on r'(0)
[-<<<<<<<<<<<<<<<<[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>>[-<+>]<[-<<+<+[>-]>[>]<[->>>+<<<]>>]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<<<<<<<<<<[-<<+<+[>-]>[>]<[->>>+<<<]>>]<<<[-<<<<<<<<<<+>>>>>>>>>>]>>>>[-<+>]>>[-<+>]<]<<<<<<<<<<<<<<<
>>>>>>>>++++++++[-<[-
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<+>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>
]>[-<+>]<]<<<<<<< t(0)

// b /= 2
>>>>>>>>>++++++++[-
    <<<<<<<<<<
    <<<<<<<<<<
    <<<<<<<<<[-
        >>>>>>>>>>
        >>>>>>>>>>
        >>>>>>>>+<<<<<<<<
        <<<<<<<<<<
        <<<<<<<<<<
    ]>>>>>>>>>
    >>>>>>>>>>
    >>>>>>>>>>[->+<]>
]>>>>++>>++++++++
// in place div
[-<<<+<<<<<<<<<<<<<[[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>-<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<[->>>>+<<<]>>>[-<<<->>>>-<+<<+>>>[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]>]<<<[[->+>>+>-[<-]>[>]<<[-<+<[->>>+<<<]>>]<<<]>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<[->>>>+<<<]>>>[-<<<->+>>+>-[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]<<]>[-<<+>>>>>+<<<]>>>>>[->+<]<<[->+<]<<<<<[->+<]>>>>>>>>]<<
[-]<<<[-]<<[-]<<<<<<<<<++++++++
[-<[-
    <<<<<<<< t(n)
    <<<<<<<< q(n)
    <<<<<<<<<<<<+ b(n)
    >>>>>>>>>>>>
    >>>>>>>>
    >>>>>>>>
]>[-<+>]<]<<<<<<<< t(0)
<<<<<<<<<<<
] // next iteration

// q ≫ 6 = q / 64
>>>> q(0) >>>>>>>> t(0) [-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++
>>++++++++
[-<<<+<<<<<<<<<<<<<[[->>>>>>>>>>+<<<<<<<<<<]>>>>>>>>>>>>>-<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<[->>>>+<<<]>>>[-<<<->>>>-<+<<+>>>[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]>]<<<[[->+>>+>-[<-]>[>]<<[-<+<[->>>+<<<]>>]<<<]>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<<[->>>>+<<<]>>>[-<<<->+>>+>-[<-]<[->+<<<-<<<<<<<<<<<+>>>>>>>>>>>>]]<<]>[-<<+>>>>>+<<<]>>>>>[->+<]<<[->+<]<<<<<[->+<]>>>>>>>>]<<
[-]<<<[-]<<[-]<<<<<<<<<<<<<<<<<.>.>.>.>.>.>.>.
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The code still has a bug but I decided to post it anyway as I don't know when I'll come around to fix that one. But up until the sqrt routine everything is tested and working correctly. \$\endgroup\$ – CShark Aug 30 at 20:52
  • \$\begingroup\$ Welcome to CGCC! Nice attempt, I look forward to you fixing the bug. You could also include a link to the BF version on tio.run, so that people can test it. \$\endgroup\$ – Robin Ryder Sep 1 at 6:48
1
\$\begingroup\$

MATLAB/Octave, 12 bytes, score 336.32

(changed according to guidance by Giuseppe to conform with rules)

@(A)std(A,1)

Argument with name A provides the lowest deviation for score, output to standard output variable Ans and actually written to command window.
Try it online!

std is a built-in function. By default it uses \$N-1\$ as demoninator but by passing 1 as second argument it's changed to \$N\$.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I believe you need a way of inputting the variable itself, so this needs to be a full program taking input through input or else as a function handle, e.g., @(H)std(H,1). Taking input as a predefined variable isn't really allowed any longer. \$\endgroup\$ – Giuseppe Sep 25 at 14:59
  • \$\begingroup\$ @Giuseppe I would argue that MATLAB scripts just work in the way you can put some data into workspace before running the actual script. IMHO it's just another way of passing arguments, in rules it's said that input/output is flexible and I'm not pulling the answer from variables, only the inputs. But I'm new here and I might not know all the subtle rules, I'm sorry. I changed the answer, but I'd like to point out @(H)std(H,1) still doesn't technically allow inputting anything if you don't save it to a variable. \$\endgroup\$ – elementiro Sep 25 at 18:14
  • 1
    \$\begingroup\$ No worries, I can see your rep and the "New contributor" tag on your profile, so I know the arcane rules of Code Golf are probably new to you. This is the relevant community consensus. Note that anonymous functions (i.e., function handles) are perfectly fine--see for instance this for a MATLAB example. \$\endgroup\$ – Giuseppe Sep 25 at 20:11
  • \$\begingroup\$ If you have any doubts, feel free to go to the CGCC general chatroom as they can probably point you to any weird rules better than I can (I still don't know some of the rules, I'm sure). And if you're feeling up to it, as a fellow MATLAB/Octave golfer, MATL is a stack-based golfing language based on MATLAB that's pretty powerful and enjoyable to golf in. \$\endgroup\$ – Giuseppe Sep 25 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.