# Sᴍᴀʟʟ Cᴀᴘꜱ Cᴏɴᴠᴇʀᴛᴇʀ

Iɴꜱᴘɪʀᴇᴅ ʙʏ @ConorO'Brien's ᴜꜱᴇʀɴᴀᴍᴇ.

Aʟꜱᴏ ᴛʜᴀɴᴋꜱ ᴛᴏ @Dᴏᴏʀᴋɴᴏʙ ꜰᴏʀ ꜱʜᴏᴡɪɴɢ ᴍᴇ ᴛʜᴇ ᴇxɪꜱᴛᴇɴᴄᴇ ᴏꜰ ǫ ᴀɴᴅ x.

Sᴍᴀʟʟ Cᴀᴘꜱ ᴀʀᴇ ᴘʀᴇᴛᴛʏ ᴄᴏᴏʟ. Tʜᴇʏ ᴀʀᴇ ᴜɴɪᴄᴏᴅᴇ ᴄʜᴀʀᴀᴄᴛᴇʀꜱ ᴛʜᴀᴛ ʀᴇᴘʟᴀᴄᴇ ꜱᴍᴀʟʟ ʟᴇᴛᴛᴇʀꜱ. Tʜᴇʏ ʟᴏᴏᴋ ᴊᴜꜱᴛ ʟɪᴋᴇ ᴛʜᴇ ᴄᴀᴘɪᴛᴀʟ ᴏɴᴇꜱ, ʙᴜᴛ ꜱᴍᴀʟʟᴇʀ, ᴀɴᴅ ʟᴏᴏᴋ ʀᴇᴀʟʟʏ ᴏꜰꜰɪᴄɪᴀʟ. Yᴏᴜʀ ᴛᴀꜱᴋ ɪꜱ ᴛᴏ ᴡʀɪᴛᴇ ᴀ ᴘʀᴏɢʀᴀᴍ ᴛʜᴀᴛ ᴄᴏɴᴠᴇʀᴛꜱ ʀᴇɢᴜʟᴀʀ ᴛᴇxᴛ ɪɴᴛᴏ ꜱᴍᴀʟʟ ᴄᴀᴘꜱ.

Hᴇʀᴇ ɪꜱ ᴀ ʟɪꜱᴛ ᴏꜰ ᴛʜᴇ ᴜɴɪᴄᴏᴅᴇ ᴄʜᴀʀᴀᴄᴛᴇʀꜱ ꜰᴏʀ ꜱᴍᴀʟʟ ᴄᴀᴘꜱ:

ᴀ ʙ ᴄ ᴅ ᴇ ꜰ ɢ ʜ ɪ ᴊ ᴋ ʟ ᴍ ɴ ᴏ ᴘ ǫ ʀ ꜱ ᴛ ᴜ ᴠ ᴡ x ʏ ᴢ


## Cʟᴀʀɪꜰɪᴄᴀᴛɪᴏɴꜱ

• Rᴇɢᴜʟᴀʀ ᴄᴀᴘꜱ ʀᴇᴍᴀɪɴ ʀᴇɢᴜʟᴀʀ ᴄᴀᴘꜱ ᴀɴᴅ ꜱᴏ ᴅᴏ ᴘᴜɴᴄᴛᴜᴀᴛɪᴏɴꜱ, ꜱᴘᴀᴄᴇꜱ, ᴇᴛᴄ.
• Iɴᴘᴜᴛ ᴄᴀɴ ʙᴇ ᴍᴜʟᴛɪᴘʟᴇ ʟɪɴᴇꜱ.
• Tʜɪꜱ ɪꜱ , ꜱᴏ ꜱʜᴏʀᴛᴇꜱᴛ ᴄᴏᴅᴇ ɪɴ ʙʏᴛᴇꜱ ᴡɪɴꜱ!

## Tᴇꜱᴛ Cᴀꜱᴇꜱ

Hello World -> Hᴇʟʟᴏ Wᴏʀʟᴅ

abcdefghijklmnopqrstuvwxyz -> ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ

Welcome to Programming Puzzles and Code Golf Stackexchange!
It is a website ->
Wᴇʟᴄᴏᴍᴇ ᴛᴏ Pʀᴏɢʀᴀᴍᴍɪɴɢ Pᴜᴢᴢʟᴇꜱ ᴀɴᴅ Cᴏᴅᴇ Gᴏʟꜰ Sᴛᴀᴄᴋᴇxᴄʜᴀɴɢᴇ!
Iᴛ ɪꜱ ᴀ ᴡᴇʙꜱɪᴛᴇ.

• What are all of those boxes? I think they are ss... – Justin Oct 12 '15 at 2:29
• F and S are boxes for me. The rest are fine, for some reason. – El'endia Starman Oct 12 '15 at 2:30
• I feel obligated fo answer, now. :P – Conor O'Brien Oct 12 '15 at 2:57
• Any ideas what the font situation is that causes the F and S not to render for a lot of us? – Loren Pechtel Oct 12 '15 at 4:27
• There is no dedicated Unicode character range for "small caps". The letters are taken from several different character ranges, intended for phonetic pronunciations. Therefore, the character codes are out of order (making this programming task more interesting), and fonts may have support for some, but not others. The missing F and S is because your font has support for the IPA Extensions and Phonetic Extensions Unicode block, but not the Latin Extended-D block, which is where small F and S are defined. – David Yaw Oct 12 '15 at 4:37

# Retina, 73 bytes

Ta-zᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ


This is exactly what Retina's transliterate mode was made for. It replaces all lowercase letters (a-z) with their corresponding small caps version. Annoyingly, the character codes of the small caps characters are all over the place, so it can't take advantage of ranges for the second part: ideally it would be Ta-zᴀ-ᴢ.

Try it online.

• It's not really surprising - what's surprising, bearing in mind the rules for what gets to be a unicode character, is that all of the small caps characters are defined in the first place. – Random832 Oct 12 '15 at 13:52
• It's not surprising. You can see the same in Unicode subscript and superscript characters. ¹, ² and ³ exist in ISO-8859-1 long before Unicode, so they are in a separated block from the rest digits and letters – phuclv Oct 12 '15 at 14:03

# Pyth, 6159 58 bytes

LXbGsmC+*7389<dGCd"#ʙ'(*ꜰɢʜɪ-.ʟ0ɴ2;ǫʀꜱ>?CDxʏE


This defines a named function y. Try it online in the Pyth Compiler/Executor.

The code contains no unprintable characters.

### Idea

Among the small caps, there are 14 characters in the range 7424 – 7458, and all of them require three bytes to be stored verbatim. By subtracting 7389 from their code points, we map them in the printable ASCII range 35 – 69, so each of them will occupy only one byte.

To decode the string, we simply add 7389 to the code points of all characters that come before a.

### Code

L                       Define y(b):
Xb                       Transliterate b...
G                      by replacing the lowercase ASCII letters...
with the characters of result of the following:
m            "…          Map; for each d in that string:
*7389<dG              Calculate (7389 * (d < 'abc...xyz')).
+        Cd            Add the product to int(d).
C                       Cast to character.
s                       Turn the resulting char array into a string.


## Javascript (ES6), 114 bytes

a=>a.replace(/[a-z]/g,b=>'ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ'[b.charCodeAt()-97])

// snippet
var o = document.getElementById("o");
var t = document.getElementById("t");
t.onkeyup = _=>o.textContent = (a=>a.replace(/[a-z]/g,b=>'ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ'[b.charCodeAt()-97]))(t.value);
<!-- snippet -->
<input id="t" placeholder='Sample Text' />
<pre id="o"></pre>

• Unless you're targetting IE8 or earlier, I'd suggest preferring oninput to onkeyup. – Neil Oct 15 '15 at 19:56
• @Neil ok, will do in the future – DankMemes Oct 15 '15 at 20:20

# CJam, 78746766 63 bytes

q'{,97>"#ʙ'(*ꜰɢʜɪ-.ʟ0ɴ2;ǫʀꜱ>?CDxʏE"{_'a<7389*+}%er


This uses the same idea as my other answer.

The code contains no unprintable characters. Try it online in the CJam interpreter.

### How it works

q       e# Read all input and push it on the stack.
'{,     e# Push the range of all characters up to 'z'.
97>     e# Remove the first 97 characters. This leaves lowercase letters.

"#ʙ'(*ꜰɢʜɪ-.ʟ0ɴ2;ǫʀꜱ>?CDxʏE"

{       e# Map; for each character in that string:
_'a<  e#   Check if a copy of the character is lower than 'F'. Pushes 1 or 0.
7389* e#   Multiply the resulting Boolean by 7389.
+     e#   Add the product to the character's code point.
}%      e#
er      e# Perform transliteration; replace each letter in the input by the
e# corresponding character of the modified string.


## ><>, 118 116 Bytes

I'll try to think of a way to remove that entire alphabet from my code later.

I haven't been able to test it with newlines, but I see no reason for it not working with them.

!oi:0(?;::"{"($"")*0$.
v"a"%&"ᴢʏxᴡᴠᴜᴛꜱʀǫᴘᴏɴᴍʟᴋᴊɪʜɢꜰᴇᴅᴄʙᴀ"&
>:?!v1-$~ ~00.>  Try it online. Emoticons found in the code: 0:(, :0, :"{, >:, 0=, and the debatable ones: i:, >:?, :?, ?; • Oh wow i love how you used the true/false results for the jump position! You can shave off 2 bytes by using >:?!v1-$~ and ~00.> as your last 2 lines – torcado Oct 12 '15 at 6:06
• @torcado Thanks, changing now. – cole Oct 12 '15 at 12:54
• More emoticons: :0(, :? – DanTheMan Oct 12 '15 at 20:20
• @DanTheMan I was debating those but I guess I'll add them. – cole Oct 13 '15 at 3:51

# Python 3, 140 bytes

import sys;print(sys.stdin.read().translate(dict(zip(range(97,123),'ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ'))))


Try it online!

Hooray for built-in Unicode support! Now works with multi-line input.

-10 bytes thanks to @Bakuriu

• why not {x for x in zip(range(97,123), ...)}? afaik this is the same length of what you have, but now you can shorten the code by using dict(zip(...)) resulting in 10 less bytes or so. – Bakuriu Oct 12 '15 at 19:34
• @FelipeNardiBatista input() only takes single-line input. The challenge specifies that multi-line input needs to be handled. – Mego May 29 '17 at 16:27

# Julia, 126 bytes

t->join([(i=Int(c);96<i<123?split("ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ","")[i-96]:c)for c=t])


Ungolfed:

function f(t::AbstractString)
# Split the small caps into an array (this particular Unicode
# string does not like to be indexed for whatever reason)
s = split("ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ", "")

# Create an array with replaced letters
r = [(i = Int(c); 96 < i < 123 ? s[i-96] : c) for c in t]

# Join the array back into a string
join(r)
end

• Where does AbstractString fit into the golfed code? – clap Dec 12 '15 at 20:33
• @VoteToSpam It doesn't; it's just there in the ungolfed code to illustrate the type of input that's expected. It's entirely unnecessary beyond that. – Alex A. Dec 12 '15 at 20:47

## Perl 5, 84 bytes

(83 bytes script and -p)

use utf8;y/a-z/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/


Nothing particularly different, but it's worth noting the necessity of the use utf8; statement to get legible text. A warning is displayed as well, but I believe the consensus is that they are acceptable:

$perl -p smallcaps.pl <<< 'Programming Puzzles and Code Golf' Wide character in print, <> line 1. Pʀᴏɢʀᴀᴍᴍɪɴɢ Pᴜᴢᴢʟᴇꜱ ᴀɴᴅ Cᴏᴅᴇ Gᴏʟꜰ$perl -p smallcaps.pl <<< 'Programming Puzzles and Code Golf' 2> /dev/null
Pʀᴏɢʀᴀᴍᴍɪɴɢ Pᴜᴢᴢʟᴇꜱ ᴀɴᴅ Cᴏᴅᴇ Gᴏʟꜰ


## Perl, 80 bytes

(74 bytes script and -pMutf8)

Thanks @hobbs!

y/a-z/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/


# Java, 306275217215 189 bytes

Well, Java is definetely not the best language to accomplish this task in... but, here it is anyway:

void p(String s){for(int i=1;i<27;s=s.replace("abcdefghijklmnopqrstuvwxyz".charAt(++i),"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ".charAt(i)));System.out.print(s);


Thanks to @ThomasKwa and @DHall for help in shaving off 91 characters!

• @ThomasKwa it probably can be golfed more, but the unicode shoots up the byte count. – GamrCorps Oct 12 '15 at 4:29
• @ThomasKwa Yep, you were right. Had some debug code left in there.... – GamrCorps Oct 12 '15 at 14:07
• a couple hints to improve this further: 1)string.replace(str1, str2) replaces ALL instances of str1 with str2, and returns the original string as is if str1 isn't found. 2)this is O(n), can you make it O(1) ? – DHall Oct 12 '15 at 17:01
• @DHall looking over it, str.replace() would likely be shorter. At work now so I'll try to fix it once I get home. – GamrCorps Oct 12 '15 at 17:14
• Ignore my previous deleted comment, I misread the specs. However, you can still golf it like this void p(String s){for(char c:s.toCharArray())System.out.print(c>96&c<123?"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ".charAt(c-97):c);} (PS: You're missing a closing bracket (}) in your current answer.) – Kevin Cruijssen May 29 '17 at 12:19

## 05AB1E, 73 bytes (non-competing)

A"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"‡


Try it online!

Explanation:

A                              - Push a-z
"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"   - Push "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"
‡ - Pop a, b, c Push a.transliterate(b -> c)


## Perl 6, 78 bytes

The simplest command line version:

$perl6 -pe'tr/a..z/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/' # 76 + 2 = 78  It gets a bit larger if you put it into a file. $_=\$*IN.slurp-rest;tr/a..z/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/;.print # 102


# Sacred JavaScript ES6, 600 Bytes

( ))) ) )( ) ))( ))) () (((  (( ()((( ))( )  ( )() (((( () ) () ( () )( )(( ((() () (((  (( ()((( (( (((((((() ) )( ) ))((  )( ) )((( ) ( () )( )(( ) (( ) ( ()(((((( (((( ()() )    ((() ( () () (( )( ( )) ((   ((    (((( ()(  ((() () (((  (( ()((( (( (((( (((((( () (())( ) ) ((() ) )( ) )) ( )((()))) ())() ( () ((() )  ( ()((()() ) )(()) ()(  ()( () )()()(( () )(()(()())()   ()()) ( ( ) ()))))    )  (()  ()(((( )  )()  )  ( )(( ( (( ) )( ((  ((()( ( ((((() () (( )  ( )()( ()((( )  )((((( ( ( ) (( ) ) )( )(( )) (((( ((() ()   ) (  )  (( (( ((()(((()((((() ((() () (( ))((( ( ( )) ((  )( () ( ()


Here's a cool image:

# JavaScript ES6, 120 Bytes

This is the code.

k=>k.match(/./g).map(z=>new Array(26) .fill(0).map((q,e)=>"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"[e])[z.charCodeAt()-97]||z).join)


This is the snippet.

while(1)alert(prompt().match(/./g).map(z=>new Array(26) .fill(0).map((q,e)=>"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"[e])[z.charCodeAt()-97]||z).join

# Julia, 105 bytes

t->map(c->96<c<123?["ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"...][c-'']:c,t)


This is simple - for each character in t, it checks to see if the character, c, is lowercase (96<c<123) - if it is, it subtracts the character with value 96 ('') from the character, and looks up the corresponding character in the array [ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"...]. If it's not lowercase, then just use c itself. The map function applies this procedure for each character in the string.

Alternative, if we can restrict input to ASCII less than 127:

### Julia, 104 bytes

t->join(['\1':'';"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ{|}~"...][t.data])


In this case, the array is longer, including all characters between ASCII 1 ('\1') and 126 ('~'), with the lowercase letters replaced as appropriate - it then uses the characters in t, expressed as unsigned integers (t.data), to lookup the values in the array, and joins the new characters back into a string at the end.

# Scala, 125 bytes

(s:String)=>s.map(c=>('a'to'z'zip "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"toMap).getOrElse(c,c))


An anonymous function that has string as an input and output. Iterate through its chars and get the unicode version of them by matching them from dict/map. Return original char if the unicode one doesn't exist.

### Usage

1. Open Scala REPL and paste the code above
2. It will create a function (resX) that can be called by passing a string (e.g. resX("my String"))

# Sed, 97 bytes

y/abcdefghijklmnopqrstuvwxyz/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/

• I am not a sed user but can abcdefghijklmnopqrstuvwxyz be replaced with a-z to save many bytes? – clap Oct 14 '15 at 4:20
• No, sadly it can't. I didn't post this as something competitive with the best solutions here, just because it's something easy to do with sed. It's also a good test of sed - broken, non-multibyte-aware sed implementations like the one in busybox (and perhaps ones in some proprietary unices?) will likely fail to run it. – R.. GitHub STOP HELPING ICE Oct 14 '15 at 4:25
• Okay, that is a shame. Great answer, though! – clap Oct 14 '15 at 4:35

# Lua, 160 bytes

function c(a)
return a:lower():gsub("%w",function(d)b=a.byte(d)-96;return("ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"):sub(b,b)end)end

• I'm not a Lua programmer, but i guess return("ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ") can be transformed to return"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ" to save 2 bytes – TuxCrafting Jun 14 '16 at 10:20

# Japt, 8180 78 bytes

"%a"@"ʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢᴀʙᴄᴅᴇꜰɢ"gXc


Try it online

• If you move ᴀʙᴄᴅᴇꜰɢ to the end of the string you can remove the 7+` :-) – ETHproductions May 29 '17 at 16:16
• So I can. Thanks, once again, @ETHproductions :) – Shaggy May 29 '17 at 16:27