Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Lowercase, but not just the letters

Parent

Lowercase, but not just the letters

+3
−0

Given a string of printable ASCII characters, convert them all to lowercase, except not just the letters.

ASCII characters that are letters have a bit in their binary representation that is 0 for uppercase, and 1 for lowercase. Setting this bit to 1 for a non-letter character that previously had it set to 0 results in it changing to a completely unrelated character, which for this challenge we will call the lowercase version of that character.

Input

  • A sequence of characters, each of which is a printable ASCII character (character codes 32 to 126 inclusive)
  • This may be a string or any ordered data structure of characters
  • There will never be an underscore _ (character code 95) as its lowercase version is character code 127, which is outside the printable range and used as a control character
  • Your code must work for inputs of up to 16 characters

Output

  • A sequence of the same number of characters as the input
  • This may be a string or any ordered data structure of characters. It does not need to match the input format (provided it is consistent between inputs)
    • For example, you may take input as an array of characters, and output as a string, provided this format does not change for different inputs
  • Each character is either the same as the input, if it was a lowercase version already, or otherwise the lowercase version of the input character

Examples

A letter

Character "A" is character code 65, or 1000001 in binary. The bit in position 5 from the right, representing $2^5$, is 0. Setting this bit to 1 gives 1100001, or 97, which is the character code for "a". So the lowercase version of "A" is "a", as expected.

A non-letter

Character "^" is character code 94, or 1011110 in binary. The bit in position 5 from the right, representing $2^5$, is 0. Setting this bit to 1 gives 1111110, or 126, which is the character code for "~". So the lowercase version of "^" is "~".

Test cases

Test cases are in the format "input" : "output"

Note that " and \ have both been escaped with a preceding \, because they are enclosed in double quotes, but each still represents a single character)

" " : " "
"!" : "!"
"\"" : "\""
"#" : "#"
"$" : "$"
"%" : "%"
"&" : "&"
"'" : "'"
"(" : "("
")" : ")"
"*" : "*"
"+" : "+"
"," : ","
"-" : "-"
"." : "."
"/" : "/"
"0" : "0"
"1" : "1"
"2" : "2"
"3" : "3"
"4" : "4"
"5" : "5"
"6" : "6"
"7" : "7"
"8" : "8"
"9" : "9"
":" : ":"
";" : ";"
"<" : "<"
"=" : "="
">" : ">"
"?" : "?"
"@" : "`"
"A" : "a"
"B" : "b"
"C" : "c"
"D" : "d"
"E" : "e"
"F" : "f"
"G" : "g"
"H" : "h"
"I" : "i"
"J" : "j"
"K" : "k"
"L" : "l"
"M" : "m"
"N" : "n"
"O" : "o"
"P" : "p"
"Q" : "q"
"R" : "r"
"S" : "s"
"T" : "t"
"U" : "u"
"V" : "v"
"W" : "w"
"X" : "x"
"Y" : "y"
"Z" : "z"
"[" : "{"
"\\" : "|"
"]" : "}"
"^" : "~"
"`" : "`"
"a" : "a"
"b" : "b"
"c" : "c"
"d" : "d"
"e" : "e"
"f" : "f"
"g" : "g"
"h" : "h"
"i" : "i"
"j" : "j"
"k" : "k"
"l" : "l"
"m" : "m"
"n" : "n"
"o" : "o"
"p" : "p"
"q" : "q"
"r" : "r"
"s" : "s"
"t" : "t"
"u" : "u"
"v" : "v"
"w" : "w"
"x" : "x"
"y" : "y"
"z" : "z"
"{" : "{"
"|" : "|"
"}" : "}"
"~" : "~"
"([({Enclosed})])" : "({({enclosed})})"
"A@B.c" : "a`b.c"

Rules

  • There is no requirement to use bitwise operations to achieve the correct output
  • Provided your output is correct for each test case input, your code is valid

Explanations are optional, but I'm more likely to upvote answers that have one.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Maximum input length (5 comments)
Why do none of the characters between space & forward slash change? Each one of them has a `0` in the... (3 comments)
Post
+1
−0

J, 39 char

Solution:

(a.{~ a.((6|.8{.1)+.(_8&{.))&.#:"0@i.])

Test example:

   (a.{~ a.((6|.8{.1)+.(_8&{.))&.#:"0@i.]) '([({Enclosed})])A@B.c'
({({enclosed})})a`b.c

How it works:

6|.8{.1 creates binary 0 0 1 0 0 0 0 0
_8&{. ensures that binari from ascii is 8 bit
(6|.8{.1)+.(_8&{.) makes third bit 1
a.((6|.8{.1)+.(_8&{.))&.#:"0@i. searches for text on right in character vector a.,...
   ...then converts to binary, then ensures third bit is 1, then, using &. reverses the binary
a.{~ converts the reversed binary, which is an ascii number, back to character text
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

If you want, you can run and share J code online using [ATO](https://ato.pxeger.com/run?1=m70wa8FOJT3... (4 comments)
If you want, you can run and share J code online using [ATO](https://ato.pxeger.com/run?1=m70wa8FOJT3...
south‭ wrote over 1 year ago

If you want, you can run and share J code online using ATO. It even has an option to paste as a code golf post, which is what I use. The header provided is a super specific way to define the function exclusively in the code body, but it is necessary. The main purpose of the header/footer is to keep the byte count in the code body accurate.

torres‭ wrote over 1 year ago

Seems cool, but I can't get it to work. The input is not giving the same output that my J installation does, and the output does not show up in the Code Golf clipboard copy.

south‭ wrote over 1 year ago

Fair enough, ATO uses J903, so I'll pull it up when I want to use a new feature since I'm too lazy to download latest. As for the output, I guess you could always add it. To each their own, tho.

torres‭ wrote over 1 year ago

I hope I didn't give the wrong impression. I really like the ATO and I wish it would have worked. I'll wait for the J update. As to the output, it's not a dealbreaker. I was planning to add it manually, but then the answer didn't match.