7
\$\begingroup\$

Introduction

Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.

๐Ÿ‡ฆ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฎ๐Ÿ‡ฏ๐Ÿ‡ฐ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ถ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡บ๐Ÿ‡ป๐Ÿ‡ผ๐Ÿ‡ฝ๐Ÿ‡พ๐Ÿ‡ฟ

Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.

This may be much harder for languages that do not innately handle Unicode. Each symbol is exactly 4 UTF-8 Bytes.

The Task

Given an input as one or more letters, output the same, with all letters replaced with their flag combinations.

Winner is the answer with the least Bytes, giving the tiebreaker to first answer posted.

Input / Output

Input and Output may use any standard method. Letters in the input may optionally only support one case, Upper or Lower. Please specify in your answer what case your solution supports.

Your output may, intentionally or otherwise, output flag emoji instead of letter pairs.

Test Cases

FR ๐Ÿ‡ซ๐Ÿ‡ท

Hello, World! ๐Ÿ‡ญ๐Ÿ‡ช๐Ÿ‡ฑ๐Ÿ‡ฑ๐Ÿ‡ด, ๐Ÿ‡ผ๐Ÿ‡ด๐Ÿ‡ท๐Ÿ‡ฑ๐Ÿ‡ฉ!

Rules

  • Standard Loopholes Apply
  • Standard Input Output allowed
  • This is , however, All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins!
\$\endgroup\$
6
  • \$\begingroup\$ Test case number two transforms both cases, do we have to do this? \$\endgroup\$
    – Maltysen
    Oct 25, 2016 at 2:23
  • \$\begingroup\$ As stated, it's not required. It's just to show what would happen if supported. \$\endgroup\$
    – ATaco
    Oct 25, 2016 at 2:24
  • \$\begingroup\$ bytes should be counted, someone can just pack data into dense Chinese characters and win. \$\endgroup\$ Oct 25, 2016 at 2:40
  • 1
    \$\begingroup\$ I'll change it to count bytes, but let the flag letter emoji count as only one byte, to keep with the initial intention. \$\endgroup\$
    – ATaco
    Oct 25, 2016 at 2:43
  • 2
    \$\begingroup\$ Is this a duplicate of this? \$\endgroup\$
    – Angs
    Oct 25, 2016 at 9:57

13 Answers 13

3
\$\begingroup\$

Retina - 9 7 bytes

Supports uppercase.

I don't really know retina, so I'm not sure the question mark diamonds show up because of TIO limitations or because I did something wrong, if its the latter, please leave a comment.

T`L`๐Ÿ‡ฆ-๐Ÿ‡ฟ

Try it online here.

\$\endgroup\$
2
  • \$\begingroup\$ The obvious solution sometimes is also the best. \$\endgroup\$
    – ATaco
    Oct 26, 2016 at 22:33
  • 2
    \$\begingroup\$ ๐Ÿ‡ฆ and ๐Ÿ‡ฟ are 4 bytes each so it's actually 13 bytes. \$\endgroup\$
    – Ion Bazan
    Oct 21, 2021 at 7:35
2
\$\begingroup\$

Pyth - 18 16 bytes

Supports lowercase.

XzGsCMrF+BC\๐Ÿ‡ฆ26

Test Suite.

\$\endgroup\$
3
  • \$\begingroup\$ Doesn't convert FR for me on online link? \$\endgroup\$
    – Downgoat
    Oct 25, 2016 at 2:46
  • \$\begingroup\$ @Downgoat FR is all uppercase, and this answer only supports lowercase \$\endgroup\$ Oct 25, 2016 at 3:00
  • \$\begingroup\$ @ATaco did not see that will be golfing that \$\endgroup\$
    – Maltysen
    Oct 25, 2016 at 3:07
2
\$\begingroup\$

Vyxal, 9 bytes

Cส€ยปฦ›โฝแน—ยป*+

Try it Online!

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 9 bytes

Ties Steffan's Vyxal answer for #1.

A"๐Ÿ‡ฆ๐Ÿ‡ฟ"ร‡ลธรงโ€ก

Try it online! Supports lowercase only.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The Retina answer is 7 bytes if we still want to go by the rules the challenge says: All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins! However, the Retina answer is broken; it displays question marks and not the correct characters. \$\endgroup\$
    – naffetS
    Jun 8, 2022 at 21:59
1
\$\begingroup\$

Lua 5.3, 76 bytes

Lua 5.3 newly has a UTF-8 manipulation library, which is useful in this case.

Lowercase only

print(arg[1]:gsub("%l",function(c)return utf8.char(c:byte()+127365)end).."")
\$\endgroup\$
1
\$\begingroup\$

Scala, 75 bytes

(s:String)=>s.flatMap(c=>if(c.isLetter)Seq(55356,c+56741)else Seq(c))

Explanation:

(s:String)=>             //define an anonymous function taking a string
  s.flatMap(c=>            //map each char...
    if(c.isLetter)           //if it's a letter
      Seq(55356,c+56741)       //...to a sequence of 55356 and c+56741, this is the target char in UTF16 encoding as a surrogate pair
    else                     //else
      Seq(c)                   //..to a sequence of c
  )                        //and flatten

Only works for uppercase. This returns a the output as sequence of integers in UTF16.

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

x86-64, 17 bytes

Takes input as UTF-32LE string in rsi, and outputs in the same format to a buffer at rdi, and code point count in rcx. Only works for uppercase letters. This can be linked to C code with the function signature void f(int *output,int *input,int dummy,int count);. The dummy variable is just to put the count in the rcx register.

fff10100 is the UTF-32LE encoding for ๐Ÿ‡ฟ, and so only costs one byte.

ad 50 5a 2c 41 2c 19 8d 80 fff10100 0f 47 c2 ab e2 ed c3

Or, in assembly:

   0:   ad                      lodsd
   1:   50                      push   rax
   2:   5a                      pop    rdx
   3:   2c 41                   sub    al,0x41
   5:   2c 19                   sub    al,0x19
   7:   8d 80 ff f1 01 00       lea    eax,[rax+0x1f1ff]
   d:   0f 47 c2                cmova  eax,edx
  10:   ab                      stosd
  11:   e2 ed                   loop   0
  13:   c3                      ret

Uses the string manipulation instruction lodsd to load one code point into eax, checks if it's a capital letter using two successive subtractions, and adds the appropriate value to convert it to a flag if it is. Otherwise, it uses the conditional move cmova to restore its original ascii value. Finally, it uses stosd to put a code point in the buffer.

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

C (gcc), 125 111 bytes

main(c,v)char**v;{for(v++;c=**v;putchar(" Ee"[c]+*(*v)++))c=!isalpha(c)-~!islower(c),c%3&&printf(L"\x879ff0");}

-14 bytes thanks to @ceilingcat

Try it online!

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

Jelly, 13 bytes

eโ‚ฌร˜Aร—โ€œยขยฎฦ‘โ€™+OแปŒ

Supports only uppercase letters.

Try it online!

Explanation

eโ‚ฌร˜Aร—โ€œยขยฎฦ‘โ€™+OแปŒ  Input: string S
eโ‚ฌ             Test if each char in S is an element of
  ร˜A             the uppercase alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ร—          Multiply by
     โ€œยขยฎฦ‘โ€™       The codepoints of 'ยขยฎฦ‘' as a base 250 integer
                 This forms 127397
          +    Vectorized add with
           O     The codepoints of each char in S
            แปŒ  Convert back to char from codepoints
               Return and print implicitly
\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6), 70 bytes

f=
s=>s.replace(/[A-Z]/g,c=>String.fromCodePoint(c.codePointAt()+127397))
;
<input oninput=o.textContent=f(this.value)><div id=o>

Accepts upper case only. Mixed case version for 73 bytes:

f=
s=>s.replace(/[A-Z]/gi,c=>String.fromCodePoint(c.codePointAt()+5|127392))
;
<input oninput=o.textContent=f(this.value)><div id=o>

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

PHP, 101 Bytes

supports both replace 64 with 96 to support only lowercase. input only ascii characters allowed

foreach(str_split($argv[1])as$c)echo($o=ord($c))>64&&$o%32<27?hex2bin("f09f87".dechex($o%32+165)):$c;

PHP, 112 Bytes

supports both remove i as modifier in the regex to support only lowercase

<?=preg_replace_callback("#[a-z]#i",function($t){return hex2bin("f09f87".dechex(ord($t[0])%32+165));},$argv[1]);

first version 205 Bytes

<?=preg_replace_callback("#[a-z]#i",function($t){return substr("๐Ÿ‡ฆ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฎ๐Ÿ‡ฏ๐Ÿ‡ฐ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ถ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡บ๐Ÿ‡ป๐Ÿ‡ผ๐Ÿ‡ฝ๐Ÿ‡พ๐Ÿ‡ฟ",(ord($t[0])%32-1)*4,4);},$argv[1]);

The version with mb_substr is one Byte longer

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

Python 3, 68 bytes

lambda s:''.join(chr(x+127397*(64<x<91))for x in map(ord,s.upper()))

Usage (when assigned to f):

print(f("Hello, World!"))
print(f("A B C - X Y Z"))
\$\endgroup\$
0
\$\begingroup\$

Ruby -p, 17 bytes

Counting the letter symbols as one byte each, per OP. Works with uppercase letters.

$_.tr!"A-Z","๐Ÿ‡ฆ-๐Ÿ‡ฟ"

Attempt This Online!

\$\endgroup\$

Your Answer

By clicking โ€œPost Your Answerโ€, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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