- 50.9k
- 11
- 133
- 364
Jelly, 87 bytes
ḊṖ$Ƭ-ịÆmJÆṁị1Æm
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
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
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.
- 50.9k
- 11
- 133
- 364
Jelly, 8 bytes
ḊṖ$Ƭ-ịÆm
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
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
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, 8 bytes
ḊṖ$Ƭ-ịÆm
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