3
\$\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\$
  • \$\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
2
\$\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\$
  • \$\begingroup\$ The obvious solution sometimes is also the best. \$\endgroup\$ – ATaco Oct 26 '16 at 22:33
2
\$\begingroup\$

Pyth - 18 16 bytes

Supports lowercase.

XzGsCMrF+BC\🇦26

Test Suite.

\$\endgroup\$
  • \$\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
0
\$\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\$
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\$

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\$

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.