Given an ISO3166-1-Alpha-2 country code your task is to decide on the traffic direction for that country:

  • Input will be a valid country code (valid as in it's an element of the two lists provided)
  • Input may be a list of two characters instead of a string if it helps
  • You may choose to take input in lowercase
  • You will choose one value, say for right (your choice) and will output that value iff the traffic in that country is right-handed and anything else in the other case
  • You only have to handle country codes that are contained in one of these lists:

These are all countries where traffic is left-handed:

['AI', 'AG', 'AU', 'BS', 'BD', 'BB', 'BM', 'BT', 'BW', 'VG', 'BN', 'KY', 'CX', 'CC', 'CK', 'CY', 'DM', 'FK', 'FJ', 'GD', 'GG', 'GY', 'HK', 'IN', 'ID', 'IE', 'IM', 'JM', 'JP', 'JE', 'KE', 'KI', 'LS', 'MO', 'MW', 'MY', 'MV', 'MT', 'MU', 'MS', 'MZ', 'NA', 'NR', 'NP', 'NZ', 'NU', 'NF', 'PK', 'PG', 'PN', 'SH', 'KN', 'LC', 'VC', 'WS', 'SC', 'SG', 'SB', 'SO', 'ZA', 'GS', 'LK', 'SR', 'SZ', 'TH', 'TL', 'TK', 'TO', 'TT', 'TC', 'TV', 'UG', 'GB', 'TZ', 'VI', 'ZM', 'ZW']

And here are all countries where traffic is right-handed:

['AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AQ', 'AR', 'AM', 'AW', 'AT', 'AZ', 'BH', 'BY', 'BE', 'BZ', 'BJ', 'BO', 'BA', 'BV', 'BR', 'IO', 'BG', 'BF', 'BI', 'CV', 'KH', 'CM', 'CA', 'CF', 'TD', 'CL', 'CN', 'CO', 'KM', 'CG', 'CR', 'CI', 'HR', 'CU', 'CW', 'CZ', 'KP', 'CD', 'DK', 'DJ', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FO', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GP', 'GU', 'GT', 'GW', 'GN', 'HT', 'HM', 'VA', 'HN', 'HU', 'IS', 'IR', 'IQ', 'IL', 'IT', 'JO', 'KZ', 'KW', 'KG', 'LA', 'LV', 'LB', 'LR', 'LY', 'LI', 'LT', 'LU', 'MG', 'ML', 'MH', 'MQ', 'MR', 'YT', 'MX', 'FM', 'MC', 'MN', 'ME', 'MA', 'MM', 'NL', 'NC', 'NI', 'NG', 'NE', 'MP', 'NO', 'OM', 'PW', 'PA', 'PY', 'PE', 'PH', 'PL', 'PT', 'PR', 'QA', 'KR', 'MD', 'RE', 'RO', 'RU', 'RW', 'BL', 'MF', 'PM', 'SM', 'ST', 'SA', 'SN', 'RS', 'SL', 'BQ', 'SX', 'SK', 'SI', 'SS', 'ES', 'PS', 'SD', 'SJ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'MK', 'TG', 'TN', 'TR', 'TM', 'UA', 'AE', 'UM', 'US', 'UY', 'UZ', 'VU', 'VE', 'VN', 'WF', 'EH', 'YE']

For completeness sake, here's a CSV file that contains all the values along with the country names.


Assuming you chose to output L for left-handed traffic, here are some valid test cases:

'PY' -> 'python'
'PN' -> 'L'
'CN' -> 33
'GY' -> 'L'

Note: There is a small chance that I missed a country or that there's a wrong classification and I will not change the specs because that might invalidate answers. If I made a mistake I sincerely apologize, please don't take offense!

  • 1
    \$\begingroup\$ Is it okay to output nothing if the country code doesn't match? \$\endgroup\$ – stevefestl Jan 6 '18 at 2:38
  • 3
    \$\begingroup\$ @SteveFest: I'd say that counts as anything else, yes. \$\endgroup\$ – ბიმო Jan 6 '18 at 3:48
  • \$\begingroup\$ may I output "left" for left case and anything else in right case? \$\endgroup\$ – l4m2 Jan 6 '18 at 4:47
  • 7
    \$\begingroup\$ I came here expecting to find a 10-byte Mathematica solution that was somehow built-in. I am sorely disappointed. \$\endgroup\$ – Silvio Mayolo Jan 6 '18 at 23:08
  • 3
    \$\begingroup\$ @SilvioMayolo CountryData can give the amount of paved and unpaved road and railroads etc in a country but not its traffic direction :( \$\endgroup\$ – hyper-neutrino Jan 8 '18 at 14:49

24 Answers 24


Python 2, 145 136 112 109 bytes


Try it online!

Outputs -1 for right-handed traffic. The string is autogenerated with this Retina script. Thanks to totallyhuman for the 9 bytes shorter lookup string. I was able to get 24 bytes more off through AdmBorkBork suggestion.
Got the lookup string 3 bytes shorter using a python script.

  • 4
    \$\begingroup\$ Since things like OT don't exist, can you get rid of some spaces like TO TC goes to TOTC? \$\endgroup\$ – AdmBorkBork Jan 5 '18 at 19:53
  • 1
    \$\begingroup\$ @AdmBorkBork thanks a lot, I got all the spaces out. \$\endgroup\$ – ovs Jan 5 '18 at 20:16
  • \$\begingroup\$ Can you explain the string at all? \$\endgroup\$ – Gigaflop Sep 20 '18 at 12:20

Jelly, 61 bytes

Many thanks to @Mr.Xcoder for helping me putting this together
Saved 1 byte thanks to @JonathanAllan

Returns 0 for right-handed or 1 for left-handed.


Try it online!


We convert each country code to an integer N by parsing it as base-256 and apply the following hash function, which is collision-free for left-handed vs right-handed traffic:

((N * 6) MOD 1513) MOD 566

This leads to the following list of values for left-handed traffic:

[   8,  14,  27,  37,  52,  60,  62,  68,  71,  84,  85,  88, 103, 105, 114, 119, 135,
  166, 167, 180, 187, 190, 195, 196, 202, 207, 208, 211, 214, 225, 226, 229, 232, 255,
  256, 262, 285, 301, 302, 303, 304, 309, 322, 325, 327, 337, 357, 369, 370, 381, 393,
  401, 408, 413, 420, 430, 453, 467, 473, 478, 492, 503, 509, 513, 516, 527, 528, 541,
  546, 547, 556, 562 ] (72 entries)

The average difference between two consecutive entries is close to 8. We delta-encode the list with increments in the range [1...16]. It means that whenever an increment is greater than 16, we need to insert an intermediate value on an unused slot (we have to make sure that it's not hit by right-handed traffic). But the hash function was chosen in such a way that we only have to do that for a few positions. This gives:

[  8,  6, 13, 10, 15,  8,  2,  6,  3, 13,  1,  3, 15,  2,  9,  5, 16, 15, 16,  1, 13,
   7,  3,  5,  1,  6,  5,  1,  3,  3, 11,  1,  3,  3, 16,  7,  1,  6, 16,  7, 16,  1,
   1,  1,  5, 13,  3,  2, 10, 16,  4, 12,  1, 11, 12,  8,  7,  5,  7, 10, 16,  7, 14,
   6,  5, 14, 11,  6,  4,  3, 11,  1, 13,  5,  1,  9,  6 ] (77 entries)

We convert this list from bijective base-16 to the following integer:


which becomes “ŒỴ¬Ʋ>r¤dị|®ædHẇ⁸ɗH^CŒ³ẇPḷgȤƲȥƓƑ®Ƭṅḅ4ṛḟṄ’ in Jelly's base-250 encoding.

The first link rebuilds the original list from this integer and the second one tests whether it contains the hash of the input.

“ŒỴ¬Ʋ>r¤dị|®ædHẇ⁸ɗH^CŒ³ẇPḷgȤƲȥƓƑ®Ƭṅḅ4ṛḟṄ’ḃ⁴+\      - 1st link: takes no input
“ŒỴ¬Ʋ>r¤dị|®ædHẇ⁸ɗH^CŒ³ẇPḷgȤƲȥƓƑ®Ƭṅḅ4ṛḟṄ’          - our big integer
                                         ḃ⁴        - convert it to bijective base-16
                                           +\      - apply delta-decoding

Oḅ⁹×6%⁽£€%566e¢                  - 2nd link: takes the country code  -> e.g. 'GB'
O                                - get ASCII codes                   -> [71, 66]
 ḅ⁹                              - convert from base-256 to integer  -> 18242
   ×6                            - multiply by 6                     -> 109452
     %⁽£€                        - modulo 1513                       -> 516
         %566                    - modulo 566                        -> 516
             e                   - look for it in the decoded list,
              ¢                  - using the first link as a nilad   -> 1
  • \$\begingroup\$ Save a byte by converting from an integer to bijective base 16: “ŒỴ¬Ʋ>r¤dị|®ædHẇ⁸ɗH^CŒ³ẇPḷgȤƲȥƓƑ®Ƭṅḅ4ṛḟṄ’ḃ⁴ (thus avoiding the increment) ...also (not a byte save, but) ¢ calls the last link as a nilad. \$\endgroup\$ – Jonathan Allan Jan 6 '18 at 20:24
  • \$\begingroup\$ @JonathanAllan Nice! Thank you. \$\endgroup\$ – Arnauld Jan 7 '18 at 8:56

PowerShell, 161 148 bytes


Try it online!

Naïve regex pattern matching. Outputs True for left-handed and False for right-handed.

Saved 13 bytes thanks to mercator golfing the regex.

  • 2
    \$\begingroup\$ You can join the alternatives for first letters C, F, H and W into [CFHW][CJKSXY] (-5), I and J into [IJ][DEMNP] (-3), shorten N into N[AFP-Z] (-1), and Z into Z. (-4), for a total of -13 bytes. New regex = A[GIU]|B[BDMNSTW]|[CFHW][CJKSXY]|DM|G[BDGSY]|[IJ][DEMNP]|K[EINY]|L[CKS]|M[OS-WYZ]|N[AFP-Z]|P[GKN]|S[BCGHORZ]|T[CHKLOTVZ]|UG|V[CGI]|Z. \$\endgroup\$ – mercator Jan 7 '18 at 1:00
  • \$\begingroup\$ @mercator Thanks for the regex golfing! \$\endgroup\$ – AdmBorkBork Jan 8 '18 at 13:30

Haskell, 137 bytes

-5 bytes thanks to ovs.

import Data.List

Try it online!

Generated the original string by hand.

  • \$\begingroup\$ got the lookup string 3 bytes shorter again: TTHSZWMSGSONPKNZMWVIDFKELSCYJPNFJMTVCXBNRBWSHKYAUGGYBTLCCKIMVGBSBBMZAINAGDMOBDIEJEMYMUNUPGSRLKTKTOTCTZ \$\endgroup\$ – ovs Jan 6 '18 at 10:30

05AB1E, 82 68 bytes

Outputs 1 for left-traffic and 0 for right-traffic.


Try it online! or as a Test Suite

Uses the string generated by totallyhuman and improved by ovs


05AB1E, 76 bytes


Try it online!


Outputs the following string:


If I split that on spaces, and interleave the alphabet into each string, it results in all the states that drive on the left side.

1 for left, 0 for right; Emigna's is better, but this felt different enough to post :).


Jelly, 69 bytes


A monadic link taking a list of characters and returning 1 if left (0 if right).

Try it online!


Uses the method as implemented totallyhuman / ovs.

ẇ“ ... ’ṃØA¤ - Link: list of characters
           ¤ - nilad followed by link(s) as a nilad:
 “ ... ’     -   base 250 number = 19752831477605543488091668410027486265612829758468833715947215534967455540194888181580207621675010690833131726534873382634884974263558670694315853304
         ØA  -   list of characters = "ABCDEFGHIJKLMNPQRSUVWXZ"
ẇ            - is a sublist of?

Also, what I did independently came in at 72 bytes:


Also a monadic link taking a list of characters and returning 1 if left (0 if right).

Try it online!


“ ... ’ṃ©ØAO0;I<0œṗ®ṭ€"ØAẎċ - Link: list of characters
“ ... ’                     - base 250 number = 20449742094039418439524274048234013619715377161457577389098927787850535557806494274193349238496252074719534810320317229
         ØA                 - list of characters = "ABCDEFGHIJKLMNPQRSUVWXZ"
        ©                   - copy to register
           O                - cast to ordinals = [71,73,85,66,68,77,78,83,84,87,67,75,88,89,77,75,74,75,66,68,71,83,89,75,68,69,77,78,69,77,80,69,73,78,89,67,75,83,79,83,84,85,86,88,90,90,65,70,80,82,86,90,72,71,75,78,68,67,66,67,71,72,79,83,90,67,72,75,76,79,84,87,90,71,67,71,73,65,83,67,66,65,77,87]
            0               - literal zero
             ;              - concatenate = [0,71,73,85,66,68,77,78,83,84,87,67,75,88,89,77,75,74,75,66,68,71,83,89,75,68,69,77,78,69,77,80,69,73,78,89,67,75,83,79,83,84,85,86,88,90,90,65,70,80,82,86,90,72,71,75,78,68,67,66,67,71,72,79,83,90,67,72,75,76,79,84,87,90,71,67,71,73,65,83,67,66,65,77,87]
              I             - incremental differences = [71,2,12,-19,2,9,1,5,1,3,-20,8,13,1,-12,-2,-1,1,-9,2,3,12,6,-14,-7,1,8,1,-9,8,3,-11,4,5,11,-22,8,8,-4,4,1,1,1,2,2,0,-25,5,10,2,4,4,-18,-1,4,3,-10,-1,-1,1,4,1,7,4,7,-23,5,3,1,3,5,3,3,-19,-4,4,2,-8,18,-16,-1,-1,12,10]
                0           - literal zero
               <            - less than (vectorises) = [0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,1,0,0,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,1,0,0]
                 œṗ         - partition at truthy indexes = ["GIU","BDMNSTW","CKXY","M","K","JK","BDGSY","K","DEMN","EMP","EINY","CKS","OSTUVXZZ","AFPRVZ","H","GKN","D","C","BCGHOSZ","CHKLOTWZ","G","CGI","AS","C","B","AMW"]
                       ØA   - list of characters = "ABCDEFGHIJKLMNPQRSUVWXZ"
                      "     - zip with:
                    ṭ€      -   tack for €ach = [["AG","AI","AU"],["BB","BD","BM","BN","BS","BT","BW"],["CC","CK","CX","CY"],["DM"],["EK"],["FJ","FK"],["GB","GD","GG","GS","GY"],["HK"],["ID","IE","IM","IN"],["JE","JM","JP"],["KE","KI","KN","KY"],["LC","LK","LS"],["MO","MS","MT","MU","MV","MX","MZ","MZ"],["NA","NF","NP","NR","NV","NZ"],["OH"],["PG","PK","PN"],["QD"],["RC"],["SB","SC","SG","SH","SO","SS","SZ"],["TC","TH","TK","TL","TO","TT","TW","TZ"],["UG"],["VC","VG","VI"],["WA","WS"],["XC"],["YB"],["ZA","ZM","ZW"]]
                         Ẏ  - tighten = ["AG","AI","AU","BB","BD","BM","BN","BS","BT","BW","CC","CK","CX","CY","DM","EK","FJ","FK","GB","GD","GG","GS","GY","HK","ID","IE","IM","IN","JE","JM","JP","KE","KI","KN","KY","LC","LK","LS","MO","MS","MT","MU","MV","MX","MZ","MZ","NA","NF","NP","NR","NV","NZ","OH","PG","PK","PN","QD","RC","SB","SC","SG","SH","SO","SS","SZ","TC","TH","TK","TL","TO","TT","TW","TZ","UG","VC","VG","VI","WA","WS","XC","YB","ZA","ZM","ZW"]
                            - ...this is the left list plus EK, OH, QC, RC, WA, XC, and YB
                            -    (which are not in the right list)
                          ċ - count

Befunge, 155 152 147 146 bytes


Try it online!

Outputs 80 for a right-handed country, and anything else indicates a left-handed country.


The bottom line of the code contains a representation of all the left-handed countries. This is a list of the first characters of the country codes, grouped by their second character. The end of each group is marked by lowercasing the last character in the group.

So for example the first group, Nz, represents NA and ZA. The second group, BSg, represents BB, SB, and GB. There is one group for each letter in the alphabet, except for the letter Q (no left-hand country codes end in Q). That empty group is represented by the character {, since that obviously won't match any valid country code.

To determine whether a given country code matches one of these entries, we iterate through the list checking whether any of the characters in the list match the first character of our input (mod 32 to account for the case), and also that the corresponding group, matches the second character of the input. The group character start as A, and is incremented every time we encounter a lowercase letter in the list.

We exit when we find a match, outputting the last character value on the stack (which will be the first character of the country code - possibly lowercase). Otherwise we'll exit when we've iterated through the whole list, in which case we will output the last number on the stack, which is always 80.


Windows Batch, 289 279 199 193 181 130 118 bytes


Outputs the ovs' string for left-hand traffic, else outputs nothing.

Note: I noticed if the input contains any country code in the list above, it will still output L. However, this does not violate the challenge rule as OP mentioned only country codes need to be handled.


@echo TTHSZ...OTCTZ            :: List all country code.(compressed by ovs)
                   |           :: Pipe the result to the find command.

                    find "%1"  :: Find the first argument in the country code list,
                               :: and output the ovs string if found.

                               :: By default, FIND returns the piped string when
                               :: a match is found.

C (gcc), 181 169 165 bytes


Try it online!

  • 2
    \$\begingroup\$ Could you use a single digit instead of 82 to save a byte? 9, for example, would output a tab character. \$\endgroup\$ – Shaggy Jan 5 '18 at 22:29

Python 2, 144 bytes


Try it online!

Prints True for left, False for right.


Retina, 150 117 bytes


Try it online!


Excel VBA, 118 Bytes

Anonymous VBE immediate window function that takes input from cell [A1] and outputs 0 if the country is right-handed


uses ovs' string


Japt, 126 100 97 bytes

Uses totallyhuman's ovs' lookup string. Takes input in lowercase and outputs false for RHD or true otherwise.


Try it

Everything between the backticks is the lookup string lowercased and compressed and ø checks if it contains the input, U.

  • 2
    \$\begingroup\$ ovs's string is much shorter now :-) \$\endgroup\$ – ETHproductions Jan 5 '18 at 20:18

Pyth, 60 57 55 50 47 46 44 bytes

00000000: 736d 406a 4322 579f 235e 804c c3eb 6f49  sm@jC"W.#^.L..oI
00000010: aee5 1f3d be3d 4e13 f326 1934 a181 a210  ...=.=N..&.4....
00000020: 7158 3f94 2232 2f43 5164 5336            qX?."2/CQdS6

Run online

Takes the input as an uppercase quoted string ('AI'). Returns 3 for left and non-3 for right.

How it works

 m           S6   map for d in [1, …, 6]:
     "…"            string literal
    C               convert to integer from base 256
   j    2           digits in base 2
  @                 wrapping index at:
           Q          input string
          C           convert to integer from base 256
         /  d         integer division by d
s                 sum

Generating the magic string

import binascii
import z3
n, k, c = 239, 6, 3
a = [z3.Bool('a{}'.format(i)) for i in range(n)]
def f(s0, s1):
    return z3.Sum([z3.If(a[(ord(s0) * 256 + ord(s1)) // j % n], 1, 0) for j in range(1, k + 1)]) == c
solver = z3.Solver()
for s0, s1 in ['AI', 'AG', 'AU', 'BS', 'BD', 'BB', 'BM', 'BT', 'BW', 'VG', 'BN', 'KY', 'CX', 'CC', 'CK', 'CY', 'DM', 'FK', 'FJ', 'GD', 'GG', 'GY', 'HK', 'IN', 'ID', 'IE', 'IM', 'JM', 'JP', 'JE', 'KE', 'KI', 'LS', 'MO', 'MW', 'MY', 'MV', 'MT', 'MU', 'MS', 'MZ', 'NA', 'NR', 'NP', 'NZ', 'NU', 'NF', 'PK', 'PG', 'PN', 'SH', 'KN', 'LC', 'VC', 'WS', 'SC', 'SG', 'SB', 'SO', 'ZA', 'GS', 'LK', 'SR', 'SZ', 'TH', 'TL', 'TK', 'TO', 'TT', 'TC', 'TV', 'UG', 'GB', 'TZ', 'VI', 'ZM', 'ZW']:
    solver.add(f(s0, s1))
for s0, s1 in ['AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AQ', 'AR', 'AM', 'AW', 'AT', 'AZ', 'BH', 'BY', 'BE', 'BZ', 'BJ', 'BO', 'BA', 'BV', 'BR', 'IO', 'BG', 'BF', 'BI', 'CV', 'KH', 'CM', 'CA', 'CF', 'TD', 'CL', 'CN', 'CO', 'KM', 'CG', 'CR', 'CI', 'HR', 'CU', 'CW', 'CZ', 'KP', 'CD', 'DK', 'DJ', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FO', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GP', 'GU', 'GT', 'GW', 'GN', 'HT', 'HM', 'VA', 'HN', 'HU', 'IS', 'IR', 'IQ', 'IL', 'IT', 'JO', 'KZ', 'KW', 'KG', 'LA', 'LV', 'LB', 'LR', 'LY', 'LI', 'LT', 'LU', 'MG', 'ML', 'MH', 'MQ', 'MR', 'YT', 'MX', 'FM', 'MC', 'MN', 'ME', 'MA', 'MM', 'NL', 'NC', 'NI', 'NG', 'NE', 'MP', 'NO', 'OM', 'PW', 'PA', 'PY', 'PE', 'PH', 'PL', 'PT', 'PR', 'QA', 'KR', 'MD', 'RE', 'RO', 'RU', 'RW', 'BL', 'MF', 'PM', 'SM', 'ST', 'SA', 'SN', 'RS', 'SL', 'BQ', 'SX', 'SK', 'SI', 'SS', 'ES', 'PS', 'SD', 'SJ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'MK', 'TG', 'TN', 'TR', 'TM', 'UA', 'AE', 'UM', 'US', 'UY', 'UZ', 'VU', 'VE', 'VN', 'WF', 'EH', 'YE']:
    solver.add(z3.Not(f(s0, s1)))
res = solver.check()
if res == z3.sat:
    m = solver.model()
    print('n={} k={} c={} a={!r}'.format(n, k, c, binascii.unhexlify('{:0{}x}'.format(
        int(''.join('01'[z3.is_true(m[x])] for x in a), 2), n // 8 * 2))))

sed, 148+1 145+1 143+1 142+1 bytes

One extra byte for -r flag (POSIX extended regexes).

Outputs empty string for left-handed traffic, original country code for the right-handed traffic.






Explained edit history:

    naïve regexp; the only optimization here is 'Z.'
    N[AFPRUZ] → N[AFP-Z]
    the replacements can match inexistent coutries, which is totally fine
    |[^DMS]K (which also matches impossible country codes) allows these changes:
    C[CKXY] → C[CXY]
    F[JK] → FJ
    |HK → ∅
    L[CKS] → L[CS]
    P[GKN] → P[GN]
    J[EMP] → J[^O] (thanks @Neil)

sed, 158+1 155+1 153+1 152+1 bytes, non-empty answer

Slight variation of the previous one. Returns L for left-handed traffic.

  • 1
    \$\begingroup\$ Can you use J[^O] instead of J[EMP]? \$\endgroup\$ – Neil Jan 6 '18 at 15:16
  • \$\begingroup\$ FYI I tried grouping by second letter but the best I could do was 3 bytes longer: [^L]B|[^EMN]C|GD|[I-K]E|[AGPSUV]G|[AKV]I|FJ|[^DMS]K|TL|JM|[KP]N|JP|SR|[BGLW]S|[BT]T|AU|TV|CX|[CGK]Y|M[OS-WYZ]|N[AFP-Z]|[BI][DMNW]|[ST][HOZ]|Z. \$\endgroup\$ – Neil Jan 6 '18 at 15:50
  • \$\begingroup\$ Huh, J[^O] was actually once on my list of smaller regexes, I wonder how I missed it. Thanks for pointing this out! As for grouping by the second letter: in addition to grouping by K you can just use |[AGPSUV]G or |[BGLW]S but it won't change total score at all. \$\endgroup\$ – Thriller Jan 8 '18 at 5:11

APL (Dyalog), 108 bytes


Try it online!

Using the lookup string by ovs.

Left-handed traffic = 1.
Right-handed traffic = 0.


Javascript (ES6), 118 116 bytes

Saved 2 bytes thanks to @Craig Ayre


Returns null for right-handed traffic

Test Cases



  • \$\begingroup\$ Could you use String.prototype.match() and have right-handed traffic denoted by null? Would save 2 bytes \$\endgroup\$ – Craig Ayre Jan 8 '18 at 15:08

K, 105 bytes

For information about K/Q languages see code.kx.com

Use: Country-code (2-char string, example "XY") after


Generates 1b (Left-handed traffic) or 0b (not Left-handed traffic)


  • 5h$"XX" generates ascii codes for each char of the 2-char string (country-code), Example 5h$"TB" generates 84 66

  • -65+integerList substract 65 to each integer in the list. Example -65+5h$"TB" generates 19 1

  • 26/:integerList computes integer equivalent to that list as digits in 26-base. Example 26/:-65+5h$"TB" generates 495 (country-code as integer)

  • in[;listOfCountryCodesAsIntegers]@x returns boolean value (1b = true, 0b = false). True if x is in the list

  • +\-48+5h$"62<729151368=1>a1A23<6<C181A83?45;488F411112115:235Q43r141738353135247F42Tl<:" calculates list of integers for each country code with Left-handed traffic

    • "62<729151368=1>a1A23<6<C181A83?45;488F411112115:235Q43r141738353135247F42Tl<:" is the 'distance string' (distance between each pair of integer-country-codes in ascending order, codified as char). Distance n is codified as ascii char 48+n

    • -48+5h$".." calculates ascii value of each char in string ".." and recover original distance as ascii-code - 48. The result is the list of distances

    • +\integerList calculates partial summation of items from the list -> absolute integer-country-codes from distances between codes.


  • Returns 0b for any non-left-handed country-code, including not valid country codes
  • We can save a char reformatting the code, but requires to write country-code "XX" inside the code (i don't know if it's valid, but i'm quite sure it's not elegant) in[26/:-65+5h$"XX";+\-48+5h$"..."]

Vim, 117 109 108 keystrokes


Try it online! (replace SE in the header with the country code)

is the escape key. The program prints the following text for right-handed traffic:



oSZAINA...OTTCTZ␛ Input the lookup-string on a new line
kg*D              Delete the everything after the last occurence of the country code
                   on the same line
  • \$\begingroup\$ I appreciate that you're answering in my favourite text editor, clever use of choosing a value for right! \$\endgroup\$ – ბიმო Jan 6 '18 at 16:13

MY-BASIC, 162 bytes

Anonymous Function that takes input as an unwrapped string (that is, without parenthesis) and outputs to the console

For y=0 To 100
Print z

Returns 0 for right-handed and 1 for left-handed traffic, try it online!


Yabasic, 127 bytes

Anonymous function that takes input as an unwrapped string (no "...") and outputs 0 if the Country is right-handed and 1 if the country is left handed.


Try it online!


C (gcc), 115 107 bytes


Try it online!

Returns 0 if left handed. -4 thanks to @JonathanFrech

  • \$\begingroup\$ Could you not define your function to take a short* as parameter? \$\endgroup\$ – Jonathan Frech Sep 19 '18 at 0:55

Vyxal r, 65 bytes


Try it Online!


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.