It's one of these again :D
Your task, if you wish to accept it, is to write a program/function (without any uppercase letters) that outputs/returns its string input/argument. The tricky part is that if I convert your source code to uppercase, the output must be reversed.
For simplicity, you can assume that the input is always a single line string containing only ASCII letters (a-z
), digits (0-9
), and spaces.
You do not need to handle empty input.
Example
Let's say your source code is abc
and its input is hello
. If I write ABC
instead and run it, the output must be olleh
.
38 Answers 38
05AB1E, 1 byte
r
Try it online lowercase or uppercase!
Finally a question which I (a dumb brain) can answer! Thanks for this easy, yet fun challenge! (I do feel great, even though it requires little effort to make an answer in 05AB1E.)
Wait, how?
r # reverses the stack. (Which literally does not do anything since only the
# implicit input is in the stack)
R # actually reverses the top string of the stack (Which is the implicit input).
# at the end, the input is automatically printed.
-
1\$\begingroup\$ That's awesome :) \$\endgroup\$Steve Bennett– Steve Bennett2020年09月20日 03:07:46 +00:00Commented Sep 20, 2020 at 3:07
-
2\$\begingroup\$ That's completely unfair! You didn't even put any effort on it and you get 40 upvotes, more than the sum of my answers. (Upvote) \$\endgroup\$TwilightSparkle– TwilightSparkle2020年09月23日 05:20:08 +00:00Commented Sep 23, 2020 at 5:20
-
2\$\begingroup\$ @null Sorry about that, but I do not have any idea how I got 40+ upvotes. (Honestly, I thought that I will get numerous downvotes) \$\endgroup\$SunnyMoon– SunnyMoon2020年09月23日 06:49:48 +00:00Commented Sep 23, 2020 at 6:49
-
1\$\begingroup\$ You beat me to it. I was thinking the same thing :) \$\endgroup\$Makonede– Makonede2020年09月26日 18:09:38 +00:00Commented Sep 26, 2020 at 18:09
Python 3, (削除) 61 50 49 (削除ここまで) 48 bytes
-1 thanks to benrg!
r=-1;r=1;print(input()[::r])
This works because
- PEP-3131 was implemented in Python 3.0; and
- These are the minimal length Unicode characters with no upper-case version which also normalise under the Normalization Form Compatibility Composition (NFKC) transformation to the basic latin characters one would normally use - TIO.
Note that identifiers, like r
and the function names print
and input
, may be written like this but not keywords, like def
or lambda
.
(See the upper-casing of the code.)
-
4\$\begingroup\$ ...but it would make the code two bytes longer :) \$\endgroup\$Jonathan Allan– Jonathan Allan2020年09月18日 08:42:24 +00:00Commented Sep 18, 2020 at 8:42
-
1\$\begingroup\$ Time to enter some bugs for various IDEs... youtrack.jetbrains.com/issue/PY-44577 \$\endgroup\$Thomas Weller– Thomas Weller2020年09月18日 08:47:35 +00:00Commented Sep 18, 2020 at 8:47
-
2\$\begingroup\$ @JonathanAllan you're probably thinking of Print X Without X \$\endgroup\$2020年09月18日 09:18:27 +00:00Commented Sep 18, 2020 at 9:18
-
2\$\begingroup\$ @ThomasWeller - nthistle's cop submission to Print X Without X employed the fact that we can use Unicode characters for identifiers. \$\endgroup\$Jonathan Allan– Jonathan Allan2020年09月18日 09:30:05 +00:00Commented Sep 18, 2020 at 9:30
-
1\$\begingroup\$ @whme No, the spec is that the lower-cased code gives the input back as-is. \$\endgroup\$Jonathan Allan– Jonathan Allan2020年09月18日 12:22:43 +00:00Commented Sep 18, 2020 at 12:22
Python 3, 48 bytes
print(input()[::b'b'[0]%3-1])
print(input()[::B'B'[0]%3-1])
You can also verify that the upper program is truly uppercase.
It's unlikely we can write a program for Python 3 just using ASCII - we have no def
, no lambda
, and no builtin function calls. Also, all the properties of existing builtin objects are lowercase so we can't access those either. So instead our strategy is to look for Unicode characters that:
- Are not uppercase
- NFKC normalise to the character we want
- NFKC normalise to the character we want even after uppercasing
The following code does exactly that.
from unicodedata import normalize
for c in 'printinput':
for i in range(0x10ffff):
if not chr(i).isupper() and normalize('NFKC', chr(i)) == normalize('NFKC', chr(i).upper()) == c:
print(chr(i))
break
else:
raise Exception('no')
-
1\$\begingroup\$ Love the bytes trick! \$\endgroup\$Jonathan Allan– Jonathan Allan2020年09月18日 08:43:25 +00:00Commented Sep 18, 2020 at 8:43
Jelly, 1 byte
ṛ
How?
ṛ - Main Link: list of characters, S
ṛ - right argument (implicitly S)
- implicitly print
Ṛ - Main Link: list of characters, S
Ṛ - reverse
- implicitly print
-
1\$\begingroup\$
Ṛ
is an uppercase letter withṛ
being its lowercase. \$\endgroup\$Adám– Adám2020年09月17日 17:36:01 +00:00Commented Sep 17, 2020 at 17:36 -
1\$\begingroup\$ Totally fixed and now just 1 byte and future-proof. \$\endgroup\$Jonathan Allan– Jonathan Allan2020年09月17日 18:13:49 +00:00Commented Sep 17, 2020 at 18:13
-
\$\begingroup\$ A bit late, but
u
/U
also works: Try it online! \$\endgroup\$2020年10月10日 14:20:54 +00:00Commented Oct 10, 2020 at 14:20 -
\$\begingroup\$ @cairdcoinheringaahing I had that before, but since
u
is still free to be implemented as an atom this one is future-proof. \$\endgroup\$Jonathan Allan– Jonathan Allan2020年10月10日 14:44:47 +00:00Commented Oct 10, 2020 at 14:44
APL (Dyalog Unicode), 10 bytes (SBCS)
Anonymous tacit prefix function.
⌽⍣('a'∊⎕a)
⌽⍣(
...)
apply reverse the following number of times:
'a'∊⎕a
is "a" a member of the uppercase alphabet? (0)
Uppercased
⌽⍣('A'∊⎕A)
⌽⍣(
...)
apply reverse the following number of times:
'A'∊⎕A
is "a" a member of the uppercase Alphabet? (1)
In Dyalog APL, ⎕A
is case-insensitive and always refers to the uppercase alphabet.
Perl 5 -p
, (削除) 33 (削除ここまで), (削除) 25 (削除ここまで), 22 bytes
Thank's to @DomHastings who also had the same idea
m;$_=/.(?{$\=$&.$\})^/
uppercase
M;$_=/.(?{$\=$&.$\})^/
-
\$\begingroup\$ This is a nice solution! Can't think of a different approach (this one didn't even jump out at me to be honest!) It's possible to potentially save a couple of bytes if you use
s
instead ofnext
and add a;
to the end. It shouldn't be a problem because the input can only contain letters! \$\endgroup\$Dom Hastings– Dom Hastings2020年09月18日 06:47:31 +00:00Commented Sep 18, 2020 at 6:47 -
\$\begingroup\$ Also, you can use
\D
as the search pattern to save a few more: Try it online! \$\endgroup\$Dom Hastings– Dom Hastings2020年09月18日 06:51:01 +00:00Commented Sep 18, 2020 at 6:51 -
\$\begingroup\$ @DomHastings, indeed, i also though to
m
instead ofnext
, but was looking if there could be a false match \$\endgroup\$Nahuel Fouilleul– Nahuel Fouilleul2020年09月18日 08:00:15 +00:00Commented Sep 18, 2020 at 8:00 -
\$\begingroup\$ Also I didn't see your comments, when I modified
[0円-277円]
to.
, i think we crossed \$\endgroup\$Nahuel Fouilleul– Nahuel Fouilleul2020年09月18日 08:03:15 +00:00Commented Sep 18, 2020 at 8:03 -
\$\begingroup\$ Ahh,
m
is even better! Looks good! \$\endgroup\$Dom Hastings– Dom Hastings2020年09月18日 08:14:08 +00:00Commented Sep 18, 2020 at 8:14
R, 122 bytes
`103円`=`162円145円166円`
`151円156円164円124円157円125円164円1468円`(c(`165円164円1468円124円157円111円156円164円`(`163円143円141円156円`(,""))))
Includes only one letter, the lone c
in the middle. The rest uses octal codes to get the equivalent of
C=rev
intToUtf8(c(utf8ToInt(scan(,""))))
With the lowercase c
, the c
makes no difference: we convert the input to integers, concatenate it with nothing, and convert back to characters. With an uppercase C
, the integer vector in the middle gets reversed before being converted back.
JavaScript (ES6), 46 bytes
Takes and returns an array of characters.
In lowercase
s=>s.map?s:s["162円145円166円145円162円163円145円"]()
In uppercase
S=>S.MAP?S:S["162円145円166円145円162円163円145円"]()
JavaScript (ES6), (削除) 74 (削除ここまで) 73 bytes
Saved 1 byte thanks to @Shaggy
Takes and returns a string.
In lowercase
s=>s.big?s:[...s]["162円145円166円145円162円163円145円"]()["152円157円151円156円"]``
In uppercase
S=>S.BIG?S:[...S]["162円145円166円145円162円163円145円"]()["152円157円151円156円"]``
-
\$\begingroup\$ You could use the logic from your second solution, using
s.big
, in your first solution to save a byte. \$\endgroup\$Shaggy– Shaggy2020年09月17日 18:43:43 +00:00Commented Sep 17, 2020 at 18:43 -
\$\begingroup\$ @Shaggy Good idea. \$\endgroup\$Arnauld– Arnauld2020年09月17日 18:46:24 +00:00Commented Sep 17, 2020 at 18:46
-
2\$\begingroup\$ The problem statement does explicitly say
input is always a single line string
, which I interpret to mean an actual string in JavaScript, rather than an array of characters. \$\endgroup\$Steve Bennett– Steve Bennett2020年09月20日 03:05:22 +00:00Commented Sep 20, 2020 at 3:05
Haskell, 38 bytes
_0(_1:_2)|'a'<'_'=_0 _2++[_1]
_0 _1=_1
_0(_1:_2)|'A'<'_'=_0 _2++[_1]
_0 _1=_1
Haskell requires that any variable name beginning with a capital letter is constructor of a declared type. This basically means we can't have any identifiers that start with a letter. (I think the options we actually have are LT
, GT
, and EQ
but I wasn't able to find a use for any of these.) Luckily it is possible to write haskell programs without letters. We can start variable names with _
and we add numbers to the end to make it a valid name (certain symbols would work too).
To detect that which mode we are in we use the fact that strings change and do a comparison between a changing and static string, 'a'<'_'
evaluates to False
while 'A'<'_'
is true.
Ruby -p
, (削除) 51 (削除ここまで) (削除) 49 (削除ここまで) (削除) 47 (削除ここまで) 46 bytes
Saved a byte by using a shorter lexicographical comparison taken from @WheatWizard's Haskell answer.
Lowercase
?a<?_&&(f=->_{/.$/?($_=$`;f[_+=$&]):$_=_})['']
?a<?_
tests whether the character a
is lexicographically less than the character _
. The test returns false
, short-circuiting the &&
operator so that none of the remaining code is actually executed. The input is printed automatically thanks to the -p
flag.
Uppercase
?A<?_&&(F=->_{/.$/?($_=$`;F[_+=$&]):$_=_})['']
Now we test whether A
is lexicographically less than _
. Here the comparison returns true
so we proceed past &&
. The code after &&
defines and calls a recursive lambda that reverses the input, which (because of -p
) has been stored in the predefined global variable $_
:
(F=->_{ # define a lambda F with parameter _
/.$/?( # if $_ contains at least one character, match the last one, then
$_=$`; # remove that character from $_
F[_+=$&] # recursively call F, appending that character to _
):$_=_ # else set $_ to _, which now contains the full reversed input
})[''] # call F, initialising _ to the empty string
Finally, $_
(now containing the reversed input) is printed automatically thanks to the -p
flag.
-
\$\begingroup\$ Very impressive. This might be the least clear Ruby code I've ever seen. \$\endgroup\$Eric Duminil– Eric Duminil2020年09月20日 15:16:20 +00:00Commented Sep 20, 2020 at 15:16
-
Windows NT Batch + coreutils, 28 bytes
@if %os:~9%==t (tac)else cat
Explanation: %OS%
contains Windows_NT
and the substring starting at position 9
is compared with the letter t
. If the batch file is uppercased then the comparison succeeds and tac
is invoked otherwise cat
is invoked.
-
\$\begingroup\$ How will invoking
cat
ortac
with no arguments print the arguments to the batch file backwards? \$\endgroup\$TessellatingHeckler– TessellatingHeckler2020年09月17日 20:09:54 +00:00Commented Sep 17, 2020 at 20:09 -
\$\begingroup\$ @TessellatingHeckler The question allows you any string input, so I'm assuming the input will be on STDIN. Maybe I should have said that in my answer... \$\endgroup\$Neil– Neil2020年09月17日 22:20:27 +00:00Commented Sep 17, 2020 at 22:20
Wolfram Language (Mathematica), 24 bytes
#[[i=1;i^2;;-i^2;;i^2]]&
I
is the built-in symbol for the imaginary unit \$i\$. Its value cannot be overridden without Unprotect
ing it first.
J, 21 14 bytes
|.^:({.\:'a_')
-7 bytes thanks to Adam!
Taking inspiration from Adam's APL answer.
how
|.^:
Reverse the following number of times...:({.\:'a_')
Grade down\:
the stringa_
and take the first element{.
.- "Grade down" returns a list of indexes for the string, sorted descending. Thus
\:'abc'
would return2 1 0
, for example. - "Grade down" will thus return
0
for the stringa_
, and1
for the stringA_
, since_
is betweena
andA
in the ascii alphabet.
- "Grade down" returns a list of indexes for the string, sorted descending. Thus
-
\$\begingroup\$
A
is uppercase. \$\endgroup\$Adám– Adám2020年09月17日 18:10:48 +00:00Commented Sep 17, 2020 at 18:10 -
\$\begingroup\$ Thanks. Needed a new approach but fixed now. \$\endgroup\$Jonah– Jonah2020年09月17日 18:32:35 +00:00Commented Sep 17, 2020 at 18:32
-
1\$\begingroup\$
|.^:({.\:'a_')
\$\endgroup\$Adám– Adám2020年09月17日 21:03:01 +00:00Commented Sep 17, 2020 at 21:03 -
\$\begingroup\$ Very clever. Thanks Adam. \$\endgroup\$Jonah– Jonah2020年09月17日 21:05:33 +00:00Commented Sep 17, 2020 at 21:05
APL (Dyalog Extended), 9 bytes
⌽⍣(&l×ばつ'a')
Try it online (both lower and upper)!
In Extended, ×ばつ
(signum) on letters queries the letter case, giving -1 for lowercase and 1 for uppercase. Then <
has implicit left arg of 0, so it tests if the right arg is positive (1) or not (0). Therefore, &l×ばつ'a'
evaluates to 0 and &l×ばつ'A'
evaluates to 1.
-
\$\begingroup\$ Clever use of the Footer! \$\endgroup\$Adám– Adám2020年09月18日 04:46:21 +00:00Commented Sep 18, 2020 at 4:46
V (vim), 2 bytes
væ
And uppercased:
Væ
Hexdump:
00000000: 76e6 v
How?
v
enters 'visual mode' and begins selecting characters. At first, only 1 character will be selected. Then æ
reverses every character that is selected. Reversing only 1 character does nothing.
But V
will select every character on the current line, and then æ
flips the whole line.
-
\$\begingroup\$ Isnt
Æ
the uppercase ofæ
\$\endgroup\$Jasen– Jasen2020年09月20日 01:30:48 +00:00Commented Sep 20, 2020 at 1:30 -
\$\begingroup\$ @Jasen Yes, it is. However, as the comments say That could get complicated. As long as the behavior is consistent for each character, it's fine to treat them (non-ASCII characters) either as lower/uppercase or as separate, non-letter characters. so I'm treating
æ
as a non-letter. \$\endgroup\$DJMcMayhem– DJMcMayhem2020年09月20日 03:32:24 +00:00Commented Sep 20, 2020 at 3:32
Forth (gforth), 61 bytes
: f 'a 65 = if bounds 1- swap 1- -do i c@ emit 1 -loop then ;
A challenge where the case insensitivity of Forth has a use ... except that you don't have a string reversal built-in, so you have to loop through the string itself in reverse.
Almost all words in Forth are case-insensitive. The only case-sensitive part in the code is 'a
or 'A
, where the char's ASCII code (97 for a
, 65 for A
) is pushed to the stack. So we can compare it with a (trivially case-insensitive) numeric literal 65
. If they're equal, the string is printed in reverse. Otherwise, the string is returned as-is.
-
\$\begingroup\$ Now to find a place where space separation is useful. \$\endgroup\$Razetime– Razetime2020年11月13日 08:15:31 +00:00Commented Nov 13, 2020 at 8:15
Brachylog, 3 bytes
ṡ↔|
and
Ṡ↔|
ṡ↔
ṡ if input is a square matrix,
Ṡ if input is a string,
↔ it is reversed
| otherwise return input unaltered
PowerShell 7+, (削除) 56 (削除ここまで), 35 bytes
-join"$args"['a'[0]-97?99..0:0..99]
# save as golf.ps1 and call .\golf.ps1 "string"
# e.g. (running in anonymous function &{} for demo):
PS C:\> &{-join"$args"['a'[0]-97?99..0:0..99]} '123 Alice'
123 Alice
PS C:\> &{-JOIN"$ARGS"['A'[0]-97?99..0:0..99]} '123 Alice'
ecilA 321
With golfing suggestions from mazzy.
Assuming the string is <= 100 characters. Change both the 99s to 1e5 notation for +2 bytes, much longer inputs, and much much slower code.
old 56 byte version
&{$a="$args";(gv a).name[0]-97?-join$a[$a.length..0]:$a}
e.g.
PS C:\> &{$a="$args";(gv a).name[0]-97?-join$a[$a.length..0]:$a} "123 Alice"
123 Alice
PS C:\> &{$A="$ARGS";(GV A).NAME[0]-97?-join$A[$A.LENGTH..0]:$A} "123 Alice"
ecilA 321
The parameters to the anonymous function {}
appear in the automatic variable $args
and get stored in variable $a
. String quotes "$args"
cast to a single string. PowerShell is indifferent about the case of variable names, command names, property names, operator names, etc. so all the code runs in either case. gv
is get-variable
which looks for the a
variable, finds its .Name
(a
or A
depending on the case of the script - case is preserved), gets character [0] which is a
or A
again but this time as a [char]
type, subtracts 97 (lowercase a
value in ASCII), and ? :
ternary operators whether that hit zero or non-zero, and either prints the original or reverse-indexes the characters and joins them into a reversed string. Printing is implicit. &{}
runs the anonymous function.
NB. TIO.Run only has PowerShell 5 or 6 at the time of writing, and ternary ?: is not in that version.
-
\$\begingroup\$
gv
is nice. you can save some bytes wuthparam($a)
instead$a="$args";
. You can omit&{}
also because CodeGolf requires a Complete program. the complete Powershell program is a text in a ps1-script. \$\endgroup\$mazzy– mazzy2020年09月18日 10:45:38 +00:00Commented Sep 18, 2020 at 10:45 -
\$\begingroup\$
gv
is nice and too heavy. The[char]'a'-97
is sufficient :) \$\endgroup\$mazzy– mazzy2020年09月18日 10:55:10 +00:00Commented Sep 18, 2020 at 10:55 -
1\$\begingroup\$ @mazzy good ideas! Can push them a bit further and do away with
param()
and[char]
and.Length
. \$\endgroup\$TessellatingHeckler– TessellatingHeckler2020年09月19日 11:26:32 +00:00Commented Sep 19, 2020 at 11:26
Pip, 6 bytes
[r_]@1
This is a function solution. Since it relies on the recently added unary R
operator, it doesn't work on TIO, but a similar 7-byte version does:
[rv_]@2
try it online! or TRY IT ONLINE!
Explanation
Lowercase:
[ ] Make a list containing
r A random number between 0 and 1;
_ The identity function
@1 Get the item at index 1 (the identity function)
Uppercase:
[ ] Make a list containing
R_ A function that reverses its argument
@1 Get the item at index 1, with cyclical indexing (the function)
The TIO version is the same idea, but uses the RV
operator for reverse. It therefore has three items in the lowercase list (including v
, which is -1) and gets the function using index 2 instead of 1.
Raku, 28 bytes
{.?"{'flip'~^' '}"()||$_}
$_
is the input to the function. Method calls lacking an explicit invocant are called on it.flip
is the method to reverse a string.$obj."name"()
is the syntax to call a method where the name is a string. The double quotes can contain interpolated values as usual.$obj.?method
means to callmethod
on$obj
if that method is defined for it, and otherwise returnNil
.~^
is the stringy exclusive-or operator, which exclusive-ors the corresponding characters of its operands.
Putting it all together, the uncapitalized program xors flip
and a string containing four spaces, producing FLIP
. That method is not defined for strings, so the .?
method call returns Nil
. Then Nil || $_
evaluates to the original string. When the source code is uppercased, flip
becomes FLIP
, which when xor-ed with the spaces becomes flip
, which when called on the input string, reverses it.
SNOBOL4 (CSNOBOL4), 61 bytes
&lcase 'a' :f(r)
output =input
r output =reverse(input)
end
SNOBOL by default case-folds identifiers and labels (unless &CASE
is set to 0
or the flag -CASE 0
is used at the start of the program), so the only thing that really changes is the 'a' -> 'A'
, as SNOBOL uses case-sensitive pattern matching. Since 'A'
is not lowercase, it jumps to the label R
, which reverses.
Klein 0X0, 68 bytes
Works in both 000 and 010
Lower case
"a`"1+-+?@ \
/!?: (0)?/!?:<@?
>$:?!\?>:?!\\( /
\ (/ \ )/
Upper case
"A`"1+-+?@ \
/!?: (0)?/!?:<@?
>$:?!\?>:?!\\( /
\ (/ \ )/
Most of this is just a program that reverses the input, which is not exactly easy in Klein.
>:?!\?)0( :?!\?@
\ (//!?:<?/!?:$<
\) / \( /
To do the condition we have the very simple
"a`"1+-+?@
Which is an expression that is exactly zero, but becomes something else when a
is capitalized. This is pretty much the exact method used by every other answer. The ?@
means that when it is zero it halts immediately (a cat program). Otherwise we continue execution to the reverse program bit.
JavaScript (V8), (削除) 46 (削除ここまで) (削除) 44 (削除ここまで) then by tch: 37 bytes
$=([o,...a])=>o?o.sub?o+$(a):$(a)+o:a
Thanks to tsh for saving 7 bytes!.
Recursive function $
takes a string and destructures it into the first character o
and an array a
of the remaining characters.
If lower case, o
has a property sub
it returns the forward string o+$(a)
.
Otherwise, O
has no property SUB
and it returns the reverse string $(A)+O
.
The final iteration happens when $
is called with and empty array so there is no o
. Here it returns a
, an empty array []
which acts as and empty string ""
in string addition.
-
1\$\begingroup\$
$=([o,...a])=>o?o.sub?o+$(a):$(a)+o:a
\$\endgroup\$tsh– tsh2020年11月13日 02:29:13 +00:00Commented Nov 13, 2020 at 2:29
Charcoal -v, 24 bytes
ternaryless"a""_"reverse
Try it online! In upper case:
TERNARYLESS"A""_"REVERSE
Try it online! Explanation: If a
or A
as appropriate is less than _
, the ternary then reverses the implicit input, otherwise just takes implicit input. The result is then implicitly printed.
-
\$\begingroup\$ I love how it looks like your
Try it online!
gets angry and demands me toTRY IT ONLINE!
. \$\endgroup\$2020年09月18日 12:37:04 +00:00Commented Sep 18, 2020 at 12:37 -
1\$\begingroup\$ @RedwolfPrograms try it online or die ;P \$\endgroup\$2020年09月19日 02:37:06 +00:00Commented Sep 19, 2020 at 2:37
MAWP, 19 bytes
%|11a{%%0~}<%0/>[;]
MAWP ignores lowercase letters, so this answer uses a conditional to check if subtraction has happened or not, and reverses based on it.
oK, 13 bytes
.:9+23*7!"!g"
Explanation:
"!g" /magic string
9+23*7! /9 + 23 * (ascii value mod 7)
.: /eval ascii values as a string
When the input is "!g"
it becomes "||"
which is evaluated as reversing twice.
When the input is "!G"
it becomes "| "
which is evaluated as reversing once.
oK repl, 10 bytes
I'm going to say that this one doesn't count, because it relies on the fact that the oK repl works in mysterious ways.
.:4*54!"u"
When the input is "u"
it becomes "$"
which evaluates as "string of expression". In the repl it is a noop when applied to strings.
When the input is "U"
it becomes "|"
which evaluates as reversing.
Excel VBA, 58 bytes
Lowercase:
sub r(s)
if asc("a")=65then s=strreverse(s)
[a1]=s
end sub
Uppercase:
SUB R(S)
IF ASC("A")=65THEN S=STRREVERSE(S)
[A1]=S
END SUB
Output is to the cell A1
of the currently active sheet (if this is in a module) or the parent sheet (if this is in a sheet object). I'm a little concerned this doesn't comply with the spec, though, because VBA auto-formats much of the code once it's input:
Sub r(s)
If Asc("a") = 65 Then s = StrReverse(s)
[a1] = s
End Sub
Of course, the standard has been to not consider the extra formatting in the byte count so I presume we can also ignore the capitalization. Really, I'm more worried about the answer being too straightforward to be interesting rather than that technicality.
heLLO
would becomeHEllo
. Although this question would still be way too hard \$\endgroup\$