29
\$\begingroup\$

The goal of this code-golf is to create a code that lets the user input an ASCII string (contains only printable ASCII characters), and your program outputs the lower-case variant of this string.

Important: you are NOT allowed to use a built-in function that converts the string (or just one character) to lowercase (such as ToLower() in .NET, strtolower() in PHP , ...)! You're allowed to use all other built-in functions, however.

Another important note: The input string doesn't contain only uppercase characters. The input string is a mix of uppercase characters, lowercase characters, numbers and other ASCII printable characters.

Good luck!

\$\endgroup\$
10
  • 5
    \$\begingroup\$ unfortunately, I'll have to opt-out. I'm not a beginner. \$\endgroup\$ Commented Oct 6, 2013 at 13:42
  • \$\begingroup\$ @Jan: Well, with beginner I actually meant that the skill level of this would be 'beginner', not that only beginners would be allowed to enter. I removed the word 'beginner' and surely, you're allowed to enter. \$\endgroup\$
    – ProgramFOX
    Commented Oct 6, 2013 at 13:45
  • 1
    \$\begingroup\$ Are regular expressions allowed? Only GolfScript could beat s/./\L\0/g. \$\endgroup\$
    – manatwork
    Commented Oct 6, 2013 at 13:49
  • 4
    \$\begingroup\$ @manatwork: surely \L is built in? \$\endgroup\$
    – marinus
    Commented Oct 6, 2013 at 13:50
  • \$\begingroup\$ @manatwork: Yes, a regex is allowed. \$\endgroup\$
    – ProgramFOX
    Commented Oct 6, 2013 at 13:50

63 Answers 63

1 2
3
0
\$\begingroup\$

Thunno 2, 2 bytes

RP

Attempt This Online! Port of user8777's Python answer.

Thunno 2, 4 bytes

kAẠṆ

Attempt This Online! No uppercase/swap-case built-ins here.

Thunno 2, 12 bytes

ıDkAsƇ?C32+C

Attempt This Online! No uppercase/swap-case/transliterate built-ins here.

Explanation

RP  # Implicit input
R   # Convert to uppercase
 P  # Swap the case of each character
    # Implicit output
kAẠṆ  # Implicit input
   Ṇ  # Transliterate the input
kA    # (from) the uppercase alphabet
  Ạ   # (to) the lowercase alphabet
      # Implicit output
ıDkAsƇ?C32+C  # Implicit input
ı             # Map over the input string:
 D            #  Duplicate it
    sƇ        #  Pop one copy, and check if it's in
  kA          #  the uppercase alphabet
      ?       #  If it is:
       C      #   Convert to codepoint
        32+   #   Add 32
           C  #   And convert to character
              #  Otherwise, the character stays on top
              # Implicit output, joined
\$\endgroup\$
0
\$\begingroup\$

Japt, 7 5 bytes

;dBíC

Try it here

\$\endgroup\$
0
\$\begingroup\$

Itr, 17 bytes

#µ»ä26¹64+=S32*+«

Reads string (surrounded by quotes) from standard input, prints the result to standard output

online interpreter

Explanation

#             ; read the string from standard input
 µ»   «       ; apply to each element
              ; implicitly print the result

ä             ; duplicate the character
 26¹64+       ; push the range from 65 to 90 ('A' through 'Z')
       =      ; vectorized equality check (of character and range)
        S     ; sum up the vector (1 if the char is in range, 0 otherwise)
         32*+ ; multiply by 32 and add to the character
```
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.