Convert to Bubble Letters

5

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.

Maltysen

Posted 2016-09-07T03:27:21.873

Reputation: 25 023

OK, exactly two of the letters in your title are visible on my desktop. Oddly enough, they look fine on my phone. – Dennis – 2016-09-07T03:29:22.430

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. – Dennis – 2016-09-07T03:30:42.503

2

ASCII ends at 127. Do you mean, perhaps, Unicode code points (which are generally expressed in hexadecimal, "⓪" being U+24EA and so on)?

– Jordan – 2016-09-07T03:33:52.250

@Jordan no, I said that the input will be ascii-only – Maltysen – 2016-09-07T03:44:11.237

I'm pretty sure that this is a duplicate, but I can't find it... – acrolith – 2016-09-07T03:44:31.193

@Dennis added ascii to table. – Maltysen – 2016-09-07T03:46:31.410

6I think @Jordan refers to the bubble characters and their ascii codes, which should say the bubble characters and their Unicode code points. – Dennis – 2016-09-07T03:47:18.813

Note: The numeric version of this challenge (i.e. converting numbers instead of letters to bubble) was in the sandbox somewhere, but never made it to main due to small caps. – Sp3000 – 2016-09-07T04:50:27.657

Possible duplicate of Sᴍᴀʟʟ Cᴀᴘꜱ Cᴏɴᴠᴇʀᴛᴇʀ

– Mego – 2016-09-07T06:53:40.420

Answers

11

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.

Dennis

Posted 2016-09-07T03:27:21.873

Reputation: 196 637

5

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.

nedla2004

Posted 2016-09-07T03:27:21.873

Reputation: 521

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, – James – 2016-09-08T19:25:16.357

@DJMcMayhem I think I counted the spaces as tabs, good point, thanks! – nedla2004 – 2016-09-08T19:49:58.710

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) – James – 2016-09-08T19:58:21.233

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. – nedla2004 – 2016-09-08T23:50:20.773

https://ethproductions.github.io/bytes/ – acrolith – 2016-10-30T19:44:36.560

1It 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(): – isaacg – 2016-11-01T16:23:24.550

If anyone could tell me how to use there multiple ifs in a lambda, that would be very helpful, I think it could save few bytes. Also, if there was a way to put is on the same line, separated by semicolons that could save some bytes. – nedla2004 – 2016-11-01T23:39:06.297

You can save 33 bytes with print(*map(lambda p:chr(ord(p)+((((9327,9333)[p.upper()==p])*p.isalpha(),9402)[p<'1'],9263)['/'<p<':']),input())) – Morgan Thrapp – 2016-11-02T15:42:03.387

@MorganThrapp That gives me SyntaxError: invalid character in identifier. – nedla2004 – 2016-11-02T15:57:13.617

Is that when you copy/paste it into repl.it? It seems to be adding some additional periods for some reason. If you delete those, it should be fine. – Morgan Thrapp – 2016-11-02T15:59:05.790

@MorganThrapp No, I paste it into interactive IDLE, when I run it as a program it pops up a box which says invalid character in identifier, is this compatible withPython 3.5, or not? – nedla2004 – 2016-11-02T16:01:41.983

It is. https://repl.it/DYYt/4

– Morgan Thrapp – 2016-11-02T16:02:05.987

@MorganThrapp It changes all the spaces to ⓚ, I believe it is not checking if the character is a letter correctly. – nedla2004 – 2016-11-02T16:06:14.223

Let us continue this discussion in chat.

– Morgan Thrapp – 2016-11-02T16:07:16.743

3

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

Emigna

Posted 2016-09-07T03:27:21.873

Reputation: 50 798

You can write Ža„ instead of of 9312. Only one byte, but it helps. – Dorian – 2019-11-26T14:02:44.487

Although @Dorian is correct that 9312 can be compressed to Ža„ now, it unfortunately won't save any bytes. That type of compressed integers wasn't available yet in the legacy version, so the new version has to be used, but the switch case builtin has been changed from a 1-byte to 2-byte builtin (š to ). EDIT: Never mind, I made an error, so that 18-byter I had just added was incorrect. – Kevin Cruijssen – 2019-11-27T12:22:33.357

2

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.

Dennis

Posted 2016-09-07T03:27:21.873

Reputation: 196 637

2

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

Jordan

Posted 2016-09-07T03:27:21.873

Reputation: 5 001

I think you can save 3 bytes with "A-Za-z0-9","Ⓐ-⓪①-⑨". – Dennis – 2016-09-07T05:59:54.893

@Dennis Right you are. Thanks! – Jordan – 2016-09-07T12:39:02.860

2

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.

Digital Trauma

Posted 2016-09-07T03:27:21.873

Reputation: 64 644

1I think you can save 3 bytes with tr A-Za-z0-9 Ⓐ-⓪①-⑨. – Dennis – 2016-09-07T05:58:41.223

@Dennis Yes, thanks! – Digital Trauma – 2016-09-07T06:02:05.960

1

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;Ⓐ-⓪①-⑨

Ton Hospel

Posted 2016-09-07T03:27:21.873

Reputation: 14 114

1

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.

Billywob

Posted 2016-09-07T03:27:21.873

Reputation: 3 363

This is a very clever solution! I was able to make a shorter but less clever solution, but I'm not convinced it's the shortest.

– rturnbull – 2016-11-02T15:31:36.047

1

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(,""))

rturnbull

Posted 2016-09-07T03:27:21.873

Reputation: 3 689

0

Java 10, 152 151 142 bytes

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

-1 byte thanks to @ceilingcat.

Explanation:

Try it online.

Explanation:

s->{                        // Method with String parameter and StringBuffer return-type
  var 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<49?              //     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

Kevin Cruijssen

Posted 2016-09-07T03:27:21.873

Reputation: 67 575

0

Python 3, 103 bytes

Might save a byte on shuffling added and subtracted numbers

lambda i:i.translate({x:x+(9333-6*(x>96)-70*(x<58)+139*(x<49))*chr(x).isalnum()for x in range(48,123)})

Try it online!

Dead Possum

Posted 2016-09-07T03:27:21.873

Reputation: 3 256

0

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>

edc65

Posted 2016-09-07T03:27:21.873

Reputation: 31 086

Why not add 9388 up front instead? Oh, and why aren't you using replace? – Neil – 2016-09-07T08:28:02.823

@Neil 10% saved thanks to your suggestions – edc65 – 2016-09-07T09:35:30.797

0

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

Magic Octopus Urn

Posted 2016-09-07T03:27:21.873

Reputation: 19 422

0

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.

user8397947

Posted 2016-09-07T03:27:21.873

Reputation: 1 242

@Maltysen How did you figure that out? – user8397947 – 2016-11-01T19:37:47.753

1https://mothereff.in/byte-counter – Maltysen – 2016-11-01T19:39:44.827

0

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

Morgan Thrapp

Posted 2016-09-07T03:27:21.873

Reputation: 3 574