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 74 characters in body
Source Link

Jelly, 87 bytes

ḊṖ$Ƭ-ịÆmJÆṁị1Æm

Try it online! Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.

How it works

ḊṖ$Ƭ-ịÆmJÆṁị1Æm - Main link. Takes a string S on the left
J  - Do the following until it reaches a fixed point, returningIndices eachof step:S
 Æṁ - Dequeue; Remove the first characterMedian
 1 - Pop; Remove the lastYield characterS
 -- Get the second-to-last step, which will be the middle character/middleIndex 2into charactersS
 Æm - Get their arithmetic mean

The Æṁ median atom returns the mean of the two central elements if the list has an even list. When the list is the indices of S (i.e. [1, 2, ..., len(S)]), this will always be half the sum of an odd and an even integer, so the result will be \$x + \frac 1 2, x \in \mathbb N\$.

When indexing with non-integers such as \$x + \frac 1 2\$, Jelly instead uses the pair \$[x, x+1]\$ to index, which, in this case, results the two central characters if the list length is even.

Jelly, 8 bytes

ḊṖ$Ƭ-ịÆm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.

How it works

ḊṖ$Ƭ-ịÆm - Main link. Takes a string S on the left
  - Do the following until it reaches a fixed point, returning each step:
 - Dequeue; Remove the first character
 - Pop; Remove the last character
 -- Get the second-to-last step, which will be the middle character/middle 2 characters
 Æm - Get their arithmetic mean

Jelly, 7 bytes

JÆṁị1Æm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.

How it works

JÆṁị1Æm - Main link. Takes a string S on the left
J - Indices of S
 Æṁ - Median
 1 - Yield S
 ị - Index into S
 Æm - Get their arithmetic mean

The Æṁ median atom returns the mean of the two central elements if the list has an even list. When the list is the indices of S (i.e. [1, 2, ..., len(S)]), this will always be half the sum of an odd and an even integer, so the result will be \$x + \frac 1 2, x \in \mathbb N\$.

When indexing with non-integers such as \$x + \frac 1 2\$, Jelly instead uses the pair \$[x, x+1]\$ to index, which, in this case, results the two central characters if the list length is even.

deleted 74 characters in body
Source Link

Jelly, 8 bytes

ḊṖ$Ƭ-ịÆm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.Relevant default

How it works

ḊṖ$Ƭ-ịÆm - Main link. Takes a string S on the left
 $Ƭ - Do the following until it reaches a fixed point, returning each step:
Ḋ - Dequeue; Remove the first character
 Ṗ - Pop; Remove the last character
 -ị - Get the second-to-last step, which will be the middle character/middle 2 characters
 Æm - Get their arithmetic mean

Jelly, 8 bytes

ḊṖ$Ƭ-ịÆm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.Relevant default

How it works

ḊṖ$Ƭ-ịÆm - Main link. Takes a string S on the left
 $Ƭ - Do the following until it reaches a fixed point, returning each step:
Ḋ - Dequeue; Remove the first character
 Ṗ - Pop; Remove the last character
 -ị - Get the second-to-last step, which will be the middle character/middle 2 characters
 Æm - Get their arithmetic mean

Jelly, 8 bytes

ḊṖ$Ƭ-ịÆm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint.

How it works

ḊṖ$Ƭ-ịÆm - Main link. Takes a string S on the left
 $Ƭ - Do the following until it reaches a fixed point, returning each step:
Ḋ - Dequeue; Remove the first character
 Ṗ - Pop; Remove the last character
 -ị - Get the second-to-last step, which will be the middle character/middle 2 characters
 Æm - Get their arithmetic mean
Source Link

Jelly, 8 bytes

ḊṖ$Ƭ-ịÆm

Try it online!

Takes input as a list of codepoints. Outputs a single codepoint. Relevant default

How it works

ḊṖ$Ƭ-ịÆm - Main link. Takes a string S on the left
 $Ƭ - Do the following until it reaches a fixed point, returning each step:
Ḋ - Dequeue; Remove the first character
 Ṗ - Pop; Remove the last character
 -ị - Get the second-to-last step, which will be the middle character/middle 2 characters
 Æm - Get their arithmetic mean

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