24
\$\begingroup\$

ISO 3166-1 is the standard that defines all the country codes. The well-known two-letter codes (US, GB, JP, etc.) are called Alpha-2 codes.

With two letters, there are only 262 = 676 possible codes, which can be nicely arranged in a grid. This table can be useful as an overview, to see which codes are actually in use, reserved, etc.

This challenge is simple: you're to print all assigned codes of this grid to STDOUT, using plain ASCII, exactly as shown below:

AA    AC AD AE AF AG    AI       AL AM AN AO AP AQ AR AS AT AU    AW AX    AZ
BA BB    BD BE BF BG BH BI BJ    BL BM BN BO    BQ BR BS BT BU BV BW BX BY BZ
CA    CC CD    CF CG CH CI    CK CL CM CN CO CP    CR CS    CU CV CW CX CY CZ
            DE    DG       DJ DK    DM    DO                            DY DZ
EA    EC    EE EF EG EH             EM       EP    ER ES ET EU EV EW         
                        FI FJ FK FL FM    FO       FR                FX      
GA GB GC GD GE GF GG GH GI       GL GM GN    GP GQ GR GS GT GU    GW    GY   
                              HK    HM HN          HR    HT HU               
   IB IC ID IE                   IL IM IN IO    IQ IR IS IT IU IV IW IX IY IZ
JA          JE                      JM    JO JP                              
            KE    KG KH KI          KM KN    KP    KR             KW    KY KZ
LA LB LC       LF       LI    LK                   LR LS LT LU LV       LY   
MA    MC MD ME MF MG MH       MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
NA    NC    NE NF NG    NI       NL       NO NP    NR    NT NU             NZ
OA                                  OM                                       
PA          PE PF PG PH PI    PK PL PM PN          PR PS PT       PW    PY   
QA                                  QM QN QO QP QQ QR QS QT QU QV QW QX QY QZ
RA RB RC    RE       RH RI       RL RM RN RO RP       RS    RU    RW         
SA SB SC SD SE SF SG SH SI SJ SK SL SM SN SO       SR SS ST SU SV    SX SY SZ
TA    TC TD    TF TG TH    TJ TK TL TM TN TO TP    TR    TT    TV TW       TZ
UA                UG          UK    UM                US                UY UZ
VA    VC    VE    VG    VI             VN                   VU               
               WF                WL       WO          WS       WV            
XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ
            YE                                           YT YU YV            
ZA                                  ZM             ZR             ZW       ZZ

(If I made any mistakes copying it down, the table here in this post is normative for the challenge, not the one on Wikipedia.)

You may or may not use trailing whitespace in each line which doesn't contain the *Z code, but not beyond the 77th character in that line (i.e., at most, you can make it a rectangular block, ending in Zs and spaces). Also, you may or may not use a single trailing new line at the end.

This is code golf, so the shortest answer (in bytes) wins.

\$\endgroup\$
  • \$\begingroup\$ Which table is your example supposed to match? Is the omission of YT (Mayotte) an oversight? \$\endgroup\$ – Greg Hewgill Oct 13 '14 at 20:42
  • \$\begingroup\$ @GregHewgill Yes thank you. I'll fix that, but for any further discrepancy, the table in this post is normative (it doesn't really matter for the challenge, if one code is missing or too much). \$\endgroup\$ – Martin Ender Oct 13 '14 at 20:44

14 Answers 14

7
\$\begingroup\$

CJam, 125 122 121 bytes

"^Kéÿ·^?{ÿ·¿oÂ^Ú^À:ð^×à^Cé^Dÿ^Ýú^À^K^V^G^Áïþ ,^@^K^ÍBù(^_+óÿþºMa^À^H^@#ï^\¨^@ÿÿ¦|¨ÿþ}íßÕ^Ø\"^Â^Nª^P ^D^R$?ÿÿð^À^AÂ^@!^I"256b2b'[,65>_m*]z{~S2*?}%26/Sf*N*

The above uses caret notation for control characters.

Printable version (141 bytes) for the online interpreter:

"J`ki4#'Tr{$V!AcG)\d6o+rW97;#1|jN!WXL%GRuqYos0xCaaBzYgN97DOA'f@#@k'867BrCc1h?&d0LBq[st0YW^?b2Jfx.&gG:O(&"31f-95b2b'[,65>_m*]z{~S2*?}%26/Sf*N*

Example run

$ base64 -d > cc.cjam <<< Igvp/7d/e/+3v2/CmoA68JfgA+kE/536gAsWB4Hv/iAsAAuNQvkoHyvz//66TWGACAAj7xyoAP//pnyo//597d/VmFwigg6qECAEEiQ////wgAHCACEJIjI1NmIyYidbLDY1Pl9tKl16e35TMio/fSUyNi9TZipOKg==
$ LANG=en_US cjam cc.cjam
AA    AC AD AE AF AG    AI       AL AM AN AO AP AQ AR AS AT AU    AW AX    AZ                                                                                                                                      
BA BB    BD BE BF BG BH BI BJ    BL BM BN BO    BQ BR BS BT BU BV BW BX BY BZ                                                                                                                                      
CA    CC CD    CF CG CH CI    CK CL CM CN CO CP    CR CS    CU CV CW CX CY CZ                                                                                                                                      
            DE    DG       DJ DK    DM    DO                            DY DZ                                                                                                                                      
EA    EC    EE EF EG EH             EM       EP    ER ES ET EU EV EW                                                                                                                                               
                        FI FJ FK FL FM    FO       FR                FX      
GA GB GC GD GE GF GG GH GI       GL GM GN    GP GQ GR GS GT GU    GW    GY   
                              HK    HM HN          HR    HT HU               
   IB IC ID IE                   IL IM IN IO    IQ IR IS IT IU IV IW IX IY IZ
JA          JE                      JM    JO JP                              
            KE    KG KH KI          KM KN    KP    KR             KW    KY KZ
LA LB LC       LF       LI    LK                   LR LS LT LU LV       LY   
MA    MC MD ME MF MG MH       MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
NA    NC    NE NF NG    NI       NL       NO NP    NR    NT NU             NZ
OA                                  OM                                       
PA          PE PF PG PH PI    PK PL PM PN          PR PS PT       PW    PY   
QA                                  QM QN QO QP QQ QR QS QT QU QV QW QX QY QZ
RA RB RC    RE       RH RI       RL RM RN RO RP       RS    RU    RW         
SA SB SC SD SE SF SG SH SI SJ SK SL SM SN SO       SR SS ST SU SV    SX SY SZ
TA    TC TD    TF TG TH    TJ TK TL TM TN TO TP    TR    TT    TV TW       TZ
UA                UG          UK    UM                US                UY UZ
VA    VC    VE    VG    VI             VN                   VU               
               WF                WL       WO          WS       WV            
XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ
            YE                                           YT YU YV            
ZA                                  ZM             ZR             ZW       ZZ
\$\endgroup\$
10
\$\begingroup\$

Python 2, 240 bytes

Straightforward binary encoding implementation.

R=range(26)
print"\n".join(" ".join(chr(65+r)+chr(65+c)if int("8hfxckgq1olihfa47x3rrdkojzkklec7qk1hp4ht6avmzxfg7c4uv14xe0pzvvg93x81ag2bf88v2w0p3p08g8nwtuktbwosj9dytset3qmhdl72v5u62nepapgabdqqu7x",36)&1<<c+r*26 else"  "for c in R)for r in R)

The script for generating the integer is quick and dirty:

codes="""AA    AC AD AE AF AG    AI       AL AM AN AO AP AQ AR AS AT AU    AW AX    AZ
BA BB    BD BE BF BG BH BI BJ    BL BM BN BO    BQ BR BS BT BU BV BW BX BY BZ
CA    CC CD    CF CG CH CI    CK CL CM CN CO CP    CR CS    CU CV CW CX CY CZ
            DE    DG       DJ DK    DM    DO                            DY DZ
EA    EC    EE EF EG EH             EM       EP    ER ES ET EU EV EW         
                        FI FJ FK FL FM    FO       FR                FX      
GA GB GC GD GE GF GG GH GI       GL GM GN    GP GQ GR GS GT GU    GW    GY   
                              HK    HM HN          HR    HT HU               
   IB IC ID IE                   IL IM IN IO    IQ IR IS IT IU IV IW IX IY IZ
JA          JE                      JM    JO JP                              
            KE    KG KH KI          KM KN    KP    KR             KW    KY KZ
LA LB LC       LF       LI    LK                   LR LS LT LU LV       LY   
MA    MC MD ME MF MG MH       MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ
NA    NC    NE NF NG    NI       NL       NO NP    NR    NT NU             NZ
OA                                  OM                                       
PA          PE PF PG PH PI    PK PL PM PN          PR PS PT       PW    PY   
QA                                  QM QN QO QP QQ QR QS QT QU QV QW QX QY QZ
RA RB RC    RE       RH RI       RL RM RN RO RP       RS    RU    RW         
SA SB SC SD SE SF SG SH SI SJ SK SL SM SN SO       SR SS ST SU SV    SX SY SZ
TA    TC TD    TF TG TH    TJ TK TL TM TN TO TP    TR    TT    TV TW       TZ
UA                UG          UK    UM                US                UY UZ
VA    VC    VE    VG    VI             VN                   VU               
               WF                WL       WO          WS       WV            
XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ
            YE                                           YT YU YV            
ZA                                  ZM             ZR             ZW       ZZ
"""
n = sum(1 << (x/3) for x in range(0, len(codes), 3) if codes[x] != " ")
def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
    return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])
print baseN(n, 36)
\$\endgroup\$
  • 1
    \$\begingroup\$ You save 4 bytes using R=range(26). \$\endgroup\$ – Falko Oct 13 '14 at 21:20
  • 1
    \$\begingroup\$ @Falko: That won't work because I need two iterators. Oh wait, this is python 2, where range returns a list! \$\endgroup\$ – Greg Hewgill Oct 13 '14 at 21:20
  • \$\begingroup\$ Oh, and 4 more writing ...,36)&1<<c+r*26else.... - Would you mind posting your script for generating the base-36 integer? \$\endgroup\$ – Falko Oct 13 '14 at 21:28
  • \$\begingroup\$ @Falko: Thanks, only 3 because 26else is not parseable. I thought I tried removing the parentheses but I must have had something else wrong at that point! \$\endgroup\$ – Greg Hewgill Oct 13 '14 at 21:33
  • \$\begingroup\$ Ok, it seems to depend on the interpreter. My Python 2.7.8 does allow 26else. (Python 2.7.6, however, does not.) \$\endgroup\$ – Falko Oct 13 '14 at 21:38
6
\$\begingroup\$

Ruby, 269 246 241 235 227

g="b6wapsm769n90ongzuvadg5vdat6ap7v1oyyie3j5wxbq9xtycezrtt9xamn9riqnnxnsxjx0al8uk8rmk5snb7quly7t5i9rkq21r1vnns5vdm7gwzqtxwwwmj02nqxlhl".to_i 36
l=*?A..?Z
676.times{|i|print g.to_s(2)[i]==?1?l[i/26]+l[i%26]:"  ",i%26==25?$/:" "}

g is a matrix where each cell that has a country code is a 1 and all others are 0. All rows are written behind and the resulting binary number has been converted to a base 36 representation. Then I just iterate over all cells and check if the code shall be printed.

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to PPCG! A few of Ruby tips: you can use {|i|...} instead of do|i|...end, and also start the first statement right after |i| (without line break). A shorter way to print without trailing line break is $><<. You can replace "\n" with $/, and "1" with ?1. And a shorter way to generate the alphabet is l=[*?A..?Z]*'' ;) \$\endgroup\$ – Martin Ender Oct 14 '14 at 10:22
  • 2
    \$\begingroup\$ Additionally, you can use the alphabet as array, no need to join it into a string. \$\endgroup\$ – manatwork Oct 14 '14 at 10:24
  • \$\begingroup\$ Thanks! If I replace print with $><< a matrix of true and false is printed. How do I use this correctly? \$\endgroup\$ – stevecross Oct 14 '14 at 10:33
  • 1
    \$\begingroup\$ There appears the problem of precedence as << is a method of $>, so you have to use parenthesis: $><<(1==2?3:4). By the way, the shortest I got from this is 231 characters: pastebin.com/iabBNh6S . \$\endgroup\$ – manatwork Oct 14 '14 at 10:38
  • 1
    \$\begingroup\$ No, I think not. But regardless you use print or $><<, use only one. print accepts multiple parameters separated with ,, for $><< you can concatenate the two pieces to output. \$\endgroup\$ – manatwork Oct 14 '14 at 10:46
4
\$\begingroup\$

CJam, 152 149 148 145 144 140 139 bytes, printable

". QH%$ydK0]cg:WSSlFu0z>O$T1<hO)Q63@D7;\KDJ^!NQN!tFr'>x@*!nf`Ut<s=N_[\%Ec0AXXZ`hayqIi'qj)jnonEj!n(ZjpjW("31f-96b2b'[,65>_m*]z{~SS+?S}%52/N*

Thanks Dennis for pointers.

Pretty straightforward approach. How it works:

". Q .... jW("                "Push this string to stack. This is a compressed string"
                              "which results to a 26 by 26 grid of 0 and 1 representing"
                              "whether that block contains country code or empty space";
              31f-96b2b       "Remove 31 from ASCII code of each of the character,"
                              "treat the number array as of base 96 and convert it to"
                              "a base 2 number";
'[,                           "Create an array of characters of ASCII code 0 to 91";
   65>                        "Take last 26 characters, which are A to Z";
      _m*                     "Copy the array and create all combinations {XX|X ∈ [A,Z]}";
         ]z                   "zip the first 26*26 array of 1 and 0 with the above"
                              "26*26 array of XX such that the final array element"
                              "is like ([B XX]|B={0,1},X∈[A,Z])";
           {~SS+?S}%          "For element, unwrap it from array, put "  " to stack,"
                              "if first number is 1, take XX otherwise, the spaces"
                              "and put a single space after each element";
                    52/       "split the array into chunks of 52,i.e 26 XX and 26 spaces";
                       N*     "Join each chunk of 52 elements with new line"

Try it online here

(Now only if I knew how to do a non printable character version)

\$\endgroup\$
  • \$\begingroup\$ I didn't pay attention to your answer earlier. After my last edit, my approach is quite similar to yours (but still a step behind). 1. :i is not needed; b works fine with a string as its second argument. 2. If you use '[, instead of 91,, you don't need :c. \$\endgroup\$ – Dennis Oct 14 '14 at 2:03
  • \$\begingroup\$ @Dennis Thanks! I actually tried the '[,65> route, but I was still putting a :c after it leading to same bytes, thus did not use it :D \$\endgroup\$ – Optimizer Oct 14 '14 at 5:41
3
\$\begingroup\$

JavaScript ES6, 336 322

a='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alert(r='tr20d,yxurj,soeyn,1migz,rbh14,5hqc,13w82y,z1c,iqx33,l8dmo,1swln,zokqa,tukfz,r8voh,jzd34,mflqi,jzjen,10gn1k,13ycc7,sn0bd,kbb0j,qm2hs,mvf4,13ydj3,18y9c,jzdah'.split(',').map((n,i)=>(1e10+(parseInt(n,36).toString(2))).slice(-26).replace(/./g,(m,j)=>+m?a[i]+a[j]+' ':'   ')).join('\n'))

The big string is each row put into binary (1 if there was a country code there, 0 if not) and then base36. Try it out in Firefox at http://jsfiddle.net/twduhqz6/1/.

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

Bash+coreutils, 361

Basic regex removal of the combos we don't want. Some mild compression of the regex:

a=({A..Z})
f=(BHJKVY CKP BEJQT A-DFHILNP-X BDI-LNOQX-Z A-HNPQS-WYZ JKOVXZ A-JLO-QSV-Z AF-KP B-DF-LNQ-Z A-DFJ-LOQS-VX DEGHJL-QWXZ BIJ BDHJKMNQSV-Y B-LN-Z B-DJO-QUVXZ B-L DFGJKQRTVX-Z PQW BEIQSUXY B-FH-JLN-RT-X BDFHJ-MO-TV-Z A-EG-KMNP-RTUW-Z _ A-DF-SW-Z B-LN-QS-VXY)
for i in ${!a[@]};{
s+="${a[i]}[${f[i]}]|"
}
echo {A..Z}{A..Z}|sed -r "s/Z /Z\n/g;s/${s%|}/  /g"
\$\endgroup\$
2
\$\begingroup\$

Haskell, 357

Damn, this is kinda hard.

import Data.List.Split
az=['A'..'Z']
k=0x9084004380010ffffffc24482004085570414419abfbb7be7fff153e65ffff001538f7c400100186b25d7fffcfd4f8149f42b1d00034047ff781e068d0015fb9ff2097c007e90f5c015943f6fdedffdefeedff97d
l i (a:b)|i`mod`2>0=a:l(i`div`2)b|1>0="  ":l(i`div`2)b
l _ _=[]
main=putStr$unlines$chunksOf 78$unwords$l k[a:[b]|a<-az,b<-az]

Prints to STDOUT when compiled (thus the main). Using proper compression would make this a lot shorter... ideas welcome

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

JavaScript (E6) 350

Not the right tool for this task (maybe thanks to String.fromCharCode?)

r=0,Q=x=>String.fromCharCode(x+64),
console.log("2dff97d 3ff7bfb 3f6fded 3005650 7e90f5 825f00 15fb9ff 1a3400 3ff781e d011 342b1d0 13e0527 3fffcfd 21ac975 1001 14e3df1 3fff001 54f997 3be7fff 26afeed 3041441 102155 244820 3ffffff 380010 2421001"
.replace(/\w+./g,x=>{for(x='0x'+x,s=c=o='',++r;++c<27;s=' ',x/=2)o+=s+(x&1?Q(r)+Q(c):'  ');return o+'\n'}))
\$\endgroup\$
1
\$\begingroup\$

J, 172 chars (printable)

echo}:"1,.u:32+(26 26$,(6#2)#:34-~3 u:
'QKa]?a@a`YQXa$HJ"\^+AB"`F&a[Y\B"N8#Z)QaD"N""P/2QFJ)TQUaa\\58("$""E]STJ"1aaKITJaa[_]?a7H$,$%LJ2*"24+%aaaa$"">*"*2F'
)*0,"1~33+,"0/~i.26

Line breaks for legibility. Straightforward binary packing, with six bits per string character (offset 34 to get into the printable range as well as avoid ').

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

Wolfram language, 244 255 bytes

Table[Table[If[BitGet[36^^b6wapsm769n90ongzuvadg5vdat6ap7v1oyyie3j5wxbq9xtycezrtt9xam\n9riqnnxnsxjx0al8uk8rmk5snb7quly7t5i9rkq21r1vnns5vdm7gwzqtxwwwmj02nqxl\hl,675-i*26-j]==1,FromCharacterCode[{i,j}+65]<>" ","   "],{j,0,25}]<>"\n",{i,0,25}]<>""

The number from fireflame241's answer was used and repacked into 36-ary form.

No builtin country data were used.

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

PHP, 323 Bytes

$p=explode(_,"^BHJKVY_^CKP_^BEJQT_EGJKMOYZ_ACE-HMPR-W_I-MORX_^JKOVXZ_KMNRTU_^AF-KP_AEMOP_EGHIMNPRWYZ_ABCFIKR-VY_^BIJ_ACEFGILOPRTUZ_AM_AE-IK-NR-TWY_AM-Z_A-CEHIL-PSUW_^PQW_^BEIQSUXY_AGKMSYZ_ACEGINU_FLOSV_\w_ETUV_AMRWZ");
foreach($r=range(A,Z)as$k=>$v)
foreach($r as$w)echo preg_match("#[{$p[$k]}]#",$w)?$v.$w:"  "," 
"[$w>Y];

Try it online!

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

C, 373 bytes

main(i,j){char e[]="0BHJKVY|0CKP|0BEJQT|EGJKLMOYZ|0BDIJKLNOQXYZ|IJKLMORX|0JKOVXZ|KMNRTU|0AFGHIJKP|AEMOP|EGHIMNPRWYZ|ABCFIKRSTUVY|0BIJ|0BDHJKMNQSVWXY|AM|0BCDJOPQUVXZ|0BCDEFGHIJKL|0DFGJKQRTVXYZ|0PQW|0BEIQSUXY|AGKMSYZ|ACEGINU|FLOSV|0|ETUV|AMRWZ",*t,*p=e,*s="|";for(i=0;t=strtok(p,s);p=0,i++)for(j=0;j<27;j++)printf(j-26?!strchr(t,65+j)^(*t!=48)?"%c%c ":"   ":"\n",65+i,65+j);}

Try it online

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

Wolfram language, 389 bytes

c=CountryData;r=Riffle;StringReplace[""<>r[#~r~" "&/@Array[CharacterRange["A","Z"][[{##}]]&,{26,26}],n="
"],{"GZ"|"WE"->"  ",x:("X"~~_~~" "|n)|##&@@(Cases[#~c~"CountryCode"&/@c[],_String]~Join~(""<>#&/@Partition[Characters@"AACPSXQNICRANTAPEAQPEPEUMQQRCSXQXDGCWLRNTPEVAQUMQVEWLRPIXDYUMQSUMQWVEFRBQYVIBXEMQMQOAQZRBLFRBUKRLIBVIUKGSSFXHRMQTFLIVIWOARIYVIZZRHMFIOAXJA",2,1])):>x,Except@n->" "}]

More readable:

c = CountryData; r = Riffle; StringReplace[
 "" <> r[#~r~" " & /@ 
    Array[CharacterRange["A", "Z"][[{##}]] &, {26, 26}], 
   n = "\n"], {"GZ" | "WE" -> "  ", 
  x : ("X" ~~ _ ~~ " " | n) | ## & @@ (Cases[#~c~"CountryCode" & /@ 
        c[], _String]~
      Join~("" <> # & /@ 
        Partition[
         Characters@
          "AACPSXQNICRANTAPEAQPEPEUMQQRCSXQXDGCWLRNTPEVAQUMQVEWLRPIXDY\
UMQSUMQWVEFRBQYVIBXEMQMQOAQZRBLFRBUKRLIBVIUKGSSFXHRMQTFLIVIWOARIYVIZZR\
HMFIOAXJA", 2, 1])) :> x, Except@n -> " "}]

Wolfram has an in-built list of ISO country codes, so this should be the perfect language for the job. However, it only knows about the country codes that are actually the codes for countries, and not the ones reserved for other uses, which are still included in this table. We therefore need to add a lot of the country codes in manually.

Explanation:

  • ""<>r[r[#," "]&/@Array[CharacterRange["A","Z"][[{##}]]&,{26,26}],n="\n"] is a string array of all pairs of letters from "A" to "Z".
  • #~c~"CountryCode"&/@c[] (where c=CountryData is defined earlier) gives a list of all country codes that Wolfram Language knows about. A couple of these are Missing["NotApplicable"], so we remove those with Cases[...,_String].
  • (""<>#&/@Partition[Characters@"AACP...AXJA",2,1]) makes 83 of the remaining country codes manually using a 138-character string, where the pairs of adjacent characters are the required country codes. This string was found more or less by hand (with the help of the FindPostmanTour function!), and there is some repetition, so there's potentially more golfing to be done here.
  • StringReplace[ <full array> ,{"GZ"|"WE"->" ",x:("X"~~_~~" "|n)|##&@@( <known country codes> ~Join~ <extra codes> ):>x,Except@n->" "}] first gets rid of two codes, "GZ" and "WE", which Wolfram thinks are country codes but aren't according to the table; then matches all codes starting with "X", plus the known codes and the ones we added manually, and replaces them with themselves; then finally everything else which isn't a newline and hasn't already been matched is turned into a space.
\$\endgroup\$
  • 1
    \$\begingroup\$ It turns out that the extraneous "GZ" and "WE" stand for Gaza Strip and West Bank. Is this the first time that the conflict in Israel has affected a code golf challenge? \$\endgroup\$ – Not a tree May 1 '17 at 8:17
0
\$\begingroup\$

Jelly, 121 120 112 110 bytes (non-competing)

“VV&ØṖgḳeƘKo⁾lc<Ṗɗẋ⁾ÆȤ¡rżQ5¤ø^k&`v®tḊẒḂṁz®ṙṂþ°~7<¹ṢƝƒ4ṇæÇZt9ẈÇḞƲY!u`İŀo0*dḅḥmȯḊȧṛƓXĠƈṾ’Bx2ða»32øØAp`OFµỌs2s26G

Try it online!

-8 bytes thanks to @Dennis

-2 bytes thanks to @Dennis's idea of Cartesian products

How it works

Simple: The program multiplies one big binary list with another big list to get most of the output, then formats it

Medium: The program encodes the big binary list

1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1

into one big number, encoding which country codes are assigned. Each element is multiplied element-wise by each element of every possible country code to get a list of all assigned country codes, which is then formatted to the output list.

Lower level:

The bulk of the program uses data encoded in:

“VV&ØṖgḳeƘKo⁾lc<Ṗɗẋ⁾ÆȤ¡rżQ5¤ø^k&`v®tḊẒḂṁz®ṙṂþ°~7<¹ṢƝƒ4ṇæÇZt9ẈÇḞƲY!u`İŀo0*dḅḥmȯḊȧṛƓXĠƈṾ’

It is a base-250 integer which holds the decimal number 233462323092263584350936137603939798267906095227198731310610883427614237299604158551774020670253062350084519623333781892392013977676150946873601610983221266427394582295973500719992107281184544524840476937, which gets turned into the above binary list.

For brevity, let's call this value c and replace the long string with c in the explanation

cBx2ða»32øØAp`OFµỌs2s26G   - main link, takes no input
c                          -  literal value
 B                         -  convert this to binary to get a list
                                       representing which codes are assigned
  x2                       -   repeat each element twice
    ða»32                  - element-wise product (dealing with 
                                       spaces) with...
         øØAp`OF           -  every possible country code in ASCII codes.
                µỌs2s26G   - format the output to be correct
\$\endgroup\$
  • \$\begingroup\$ ;⁶$€Fs78;⁷$€ can be replaced with s26G. \$\endgroup\$ – Dennis Apr 30 '17 at 5:16
  • \$\begingroup\$ Hints: Look into Cartesian products. You don't need spaces for blank; G will pad empty strings with spaces. \$\endgroup\$ – Dennis Apr 30 '17 at 5:27
  • \$\begingroup\$ I think this is non-competing. \$\endgroup\$ – Erik the Outgolfer May 1 '17 at 9:33
  • \$\begingroup\$ Yeah, the language is newer than the challenge. \$\endgroup\$ – mbomb007 May 1 '17 at 19:44

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.