bcLOG

bencooper.xyz

๐Ÿ‡จ๐Ÿ‡ญ Flag Symmetry

July 6, 2024

Pirates and Protest

Back in ye olde days when privateers were near the top of a sailor's concerns, flying a flag upside down was thought to be a way to signal to allied ships that you were in distress. Thatโ€™s great news for the majority of countries, but for a select 14, and a few others, whose flags' mirror images are so similar to the original that you really canโ€™t tell (looking at you, Great Britain), this was not possible.

Flying a flag upside down has since become a common form of protest (and, at one point, even ended up as a case in front of the supreme court!). This protest method has come up in a number of high profile occasions over the past few years (Jan. 6th, Overturning of Roe v Wade, Maro Lago FBI raid, and Justice Alito's home).

When discussing these events with a friend during a long car ride, we began joking about how this form of protest wouldnโ€™t be possible in a country like Switzerland, since there is no one "correct" way to hang the flag (assuming you arenโ€™t being a smart-ass and hanging it from a corner or something).

This, of course, led to a game of guessing which other flags would fall into this category of "unflippable," and this project idea was born.

A lil rusty

I decided to use this as an excuse to try out Rust lang since there are some more advanced embedded project ideas that I want to work up to in the future.

The code basically loops through pixels in a flag, comparing them across the vertical and horizontal axis. At first I thought I was done with the project in the first few hours of working on it until I discovered Japan wasn't included in the fully symmetrical category!

Frustratingly, this was due to the structure of the png images I was getting back from the api. There were significant differences in many 1-to-1 pixel comparisons around the central circle, despite the area representing the mirrored curve.

I had to switch my approach to a fuzzy-match window that I could bring in as a secondary check when the 1-to-1 check failed. This was a bit of a doozy but a great learning experience (I see why people like this language so much).

The results

-> you can find a csv of the detailed results on github

+----------------------------------------+-----+
| ๐Ÿชฉ Flags with full symmetry            | 14  |
+----------------------------------------+-----+
| โ†•๏ธ Flags with horizontal line symmetry  | 23  |
+----------------------------------------+-----+
| โ†”๏ธ Flags with vertical line symmetry    | 42  |
+----------------------------------------+-----+
| โŒ Flags with no symmetry              | 173 |
+----------------------------------------+-----+

Full symmetry flags: ๐Ÿ‡ต๐Ÿ‡ช๐Ÿ‡ฏ๐Ÿ‡ฒ๐Ÿ‡ฏ๐Ÿ‡ต๐Ÿ‡น๐Ÿ‡ญ๐Ÿ‡ซ๐Ÿ‡ฒ๐Ÿ‡ฑ๐Ÿ‡ป๐Ÿ‡จ๐Ÿ‡ญ๐Ÿ‡ง๐Ÿ‡ผ๐Ÿ‡ฎ๐Ÿ‡ฑ๐Ÿ‡ฆ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡ฐ๐Ÿ‡ฌ๐Ÿ‡ฌ๐Ÿ‡ณ๐Ÿ‡ฌ๐Ÿ‡ฌ๐Ÿ‡ช
Horizontal line symmetry flags: ๐Ÿ‡ฌ๐Ÿ‡พ๐Ÿ‡ฆ๐Ÿ‡ฝ๐Ÿ‡ต๐Ÿ‡ผ๐Ÿ‡ฌ๐Ÿ‡ณ๐Ÿ‡ฒ๐Ÿ‡ซ๐Ÿ‡ซ๐Ÿ‡ด๐Ÿ‡ฎ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡ฉ๐Ÿณ๏ธ๐Ÿ‡จ๐Ÿ‡ฎ๐Ÿ‡ธ๐Ÿ‡ช๐Ÿ‡ฉ๐Ÿ‡ฐ๐Ÿ‡ง๐Ÿ‡ญ๐Ÿ‡ธ๐Ÿ‡ฏ๐Ÿ‡ฒ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡ธ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ถ๐Ÿ‡ฆ๐Ÿ‡ท๐Ÿ‡ด๐Ÿ‡ฎ๐Ÿ‡น
Vertical line symmetry flags: ๐Ÿ‡ฌ๐Ÿ‡ฆ๐Ÿ‡ธ๐Ÿ‡ท๐Ÿ‡ท๐Ÿ‡ช๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ธ๐Ÿ‡ด๐Ÿ‡ฒ๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡น๐Ÿ‡ท๐Ÿ‡บ๐Ÿ‡น๐Ÿ‡ฏ๐Ÿ‡ญ๐Ÿ‡บ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ฒ๐Ÿ‡ฒ๐Ÿ‡ป๐Ÿ‡ณ๐Ÿ‡ธ๐Ÿ‡พ๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ง๐Ÿ‡ฌ๐Ÿ‡ป๐Ÿ‡ช๐Ÿ‡ธ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡จ๐Ÿ‡ฑ๐Ÿ‡บ๐Ÿ‡ญ๐Ÿ‡ณ๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡จ๐Ÿ‡ด๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฎ๐Ÿ‡ฉ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡ง๐Ÿ‡ฎ๐Ÿ‡ฒ๐Ÿ‡ท๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡ฆ๐Ÿ‡ฆ๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡ด๐Ÿ‡ช๐Ÿ‡บ๐Ÿ‡ง๐Ÿ‡ง๐Ÿ‡ฑ๐Ÿ‡จ๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ฆ๐Ÿ‡ฒ๐Ÿ‡จ๐Ÿ‡ฆ๐Ÿ‡ณ๐Ÿ‡ช๐Ÿ‡พ๐Ÿ‡ช
No symmetry flags: ๐Ÿ‡ฟ๐Ÿ‡ผ๐Ÿ‡น๐Ÿ‡จ๐Ÿ‡ญ๐Ÿ‡ฐ๐Ÿ‡ป๐Ÿ‡จ๐Ÿ‡ฆ๐Ÿ‡ธ๐Ÿ‡ณ๐Ÿ‡บ๐Ÿ‡ฎ๐Ÿ‡ด๐Ÿ‡ฑ๐Ÿ‡พ๐Ÿ‡ฒ๐Ÿ‡ถ๐Ÿ‡ง๐Ÿ‡ฒ๐Ÿ‡จ๐Ÿ‡ฐ๐Ÿ‡ง๐Ÿ‡ฟ๐Ÿ‡ธ๐Ÿ‡ฌ๐Ÿ‡ช๐Ÿ‡ฌ๐Ÿ‡ต๐Ÿ‡ฆ๐Ÿ‡ฟ๐Ÿ‡ฆ๐Ÿ‡ฐ๐Ÿ‡ฌ๐Ÿ‡ฏ๐Ÿ‡ช๐Ÿ‡ผ๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡ท๐Ÿ‡ฏ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡บ๐Ÿ‡ฟ๐Ÿ‡ง๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ธ๐Ÿ‡ญ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ญ๐Ÿ‡ฐ๐Ÿ‡ท๐Ÿ‡น๐Ÿ‡ฌ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ช๐Ÿ‡น๐Ÿ‡ณ๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡น๐Ÿ‡ณ๐Ÿ‡ซ๐Ÿ‡จ๐Ÿ‡ผ๐Ÿ‡ธ๐Ÿ‡ธ๐Ÿ‡ง๐Ÿ‡ฏ๐Ÿ‡ฑ๐Ÿ‡ฐ๐Ÿ‡ง๐Ÿ‡ด๐Ÿ‡ฆ๐Ÿ‡ฎ๐Ÿ‡ต๐Ÿ‡ฌ๐Ÿ‡จ๐Ÿ‡ป๐Ÿ‡ฐ๐Ÿ‡ต๐Ÿ‡ฎ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ฎ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿณ๏ธ๐Ÿ‡ผ๐Ÿ‡ธ๐Ÿ‡ง๐Ÿ‡ธ๐Ÿณ๏ธ๐Ÿ‡ง๐Ÿ‡ซ๐Ÿ‡ฒ๐Ÿ‡ญ๐Ÿ‡ฐ๐Ÿ‡ฟ๐Ÿ‡บ๐Ÿ‡ณ๐Ÿ‡ณ๐Ÿ‡จ๐Ÿ‡ต๐Ÿ‡น๐Ÿ‡จ๐Ÿ‡ฑ๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฌ๐Ÿ‡ฌ๐Ÿ‡ซ๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ฌ๐Ÿ‡ต๐Ÿ‡ญ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡ช๐Ÿ‡ฆ๐Ÿ‡ผ๐Ÿ‡ฒ๐Ÿ‡ฝ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡ง๐Ÿ‡ฆ๐Ÿ‡ฒ๐Ÿ‡น๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡ฐ๐Ÿ‡ฎ๐Ÿ‡ซ๐Ÿ‡ฐ๐Ÿ‡ต๐Ÿ‡ณ๐Ÿ‡น๐Ÿ‡ฐ๐Ÿ‡ณ๐Ÿ‡ฆ๐Ÿ‡ฆ๐Ÿ‡ฟ๐Ÿ‡จ๐Ÿ‡ท๐Ÿ‡จ๐Ÿ‡ฟ๐Ÿ‡ฌ๐Ÿ‡ฑ๐Ÿ‡ธ๐Ÿ‡ฝ๐Ÿ‡ฆ๐Ÿ‡ช๐Ÿ‡จ๐Ÿ‡ซ๐Ÿณ๏ธ๐Ÿ‡ฐ๐Ÿ‡ฒ๐Ÿ‡น๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ฟ๐Ÿ‡ฌ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡ฌ๐Ÿ‡จ๐Ÿ‡ณ๐Ÿ‡ฆ๐Ÿ‡ท๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡ง๐Ÿ‡ฑ๐Ÿ‡ณ๐Ÿ‡ต๐Ÿ‡ฐ๐Ÿ‡ผ๐Ÿ‡ซ๐Ÿ‡ฏ๐Ÿณ๏ธ๐Ÿ‡ฐ๐Ÿ‡พ๐Ÿ‡ฒ๐Ÿ‡พ๐Ÿ‡ฌ๐Ÿ‡ธ๐Ÿ‡ฌ๐Ÿ‡บ๐Ÿ‡พ๐Ÿ‡น๐Ÿ‡ต๐Ÿ‡ซ๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡จ๐Ÿ‡พ๐Ÿ‡ต๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡ณ๐Ÿ‡บ๐Ÿ‡พ๐Ÿ‡ฎ๐Ÿ‡ฒ๐Ÿ‡บ๐Ÿ‡ฌ๐Ÿ‡น๐Ÿ‡ฑ๐Ÿ‡ง๐Ÿ‡ณ๐Ÿณ๏ธ๐Ÿ‡ฎ๐Ÿ‡ถ๐Ÿ‡ฒ๐Ÿ‡ฉ๐Ÿ‡ง๐Ÿ‡น๐Ÿ‡ง๐Ÿ‡พ๐Ÿ‡ช๐Ÿ‡จ๐Ÿ‡ธ๐Ÿ‡ฉ๐Ÿ‡ธ๐Ÿ‡ฆ๐Ÿ‡ด๐Ÿ‡ฒ๐Ÿ‡ฑ๐Ÿ‡ง๐Ÿ‡ฆ๐Ÿ‡ถ๐Ÿ‡ฐ๐Ÿ‡ณ๐Ÿ‡ฐ๐Ÿ‡ช๐Ÿ‡ฒ๐Ÿ‡ผ๐Ÿ‡ฌ๐Ÿ‡ผ๐Ÿ‡ช๐Ÿ‡ท๐Ÿ‡ฌ๐Ÿ‡ถ๐Ÿ‡ฉ๐Ÿ‡ฒ๐Ÿ‡ฐ๐Ÿ‡ญ๐Ÿ‡ธ๐Ÿ‡ฒ๐Ÿ‡ต๐Ÿ‡ฐ๐Ÿ‡ฝ๐Ÿ‡ฐ๐Ÿ‡ฉ๐Ÿ‡ฏ๐Ÿ‡น๐Ÿ‡ผ๐Ÿ‡ท๐Ÿ‡ผ๐Ÿ‡จ๐Ÿ‡ฒ๐Ÿ‡ฆ๐Ÿ‡ฉ๐Ÿ‡ธ๐Ÿ‡ญ๐Ÿ‡ป๐Ÿ‡ฌ๐Ÿ‡น๐Ÿ‡ด๐Ÿ‡ฆ๐Ÿ‡ด๐Ÿ‡ฌ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡ป๐Ÿ‡ฒ๐Ÿ‡ฟ๐Ÿ‡จ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡จ๐Ÿ‡ป๐Ÿ‡ฆ๐Ÿ‡ต๐Ÿ‡พ๐Ÿ‡ธ๐Ÿ‡ฐ๐Ÿ‡ฟ๐Ÿ‡ฒ๐Ÿ‡ฒ๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡ป๐Ÿ‡น๐Ÿ‡ฟ๐Ÿ‡ต๐Ÿ‡ท๐Ÿ‡ป๐Ÿ‡ฎ๐Ÿ‡ฉ๐Ÿ‡ด๐Ÿ‡ฉ๐Ÿ‡ฟ๐Ÿ‡ฒ๐Ÿ‡ต๐Ÿ‡ณ๐Ÿ‡ฟ๐Ÿ‡ฑ๐Ÿ‡ท๐Ÿ‡ป๐Ÿ‡บ๐Ÿ‡ฑ๐Ÿ‡ธ๐Ÿ‡ฌ๐Ÿ‡ฉ๐Ÿ‡ธ๐Ÿ‡ณ๐Ÿ‡ฒ๐Ÿ‡ป๐Ÿ‡ง๐Ÿ‡ท๐Ÿ‡ฆ๐Ÿ‡ซ๐Ÿณ๏ธ๐Ÿ‡ต๐Ÿ‡ฒ