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! 🇭🇪🇱🇱🇴, 🇼🇴🇷🇱🇩!


  • 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!
  • \$\begingroup\$ Test case number two transforms both cases, do we have to do this? \$\endgroup\$ – Maltysen Oct 25 '16 at 2:23
  • \$\begingroup\$ As stated, it's not required. It's just to show what would happen if supported. \$\endgroup\$ – ATaco Oct 25 '16 at 2:24
  • \$\begingroup\$ bytes should be counted, someone can just pack data into dense Chinese characters and win. \$\endgroup\$ – noɥʇʎԀʎzɐɹƆ Oct 25 '16 at 2:40
  • \$\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 '16 at 2:43
  • 2
    \$\begingroup\$ Is this a duplicate of this? \$\endgroup\$ – Angs Oct 25 '16 at 9:57

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.


Try it online here.

  • \$\begingroup\$ The obvious solution sometimes is also the best. \$\endgroup\$ – ATaco Oct 26 '16 at 22:33

Pyth - 18 16 bytes

Supports lowercase.


Test Suite.

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

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

Jelly, 13 bytes


Supports only uppercase letters.

Try it online!


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

JavaScript (ES6), 70 bytes

<input oninput=o.textContent=f(this.value)><div id=o>

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

<input oninput=o.textContent=f(this.value)><div id=o>


PHP, 101 Bytes

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


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


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

Scala, 75 bytes

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


(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.


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.