Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 8 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19(削除) 19 (削除ここまで) 17 bytes

×ばつ⍨-×ばつ(M←+×ばつM←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ⍨-×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) (削除) 19 (削除ここまで) 17 bytes

×ばつ⍨-×ばつM←+/÷≢

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

edited body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula formula

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

added 1288 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following, train-less function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL .

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following, train-less function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL.

Dyalog APL, (削除) 24 (削除ここまで) (削除) 23 (削除ここまで) (削除) 21 (削除ここまで) (削除) 20 (削除ここまで) 19 bytes

×ばつ(M←+/÷≢)

This defines an unnamed, monadic function train, which is equivalent to the following function.

{.5*⍨M(×ばつ⍨⍵)×ばつ(M←{(+/⍵)÷≢⍵})⍵}

Try them online on TryAPL .

How it works

The code consists of several trains.

M←+/÷≢

This defines a monadic 3-train (fork) M that executes +/ (sum of all elements) and (length) for the right argument, then applies ÷ (division) to the results, returning the arithmetic mean of the input.

×ばつM

This is another fork that applies M to the right argument, repeats this a second time, and applies ×ばつ (product) to the results, returning μ2.

×ばつ⍨-(×ばつM)

This is yet another fork that calculates the square of the arithmetic mean as explained before, applies ×ばつ (product with itself) to the right argument, and finally applies - (difference) to the results.

For input (x1, ..., xN), this function returns (x1 - μ2, ..., xN - μ2).

*∘.5∘M

This composed function is applies M to its right argument, then *∘.5. The latter uses right argument currying to apply map input a to a*0.5 (square root of a).

(*∘.5∘M)(×ばつ⍨-(×ばつM))

Finally, we have this monadic 2-train (atop), which applies the right function first, then the left to its result, calculating the standard deviation as follows.

formula

added 163 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 2 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 23 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
deleted 6 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading

AltStyle によって変換されたページ (->オリジナル) /