45
\$\begingroup\$

Portable Spec.

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ᴛ ɪꜱ ᴀ ᴡᴇʙꜱɪᴛᴇ.
\$\endgroup\$
  • 6
    \$\begingroup\$ What are all of those boxes? I think they are ss... \$\endgroup\$ – Justin Oct 12 '15 at 2:29
  • 80
    \$\begingroup\$ F and S are boxes for me. The rest are fine, for some reason. \$\endgroup\$ – El'endia Starman Oct 12 '15 at 2:30
  • 9
    \$\begingroup\$ I feel obligated fo answer, now. :P \$\endgroup\$ – Conor O'Brien Oct 12 '15 at 2:57
  • 9
    \$\begingroup\$ Any ideas what the font situation is that causes the F and S not to render for a lot of us? \$\endgroup\$ – Loren Pechtel Oct 12 '15 at 4:27
  • 50
    \$\begingroup\$ 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. \$\endgroup\$ – David Yaw Oct 12 '15 at 4:37

18 Answers 18

1
\$\begingroup\$

Japt, 81 80 78 bytes

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

Try it online

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

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

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Bakuriu Oct 12 '15 at 19:34
  • \$\begingroup\$ @FelipeNardiBatista input() only takes single-line input. The challenge specifies that multi-line input needs to be handled. \$\endgroup\$ – Mego May 29 '17 at 16:27
4
\$\begingroup\$

05AB1E, 73 bytes (non-competing)

Yet again, I wish Adnan had published this language earlier.

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

Try it online!

Explanation:

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

Retina, 73 bytes

T`a-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 T`a-z`ᴀ-ᴢ.

Try it online.

\$\endgroup\$
  • 6
    \$\begingroup\$ 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. \$\endgroup\$ – Random832 Oct 12 '15 at 13:52
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – phuclv Oct 12 '15 at 14:03
3
\$\begingroup\$

Sacred JavaScript ES6, 600 Bytes

Hey look, I answered!

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

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``

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

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

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
\$\endgroup\$
12
\$\begingroup\$

CJam, 78 74 67 66 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.
\$\endgroup\$
26
\$\begingroup\$

Pyth, 61 59 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.
\$\endgroup\$
4
\$\begingroup\$

Java, 306 275 217 215 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!

\$\endgroup\$
  • 2
    \$\begingroup\$ @ThomasKwa it probably can be golfed more, but the unicode shoots up the byte count. \$\endgroup\$ – GamrCorps Oct 12 '15 at 4:29
  • \$\begingroup\$ @ThomasKwa Yep, you were right. Had some debug code left in there.... \$\endgroup\$ – GamrCorps Oct 12 '15 at 14:07
  • 1
    \$\begingroup\$ 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) ? \$\endgroup\$ – DHall Oct 12 '15 at 17:01
  • \$\begingroup\$ @DHall looking over it, str.replace() would likely be shorter. At work now so I'll try to fix it once I get home. \$\endgroup\$ – GamrCorps Oct 12 '15 at 17:14
  • \$\begingroup\$ 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.) \$\endgroup\$ – Kevin Cruijssen May 29 '17 at 12:19
2
\$\begingroup\$

Sed, 97 bytes

y/abcdefghijklmnopqrstuvwxyz/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/
\$\endgroup\$
  • \$\begingroup\$ I am not a sed user but can abcdefghijklmnopqrstuvwxyz be replaced with a-z to save many bytes? \$\endgroup\$ – clap Oct 14 '15 at 4:20
  • \$\begingroup\$ 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. \$\endgroup\$ – R.. Oct 14 '15 at 4:25
  • \$\begingroup\$ Okay, that is a shame. Great answer, though! \$\endgroup\$ – clap Oct 14 '15 at 4:35
2
\$\begingroup\$

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"))
\$\endgroup\$
9
\$\begingroup\$

><>, 118 116 Bytes

-2 bytes thanks to @torcado.

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:, >:?, :?, ?;

\$\endgroup\$
  • 2
    \$\begingroup\$ 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 \$\endgroup\$ – torcado Oct 12 '15 at 6:06
  • \$\begingroup\$ @torcado Thanks, changing now. \$\endgroup\$ – cole Oct 12 '15 at 12:54
  • \$\begingroup\$ More emoticons: :0(, :? \$\endgroup\$ – DanTheMan Oct 12 '15 at 20:20
  • \$\begingroup\$ @DanTheMan I was debating those but I guess I'll add them. \$\endgroup\$ – cole Oct 13 '15 at 3:51
6
\$\begingroup\$

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ʏᴢ/
$perl -pMutf8 -e'y/a-z/ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ/' <<< 'Programming Puzzles and Code Golf' 2> /dev/null
Pʀᴏɢʀᴀᴍᴍɪɴɢ Pᴜᴢᴢʟᴇꜱ ᴀɴᴅ Cᴏᴅᴇ Gᴏʟꜰ
\$\endgroup\$
  • \$\begingroup\$ Subtract 9 for use utf8; and add 5 for -Mutf8. \$\endgroup\$ – hobbs Oct 12 '15 at 17:39
  • \$\begingroup\$ @hobbs Of course! I did play with that earlier, but I'm often unsure how to score correctly when abusing a lot of the commandline switches... I'll add that in! \$\endgroup\$ – Dom Hastings Oct 12 '15 at 17:47
2
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

Ruby, 89 bytes

p ARGV[0].tr "a-z","ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"

To use:

ruby <file-name> "<string>"
\$\endgroup\$
  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! I'm not sure if surrounding the output in quotes is allowed, but you can save a few bytes by turning your code into a lambda. ->s{s.tr"a-z","ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ"} is only 84 bytes. \$\endgroup\$ – Dennis Oct 12 '15 at 13:09
  • \$\begingroup\$ (After reading the question again, I'm not sure function are allowed. A few answers are using functions. I'll request clarification from the OP.) \$\endgroup\$ – Dennis Oct 12 '15 at 13:13
  • 1
    \$\begingroup\$ you can replace p ARGV[0] with p$*[0] to save 3. ` \$\endgroup\$ – AShelly Oct 13 '15 at 16:13
6
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Where does AbstractString fit into the golfed code? \$\endgroup\$ – clap Dec 12 '15 at 20:33
  • \$\begingroup\$ @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. \$\endgroup\$ – Alex A. Dec 12 '15 at 20:47
12
\$\begingroup\$

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>

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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