| Bytes | Lang | Time | Link |
|---|---|---|---|
| 031 | AWK | 250825T162043Z | xrs |
| 005 | Uiua | 231125T085136Z | chunes |
| 005 | J | 171031T134251Z | Jonah |
| 006 | Itr | 230814T125110Z | bsoelch |
| 018 | PowerShell | 230815T150006Z | James Fl |
| 020 | Javascript | 230814T131418Z | Luis fel |
| 003 | Thunno 2 | 230809T160447Z | The Thon |
| 032 | ZSH | 230404T102709Z | Thor |
| 004 | Vyxal | 230404T093609Z | The Thon |
| nan | 230404T093400Z | The Thon | |
| 020 | C# Visual C# Interactive Compiler | 220114T115635Z | Fichtelz |
| 024 | Factor | 220114T065826Z | chunes |
| 013 | V | 170531T210756Z | DJMcMayh |
| 035 | C | 170604T040605Z | MD XF |
| 005 | APL Dyalog | 171031T130150Z | J. Sall& |
| nan | Perl 5 | 171031T014743Z | Xcali |
| 046 | Lua | 170531T210759Z | MCAdvent |
| 023 | shortC | 170604T040801Z | MD XF |
| 024 | Crystal | 170601T094207Z | Domii |
| 041 | REXX | 170601T205508Z | idrougge |
| 027 | Clojure | 170601T171218Z | NikoNyrh |
| 022 | Python | 170531T210852Z | totallyh |
| 057 | C++ | 170601T043032Z | HSchmale |
| 018 | Ruby | 170601T092008Z | reiterma |
| 022 | Cubix | 170601T145644Z | user4854 |
| 051 | R | 170601T134336Z | bouncyba |
| 035 | Lua | 170601T105936Z | Felipe N |
| 008 | CJam | 170601T110057Z | Erik the |
| 007 | Pyth | 170601T101557Z | Jim |
| 036 | PHP>=7.1 | 170531T220628Z | Jör |
| 073 | C | 170601T094838Z | sigvaldm |
| 027 | C# | 170601T082603Z | TheLetha |
| 042 | Java 8 | 170601T090310Z | Kevin Cr |
| 025 | ><> with this interpreter | 170601T053742Z | Not a tr |
| 011 | CJam | 170601T031117Z | Esolangi |
| 024 | Alice | 170601T022900Z | Nitrodon |
| nan | 170601T000611Z | Brad Gil | |
| 034 | Mathematica | 170531T220545Z | ZaMoC |
| 018 | QBIC | 170531T223951Z | steenber |
| 022 | Haskell | 170531T223433Z | nimi |
| 008 | Japt | 170531T222646Z | Luke |
| 004 | Jelly | 170531T213244Z | fireflam |
| 005 | 05AB1E | 170531T210944Z | Riley |
| 026 | JavaScript ES6 | 170531T211818Z | ETHprodu |
| 022 | Octave | 170531T212448Z | Stewie G |
| 005 | MATL | 170531T211042Z | DJMcMayh |
AWK, 31 bytes
$0=a[split($1,a,X)-$2+1]==a[$2]
Prints 1 for truthy, nothing for falsey. Link is to version that prints 0 for falsey.
J, 6 5 bytes
{]=|.
-4 bytes thanks to FrownyFrog for {(=|.)
See original answer explanation -- idea is similar enough, but this is accomplished with a dyadic hook whose right verb is itself a monadic hook.
original answer (10 bytes)
{=/@(,:|.)
,:|. right arg on top of reverse right arg
=/ are they elementwise equal?
{ take from that boolean list the index indicated by the left arg
Itr, 6 bytes
ä¡Y=à@
0-indexed
Explanation
ä ; duplicate the first (implicit) input
¡ ; reverse it
Y= ; zip the two lists with equality
à@ ; get the element at the index given by the second index
; implicit output
Javascript, 20 bytes
s=>n=>s[n]==s.at(~n)
Thunno 2, 3 bytes
Ḳ=i
Explanation
Ḳ=i # Implicit input
Ḳ # Bifurcate the input string
= # Check for equality (vectorised)
i # Index into this list
# Implicit output
Vyxal, 4 bytes
fḂ=i
Explanation
fḂ=i # Implicit input
f # Flatten into a list of characters
Ḃ # Bifurcate: duplicate and reverse
= # Are they equal (vectorises)
i # Index in
# Implicit output
Thunno, \$ 8 \log_{256}(96) \approx \$ 6.58 bytes
Drz.=sAI
0-indexed. Change AI to AH if you want it to be 1-indexed.
Explanation
Drz.=sAI # Implicit input
Dr # Duplicate and reverse
z.= # Zipped equality
sAI # Swap and index in
# Implicit output
C# (Visual C# Interactive Compiler), 20 bytes
I don't have enough reputation to comment on TheLethalCoder's answer, but in C# 8 you can save some more bytes.
s=>n=>s[n]==s[^++n];
Factor, 24 bytes
[ 2dup nth -rot nth* = ]
Explanation
nth* is like nth except it indexes from the back; if 0 nth is the first element, 0 nth* is the last.
! 1 "[][]"
2dup ! 1 "[][]" 1 "[][]"
nth ! 1 "[][]" 93
-rot ! 93 1 "[][]"
nth* ! 93 91
= ! f
V, 26, 16, 13 bytes
ä$Àñã2xñVpø±
Hexdump:
00000000: e424 c0f1 e332 78f1 5670 f888 b1 .$...2x.Vp...
1 indexed.
Explanation:
ä$ " Duplicate this line horizontally
Àñ ñ " Arg1 times...
ã " Move to the center of this line
2x " And delete two characters
V " Select this whole line
p " And replace it with the last pair of characters we deleted
ø " Count the number of matches of the following regex...
<0x88> " Any character
± " Followed by itself
For reference, my original answer was:
Àñx$x|ñxv$hhpÓ¨.©±/1
ñllS0
Try it online! (0 indexed)
Hexdump:
00000000: c0f1 7824 787c f178 7624 6868 70d3 a82e ..x$x|.xv$hhp...
00000010: a9b1 2f31 0af1 6c6c 5330 ../1..llS0
APL (Dyalog), 10 5 bytes
⊃=⊃∘⌽
This is a tacit function, which needs to be assigned a name such as f←⊃=⊃∘⌽, and then called as int f string.
Thanks to @Adám for a whopping 5 bytes.
How it works:
⊃=⊃∘⌽ ⍝ Main function; tacit.
⍝ Inputs are ⍺ = 1 (left) and ⍵ = 'abca' (right).
⊃ ⍝ ⍺⊃⍵, meaning 'pick the ⍺-th element of ⍵'
= ⍝ Compare to
⌽ ⍝ ⌽⍵, meaning 'invert ⍵'
⊃ ⍝ Again, ⍺⊃⍵, but:
∘ ⍝ Compose. This turns ⌽ into the right argument for ⊃,
⍝ which becomes 'pick the ⍺-th element from ⌽(the inverse of)⍵'
The 22 byte answer was edited out. If you want to see it, check the revision history.
shortC, 23 bytes
Df(s,n)s[n]==s[Ss)-1-n]
Substitutions in this program:
D->#defineS->strlen(- No auto-inserted closing stuff :(
REXX, 41 bytes
parse arg n,=(n)l+1''-(n)r+1 .
return l=r
Arguments are given in n,s order since n is required for parsing s.
Clojure, 27 bytes
#(nth(map =(reverse %)%)%2)
Wow, this was shorter than I expected.
C++, 57 Bytes
Assuming header includes don't count.
bool c(std::string s,int i){return s[i]==s[s.size()-i];}
Ruby, 22 20 18 bytes
->s,n{s[n]==s[~n]}
Cubix, 22 bytes
..@.IAp):tBvpptc?1.\O0
1-indexed, takes input as index,string, separated by a space.
Cubified
. .
@ .
I A p ) : t B v
p p t c ? 1 . \
O 0
. .
Explanation
This is mostly linear. The main logic is
IAp):tBpptc
IA Get the first input as an int and the rest as a string.
p): Move the index to the top of the stack, increment it, and copy it.
t Look up the appropriate character in the string.
Bpp Reverse the stack and put the index and character back on top.
t Look up the appropriate character in the reversed string.
c XOR the two characters.
We then branch with ? to Output 1 if the result is 0 and 0 otherwise.
R 51 bytes
function(s,n){s=el(strsplit(s,''));s[n]==rev(s)[n]}
Anonymous function, uses 1-based indexing
Pyth, 8 7 bytes
q@zQ@_z
With the input reversed: first the index, then the string. It is 0-indexed.
Explanations:
q@zQ@_z
@zQ Get the nth (Qth) character
_z Reverse the string
@ Get the nth character of the reversed string. Implicit input of the index
q Test equality
C, 73 bytes
Compiles as-is with GCC 6.3.1 (no flags). Some unnecessary obfuscation included.
main(c,v)char**v;{c=atoi(v[2]);putchar((*++v)[c]-(*v)[strlen(*v+1)-c]);}
Usage
$./a.out abcdcba 6
Truthy = nothing, falsey = garbage.
C#, 28 27 bytes
s=>n=>s[n]==s[s.Length+~n];
Saved a byte thanks to @KevinCruijssen.
Compiles to a Func<string, Func<int, bool>>.
><> (with this interpreter), 25 bytes
i:0(?v
]&=n;>~{:}[:}]&r[}
It doesn't work in TIO: the TIO interpreter doesn't reverse the new stack when doing the [ instruction, but the fish playground does — compare "abcde"5[ooooo; run here and here, for example.
The string input is taken from STDIN, and we assume n is already on the stack. Uses 1-indexing.
The fish gets the nth character with [:}]&, which siphons off the first n things on the stack into a new, reversed stack, manipulates that a bit, then puts the things back and saves the nth character in the register. It then reverses the whole stack and does the same again, and returns 1 if the two characters are equal, and 0 otherwise.
This seems to work at TIO, for 26 bytes:
i:0(?v
]&=n;>~{:}[{:}]&r[{
CJam, 11 bytes
q~_2$=@@~==
Bad. Too much stack manipulation.
Alice, 24 bytes
/t.~e?/-mom
\I!RtI&1n;@/
Input consists of the string on one line, and the number on the second line. Output is Jabberwocky if the characters are the same, and nothing otherwise.
Explanation
This program is mostly in ordinal mode, with one command in cardinal mode. Linearized, the program is as follows:
I.ReI&1m;mt!~t?&-no
I % Input first line
% STACK: ["ppqqpq"]
. % Duplicate top of stack
% STACK: ["ppqqpq", "ppqqpq"]
R % Reverse top of stack
% STACK: ["ppqqpq", "qpqqpp"]
e % Push empty string
% STACK: ["ppqqpq", "qpqqpp", ""]
I % Input next line
% STACK: ["ppqqpq", "qpqqpp", "", "3"]
& % (cardinal mode) Pop stack and repeat next command that many times
% STACK: ["ppqqpq", "qpqqpp", ""], ITERATOR: [3]
1 % Append "1" to top of stack
% STACK: ["ppqqpq", "qpqqpp", "111"]
m % Truncate so the top two strings on the stack have the same length
% STACK: ["ppqqpq", "qpq", "111"]
; % Discard top of stack
% STACK: ["ppqqpq", "qpq"]
m % Truncate again
% STACK: ["ppq", "qpq"]
t % Extract last character
% STACK: ["ppq", "qp", "q"]
! % Move top of stack to tape
% STACK: ["ppq", "qp"]
~ % Swap
% STACK: ["qp", "ppq"]
t % Extract last character
% STACK: ["qp", "pp", "q"]
? % Copy data from tape onto top of stack
% STACK: ["qp', "pp", "q", "q"]
& % Iterator: effectively a no-op in ordinal mode when the top of the stack is a 1-character string
% STACK: ["qp", "pp", "q"], ITERATOR: ["q"]
- % Remove occurrences: here, result is "" iff the characters are equal
% STACK: ["qp", "pp", ""]
n % Logical Not (for a consistent truthy value)
% STACK: ["qp", "pp", "Jabberwocky"]
o % Output top of stack
Perl 6, 27 bytes
{[eq] $^a.comb[$^b,*-1-$b]}
{ # bare block lambda with two placeholder parameters 「$a」 and 「$b」
[eq] # reduce using string equality operator
$^a # declare first positional parameter
.comb\ # split that into individual characters
[ # index into that sequence
$^b, # declare and use second parameter
*-1-$b # closure that subtracts one and the
# second parameter of the outer block
# (「*」 is the parameter of this closure)
]
}
Mathematica, 34 Bytes
s=StringTake;s[#,{#2}]==s[#,{-#2}]&
QBIC, 18 bytes
?_s;,:,1|=_sA,-a,1
Explanation
? = PRINT -1 if equal, 0 otherwise, between
_s | A substring of
;,:,1 A$ string (read from cmd line), from the n'th pos, length 1
_sA,-a,1 And a substring of A$, n'th pos from the right, also 1 length
The second Substring is auto-terminated because EOF.
Haskell, 22 bytes
s#n=s!!n==reverse s!!n
0-basd. Usage example: "letter" # 1 -> True.
Jelly, 5 4 bytes
=UƓị
There should be no shorter answers in Jelly. An program would need comparison, reversal/negation, an index call, and a byte for control flow (Ɠ in this case), which adds up to four bytes.
How it works
=UƓị
- (implicit) input string
= - equals (vectorizing by characters because a string is a charlist)
U - the reversed string
ị - get the element at the index of:
Ɠ - the input index
-1 byte thanks to @ais523, using Ɠ
05AB1E, 7 5 bytes
-2 bytes thanks to Adnan
ÂøsèË
Try it online! or Try all tests
 # Add a reversed copy on top of the original string
ø # Zip
sè # Extract the nth element
Ë # Check if they are equal
JavaScript (ES6), 26 bytes
s=>n=>s[n]==s.substr(~n,1)
Alternatively:
s=>n=>s[n]==s.slice(~n)[0]
This one almost works, but fails when n == 0 (because s.slice(-1,0) == ""):
s=>n=>s[n]==s.slice(~n,-n)
Another 26-byte solution that @RickHitchcock pointed out:
s=>n=>s[n]==s[s.length+~n]
Octave, 22 bytes
@(s,n)s(n)==s(end-n+1)
Or the same bytecount:
@(s,n)s(n)==flip(s)(n)
Explanation:
It's quite straight forward. The first one takes a string s and an integer n as inputs and checks the n'th element s(n) against the "last-n+1" element for equality.
The second one checks the n'th element s(n) against the n'th element of s reversed.
MATL, 5 bytes
tP=w)
Explanation:
t % Duplicate the input
Stack:
['ppqqpq' 'ppqqpq']
P % Reverse the top element of the stack
Stack:
['ppqqpq' 'qpqqpp']
= % Equals. Push an array of the indices that are equal
Stack:
[[0 1 1 1 1 0]]
w % Swap the top two elements
Stack:
[[0 1 1 1 1 0], 3]
) % Grab the a'th element of b