-5
\$\begingroup\$

Challenge

You will be given a string as an argument. You need to convert that string to upper case. But you can't use any built in method or function nor any external programs.

Rule

No use of built in methods or functions or external programs. Only arithmetic, bitwise, logical operators, regex, replace, split, join, ASCII codes are allowed.

Input

The string as an argument. The string can contain spaces and special characters.

Output

The string in upper case.

This is so shortest code wins.

\$\endgroup\$
11
  • \$\begingroup\$ Does "one two" become "One two", "One Two", or "ONE TWO"? \$\endgroup\$
    – PkmnQ
    Mar 8, 2020 at 8:21
  • \$\begingroup\$ "ONE TWO" @Want \$\endgroup\$
    – Wasif
    Mar 8, 2020 at 8:21
  • 3
    \$\begingroup\$ Can contain spaces and special characters : does that include code points \$\ge127\$? \$\endgroup\$
    – Arnauld
    Mar 8, 2020 at 8:46
  • 2
    \$\begingroup\$ We can assume that any keyboard is acceptable? \$\endgroup\$
    – ouflak
    Mar 8, 2020 at 9:07
  • 2
    \$\begingroup\$ I still think this question is unclear. What is allowed and not allowed is only vaguely explained. But additionally since special characters must be supported it is unclear what characters need to be made "upper case" and what that means. E.g. do we need to make á into Á? \$\endgroup\$
    – Wheat Wizard
    Mar 16, 2020 at 20:31

13 Answers 13

2
\$\begingroup\$

Japt, 5 bytes

;dCíB

Try it here

\$\endgroup\$
1
  • 2
    \$\begingroup\$ @Downvoters, please have the decency to leave I comment! \$\endgroup\$
    – Shaggy
    Mar 16, 2020 at 21:12
1
\$\begingroup\$

Turing Machine Code, 279 bytes

0 q Q r 0
0 w W r 0
0 e E r 0
0 r R r 0
0 t T r 0
0 y Y r 0
0 u U r 0
0 i I r 0
0 o O r 0
0 p P r 0
0 a A r 0
0 s S r 0
0 d D r 0
0 f F r 0
0 g G r 0
0 h H r 0
0 j J r 0
0 k K r 0
0 l L r 0
0 z Z r 0
0 x X r 0
0 c C r 0
0 v V r 0
0 b B r 0
0 n N r 0
0 m M r 0
0 _ _ r 0
0 * * r 0

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Keg, 14 bytes

(&az⑻•[& -|&],

Try it online!

Finally! A challenge Keg was designed for! This utilises the fact that a) subtracting 32 from the ordinal value of any lower-case letter gives its upper-case counterpart and b) characters are treated as numbers when arithmetic is applied.

The unicode part is to ensure the letter is in the lower case range, without using built-ins.

\$\endgroup\$
1
  • \$\begingroup\$ Hey @Downvoters, at least be courteous enough to leave a comment explaining what y'all think is wrong here. \$\endgroup\$
    – lyxal
    Mar 16, 2020 at 21:59
1
\$\begingroup\$

05AB1E, 8 5 bytes

(Once again, a'_' uses something that I didn't know even existed in 05AB1E.)

AžpR‡

Explanation

       # Implicit input
A      # Push lowercase alphabet
 žp    # Push uppercase alphabet reversed
   R   # And reverse it again
    ‡  # Transliterate
     J # Join list

Try it online!

Original solution without ‡, 19 18 bytes

εDAskD®ÊižpRèës}}J

Try it online!

Explanation

                   # Implicit input
ε               }  # Loop on each character
εD              }  # Duplicate
ε A             }  # Push lowercase alphabet
ε  s            }  # Swap
ε   k           }  # Find index of character in alphabet
ε    D          }  # Duplicate for comparison
ε     ®         }  # Push -1 (see link below)
ε      Ê        }  # Check if equal
ε       i    ë }}  # If-else statement
ε       ižp  ë }}  # Push uppercase alphabet in reverse
ε       i  R ë }}  # Reverse the string (so now it's just the uppercase alphabet)
ε       i   èë }}  # Index the uppercase alphabet
ε       i    ës}}  # Swap to get character
                 J # Join all the items

If you're wondering why ® returns -1, go here

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 5B. (Ab)uses the transliteration. \$\endgroup\$
    – user92069
    Mar 8, 2020 at 10:13
  • \$\begingroup\$ FYI I can do it without transliteration in 13 bytes: εDAus«sAskè}J. \$\endgroup\$
    – Neil
    Mar 8, 2020 at 11:00
  • 1
    \$\begingroup\$ @Neil this uses the built-in u, making it invalid. 14 bytes using žpR instead of Au. \$\endgroup\$
    – Grimmy
    Mar 9, 2020 at 13:16
1
\$\begingroup\$

Batch, 245 116 Bytes

@Set v=%~1
@for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)do @call set v=%%v:%%A=%%A%%
@ECHO(%v%

Somewhat ugly and brute forced, using a for loop to enact substring modification on each instance of a character. 129 bytes dropped thanks to Neil

\$\endgroup\$
5
  • \$\begingroup\$ Hey thanks for submission. It works, but it's way too long (245 bytes!) \$\endgroup\$
    – Wasif
    Mar 8, 2020 at 8:41
  • \$\begingroup\$ indeed, but that's batch. no means within the language of batch to shorten it further. (I have 0 expectations of providing the shortest answer) \$\endgroup\$
    – T3RR0R
    Mar 8, 2020 at 8:44
  • \$\begingroup\$ @set/pv= is a slightly golfier way to take input. \$\endgroup\$
    – Neil
    Mar 8, 2020 at 10:40
  • \$\begingroup\$ Substring replacement is case-insensitive in Batch, so you can simply use @for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)do @call set v=%%v:%%A=%%A%% (using call also removes the need to enable delayed expansion). \$\endgroup\$
    – Neil
    Mar 8, 2020 at 10:42
  • \$\begingroup\$ One of those little details I clean forgot. Answer updated. \$\endgroup\$
    – T3RR0R
    Mar 8, 2020 at 11:12
1
\$\begingroup\$

Erlang (escript), 56 bytes

Numeric lists are strings in Erlang. (9 bytes away from C, let's see if I can get this shorter.)

f([H|T])->[H-if H>97,H<122->32;1<2->0end]++f(T);f(N)->N.

Try it online!

Explanation

f([H | T]) -> % Try to split the input into head & tail
[H -          % Subtract the current item by:
if
  H > 97, H < 122 -> 32;
              % If the item's ord code is in the lowercase letter range:Return 32
  1 < 2 -> 0  % Otherwise, return 0. 1<2 is 1 byte shorter than true.
end 
] ++ f(T);    % Concatenate with the uppercased tail


f(N) -> N.    % If the tail is the null list (i.e. it can't be splitted):
              % Return this operand.
```
\$\endgroup\$
0
1
\$\begingroup\$

Bash + core utilities, 10 bytes

tr a-z A-Z

Try it online!

\$\endgroup\$
1
\$\begingroup\$

4, 54 bytes

Thanks to @PkmnQ for pointing out the bug!

3.6993269897697017008003010098801100009960100950070094

Try it online!

4, 28 bytes (old answer, only supports lower case and nothing else XD)

3.69932700800100009950070094

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Cool, but if you input a capital letter it becomes gibberish. \$\endgroup\$
    – PkmnQ
    Mar 8, 2020 at 10:36
  • \$\begingroup\$ Welp, fix is underway \$\endgroup\$
    – vdmx
    Mar 8, 2020 at 10:43
1
\$\begingroup\$

C (gcc), 47 45 bytes

Saved 2 bytes thanks to ceilingcat!!!

f(char*s){for(;*s;++s)*s^=*s>96&*s<123?32:0;}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ @ceilingcat That's the way to golf if statement followed by assignment - thanks! :-) \$\endgroup\$
    – Noodle9
    Mar 9, 2020 at 21:29
0
\$\begingroup\$

APL+WIN, 28 bytes

Prompts for string:

⎕av[i-32×(i←⎕av⍳⎕)∊(97+⍳26)]

Converts string to relevant indices in APL's atomic vector, identifies indices of lower case letters, decrements only those indices by 32 and converts resulting string back to characters.

\$\endgroup\$
1
  • \$\begingroup\$ @a'_' Not sure. The rules state ascii codes are supported and that is effectively what is in the APL atomic vector. \$\endgroup\$
    – Graham
    Mar 8, 2020 at 9:50
0
\$\begingroup\$

Charcoal, 9 bytes

⭆S§⁺αι⌕βι

Try it online! Link is to verbose version of code. Only 7 bytes longer than the built-in! Explanation:

 S          Input string
⭆           Map over characters and join
      ⌕     Find index in
       β    Lowercase alphabet of
        ι   Current character
  §         Cyclically index into
   ⁺        Concatenation of
    α       Uppercase alphabet
     ι      Current character
            Implicitly print

If the input character is not found in the lowercase alphabet, the returned index is -1, which represents the last character when passed to the cyclic index function.

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

Retina, 5 bytes

T`l`L

Try it online!

Transliterate lower case letters into upper case Letters.

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

16/32/64-bit x86 assembly language, 17 bytes

AC    l1: lodsb
3C 61     cmp   al, 'a'
72 06     jb    l2
3C 7A     cmp   al, 'z'
77 02     ja    l2
24 DF     and   al, 0dfh ;convert to uppercase
AA    l2: stosb
84 C0     test  al, al
75 F0     jne   l1
C3        ret

Call with (r/e)si pointing to source string, (r/e)di to destination buffer to hold converted text.

\$\endgroup\$
2
  • \$\begingroup\$ why was this downvoted? This seems like a perfectly valid answer to me. Oh well, at least I can help get you back up to 0... \$\endgroup\$
    – 640KB
    Feb 5, 2021 at 2:25
  • \$\begingroup\$ Right, yes. I was 6502 coding right before that. \$\endgroup\$ Feb 5, 2021 at 19:21

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