K4 Countries

October 2022

It’s hard to motivate the listing of all the groups of 4 countries that border one another. It doesn’t force the four-coloring of maps — these states need four colors even though they don’t have a K4 group:

Oregon, Idaho, Nevada, California, Utah, and Arizona

It sort of relates to the quadripoint, which which may or may not exist at an intersection of Namibia, Zambia, Zimbabwe, and Botswana, but not really.

Screenshot of one article in Geopolitics and one in the New York Times

And there’s no geopolitical angle. Some K4 groups have conflict, some not.

So with little reason, here are the 12 groups of four countries that border one another according to World Bank data:

  1. Bolivia, Paraguay, Brazil, and Argentina
  2. Rwanda, Tanzania, the Democratic Republic of the Congo, and Burundi
  3. Rwanda, Tanzania, Uganda, and the Democratic Republic of the Congo
  4. Tanzania, Malawi, Zambia, and Mozambique
  5. Turkey, Azerbaijan, Iran, and Armenia
  6. Serbia, Croatia, Bosnia and Herzegovina, and Montenegro
  7. Lithuania, Poland, Belarus, and Russia
  8. Lithuania, Russia, Belarus, and Latvia
  9. Poland, Belarus, Ukraine, and Russia
  10. Turkey, Azerbaijan, Armenia, and Georgia
  11. Luxembourg, France, Germany, and Belgium
  12. France, Netherlands, Germany, and Belgium

And the code that found them:

import json
from itertools import combinations
from collections import defaultdict

# https://datacatalog.worldbank.org/search/dataset/0038272/World-Bank-Official-Boundaries
# "World Boundaries GeoJSON - Very High Resolution"
with open("WB_Boundaries_GeoJSON_highres/WB_Admin0_boundary_lines.geojson") as f:
    gj = json.load(f)

assocs = {
    "Sint Maarten": "Netherlands",
    "Saint Martin": "France",
    # Cyprus associations are arbitrary and don't affect the output
    "Cyprus U.N. Buffer Zone": "Cyprus",
    "Cyprus No Mans Area": "Cyprus",
    "Dhekelia Sovereign Base Area": "United Kingdom",
    "Northern Cyprus": "Turkey",

def assoc(country):
    if country in assocs:
        return assocs[country]
    return country

# Build adjacency list
d = defaultdict(set)
for feature in gj["features"]:
    i = assoc(feature["properties"]["adm0_left"])
    j = assoc(feature["properties"]["adm0_right"])
    if i == j: continue

# Brute force K_4 subgraphs
# Lots of sets to paper over my laziness
subgraphs = set()
for i in d:
    for j in combinations(d[i], 3):
        if j[0] in d[j[1]] and j[1] in d[j[2]] and j[2] in d[j[0]]:
            subgraphs.add(frozenset([i, j[0], j[1], j[2]]))

for s in subgraphs: print(s)