4
\$\begingroup\$

So I was playing around with my compose key, and found some cool things, one of them being that by pressing compose + ( + alphanumeric + ), you get that character inside a bubble, like so: .

Your task in this challenge is simple, to convert ordinary text to bubble letter text.

Here are the ascii chars, the bubble characters and their Unicode code points:

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
⓪①②③④⑤⑥⑦⑧⑨ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ
9450 9312 9313 9314 9315 9316 9317 9318 9319 9320 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423

Your input will contain only printable ascii characters, and if a character cannot be bubbleified, leave it as is.

This is , so shortest code in bytes wins!

Note: This is not isomorphic to my earlier challenge about small-caps conversion since unlike small-caps, bubble letters are in a mostly contiguous segment of code-points, allowing for more interesting approaches.

\$\endgroup\$
  • \$\begingroup\$ OK, exactly two of the letters in your title are visible on my desktop. Oddly enough, they look fine on my phone. \$\endgroup\$ – Dennis Sep 7 '16 at 3:29
  • \$\begingroup\$ Also, the last 26 characters in your table don't render at all on my desktop. You should mention which ASCII characters they map to. \$\endgroup\$ – Dennis Sep 7 '16 at 3:30
  • 2
    \$\begingroup\$ ASCII ends at 127. Do you mean, perhaps, Unicode code points (which are generally expressed in hexadecimal, "⓪" being U+24EA and so on)? \$\endgroup\$ – Jordan Sep 7 '16 at 3:33
  • \$\begingroup\$ @Jordan no, I said that the input will be ascii-only \$\endgroup\$ – Maltysen Sep 7 '16 at 3:44
  • 6
    \$\begingroup\$ I think @Jordan refers to the bubble characters and their ascii codes, which should say the bubble characters and their Unicode code points. \$\endgroup\$ – Dennis Sep 7 '16 at 3:47

14 Answers 14

10
\$\begingroup\$

Retina, 20 bytes

T`Lld`Ⓐ-⓪①-⑨

Try it online!

How it works

There's a gap between the code points of (0) and (1), but – fortunately – the character right after (z) is (0). This way, we can transliterate the character from concatenated ranges A-Za-z0-9 to the characters of the concatenated ranges (A)-(0)(1)-(9).

The rest is straightforward: T activates transliteration mode, Lld yields all uppercase ASCII letters (L), all lowercase ASCII letters (l) and all digits (d), and Ⓐ-⓪①-⑨ the corresponding bubble characters.

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

Python 3, 146 bytes

for p in list(input()):
 t=0
 if p.isdigit():t=9263
 if p=='0':t=9402
 if p.isalpha():
  t=9327
  if p.upper()==p:t=9333
 print(end=chr(ord(p)+t))

This might be able to be made shorter, any help would be appreciated. Try it on repl.it, here.

\$\endgroup\$
  • \$\begingroup\$ Where are you getting 184? I'm counting 195 with 4 spaces. Which, BTW, if you replace all the 4 spaces with one space, you could shave it down to 168, \$\endgroup\$ – DJMcMayhem Sep 8 '16 at 19:25
  • \$\begingroup\$ @DJMcMayhem I think I counted the spaces as tabs, good point, thanks! \$\endgroup\$ – nedla2004 Sep 8 '16 at 19:49
  • \$\begingroup\$ How about something like this: lambda s:''.join(chr(ord(p)+[[9263,9402],[9327,9333]][p.isalpha()][p=='0'or p.upper()==p])for p in s) (Note, I haven't tested it extensively) \$\endgroup\$ – DJMcMayhem Sep 8 '16 at 19:58
  • \$\begingroup\$ For me it tells me SyntaxError: invalid character in identifier and highlights the 9 in ​p=='0' part. Also is there a tool you use to count bytes, I can't find any. \$\endgroup\$ – nedla2004 Sep 8 '16 at 23:50
  • 1
    \$\begingroup\$ It doesn't look like you're using l after the first line, so you can put it directly into the for loop, with for p in input(): \$\endgroup\$ – isaacg Nov 1 '16 at 16:23
2
\$\begingroup\$

Jelly, 23 22 21 bytes

“2Ỵf“2Ṇ3‘r/9.ȷ_ỌFØB,y

Try it online!

How it works

“2Ỵf“2Ṇ3‘r/9.ȷ_FỌØB,y  Main link. Argument: s (string)

“2Ỵf“2Ṇ3‘              Yield [[50, 188, 102], [50, 180, 51]].
         r/            Reduce by range.
                       This yields [[50], [188, ..., 180], [102, ..., 51].
           9.ȷ_        Subtract these integers from 9500.
                       This yields [[9450], [9312, ..., 9320], [9398, ..., 9449]].
               Ọ       Unordinal; convert the resulting code points to characters.
                F      Flatten the resulting array of strings.
                       This yields the bubbles of
                       [0, ..., 9, A, ..., Z, a, ..., z].
                 ØB,   Pair "0...9A...Za...z" with the generated string.
                    y  Transliterate.
\$\endgroup\$
2
\$\begingroup\$

Bash on OSX, 27

  • 3 bytes saved thanks to @Dennis.

    tr A-Za-z0-9 Ⓐ-⓪①-⑨
    

I/O via STDIN/STDOUT. The OSX tr apparently handles these unicode characters whereas the GNU coreutils tr does not.

\$\endgroup\$
  • 1
    \$\begingroup\$ I think you can save 3 bytes with tr A-Za-z0-9 Ⓐ-⓪①-⑨. \$\endgroup\$ – Dennis Sep 7 '16 at 5:58
  • \$\begingroup\$ @Dennis Yes, thanks! \$\endgroup\$ – Digital Trauma Sep 7 '16 at 6:02
2
\$\begingroup\$

Ruby, 38 34 + 1 = 35 bytes

+1 byte for -p flag. Takes input on STDIN.

-3 bytes thanks to Dennis.

$_.tr!"A-Za-z0-9","Ⓐ-⓪①-⑨"

See it on eval.in: https://eval.in/636978

\$\endgroup\$
  • \$\begingroup\$ I think you can save 3 bytes with "A-Za-z0-9","Ⓐ-⓪①-⑨". \$\endgroup\$ – Dennis Sep 7 '16 at 5:59
  • \$\begingroup\$ @Dennis Right you are. Thanks! \$\endgroup\$ – Jordan Sep 7 '16 at 12:39
2
\$\begingroup\$

05AB1E, 19 bytes

Uses CP-1252 encoding.

žKš52Ý86+8Ý«9312+ç‡

Try it online!

Explanation

žK                    # Push the string "a-zA-Z0-9"
  š                   # switch case: "A-Za-z0-9"
   52Ý                # push range [0 ... 52]
      86+             # add 86: [86 ... 138]
         8Ý«          # concatenate with range [0 ... 8]: [86 ... 138, 0 ... 8]
            9312+     # add 9312: [9398 ... 9450, 9312 ... 9320]
                 ç    # convert to char: ['Ⓐ', ... 'Ⓩ', 'ⓐ', ..., 'ⓩ', '⓪', ..., '⑨']
                  ‡   # transliterate alphabet to bubble alphabet
\$\endgroup\$
1
\$\begingroup\$

Perl, 27 bytes

Includes +1 for -p

Give input on STDIN, uses the Dennis transliteration order. The only thing interesting about this solution is the lack of the final ; (needs a recent enough perl)

#!/usr/bin/perl -p
y;A-Za-z0-9;Ⓐ-⓪①-⑨
\$\endgroup\$
1
\$\begingroup\$

R, 140 bytes

A bit late to the party again.

x=utf8ToInt(scan(,""));a=x<58&x>48;b=x>95&x<123;c=x>64&x<91;d=x==48;x[a]=x[a]+9263;x[b]=x[b]+9327;x[c]=x[c]+9333;x[d]=x[d]+9402;intToUtf8(x)

Ungolfed

x=utf8ToInt(scan(,""));
a=x<58&x>48;
b=x>95&x<123;
c=x>64&x<91;
d=x==48;
x[a]=x[a]+9263;
x[b]=x[b]+9327;
x[c]=x[c]+9333;
x[d]=x[d]+9402;
intToUtf8(x)

Will add an explanation and try to golf this tomorrow again.

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

R, 124 91 characters

Takes input from stdin. Probably can be golfed with some cleverness. Saved some bytes by replacing the list of bubble characters with UTF code points.

chartr(paste(c(1:9,LETTERS,letters,0),collapse=""),intToUtf8(c(0:8,86:138)+9312),scan(,""))
\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6) 93 104

Edit 11 bytes saved thx @Neil again

Having to use String.fromCharCode, javascript is doomed...

s=>s.replace(/[^\W_]/g,c=>String.fromCharCode(9388+parseInt(c,36)+(-c?-77:62-c||c>'Z'&&26)))

Test

f=
s=>s.replace(/[^\W_]/g,c=>String.fromCharCode(9388+parseInt(c,36)+(-c?-77:62-c||c>'Z'&&26)))

function update() {
  O.textContent=f(I.value)
}

update()
<input id=I oninput="update()" value='Hello world!'>
<pre id=O></pre>

\$\endgroup\$
  • \$\begingroup\$ Why not add 9388 up front instead? Oh, and why aren't you using replace? \$\endgroup\$ – Neil Sep 7 '16 at 8:28
  • \$\begingroup\$ @Neil 10% saved thanks to your suggestions \$\endgroup\$ – edc65 Sep 7 '16 at 9:35
0
\$\begingroup\$

Groovy (135 Bytes)

b=(9312..9320)+(9424..9450)+(9398..9423);r=('0'..'9')+('a'..'z')+('A'..'Z');x={s->s.collect{(x=r.indexOf(it))>=0?(char)b[x]:it}}.join()

https://groovyconsole.appspot.com/script/5189010641125376

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

Java, 747 bytes

String a(String...A){for(int i=1;i<A.length-1;i+=2)A[0]=A[0].replace(A[i],A[i+1]);return A[0];}String b(String B){return a(B,"0","⓪","1","①","2","②","3","③","4","④","5","⑤","6","⑥","7","⑦","8","⑧","9","⑨","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","ⓩ","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","Ⓩ");}

If the source code may only contain ASCII characters, then replace every non-ASCII character with \uINSERTRESPECTIVECODEPOINTINHEXADECIMALHERE. Doing so results in a 933-byte program.

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

Python 3, 107.

This borrows part of its algorithm from nedla2004's answer.

lambda x:list(map(lambda p:chr(ord(p)+(((9327+6*('@'<p<'[')*p.isalpha(),9402)[p<'1'],9263)['0'<p<':'])),x))
\$\endgroup\$
0
\$\begingroup\$

Java 8, 152 bytes

s->{StringBuffer r=new StringBuffer();s.chars().forEach(c->r.appendCodePoint(c+(c>48&c<58?9263:c>64&c<91?9333:c>96&c<123?9327:c==48?9402:0)));return r;}

Explanation:

Try it online.

Explanation:

s->{                     // Method with String parameter and StringBuffer return-type
  StringBuffer r=new StringBuffer();
                         //  Resulting StringBuffer
  s.chars().forEach(c->  //  Loop over the chars of the input as integers
    r.appendCodePoint(   //   Convert int to char, and append it to the result:
      c                  //    The current character as integer
      +(c>47&c<58?       //    If it's a digit:
         c==48?          //     If it's 0 (special case)
          9402           //      Add 9402 to convert it
         :               //     Else (1-9)
          9263           //      Add 9263 to convert it
        :c>64&c<91?      //    Else-if it's an uppercase letter:
         9333            //     Add 9333 to convert it
        :c>96&c<123?     //    Else-if it's a lowercase letter:
         9327            //     Add 9327 to convert it
        :                //    Else:
         0)));           //     Leave it as is by adding 0
  return r;}             //  Return the resulting StringBuffer
\$\endgroup\$

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.