Top
Best
New

Posted by bennett_dev 2 days ago

Compressing a flag to 11 bits(read.vantezzen.io)
142 points | 59 commentspage 3
classified 2 hours ago|
I thought it was meant ironically because a flag (in software) is just one bit.
ButlerianJihad 5 hours ago||
I had some physical therapy sessions back in 2021, and during that time, I discovered the myths of Procrustes and his infamous bed. I shared the profile of Procrustes with the doctor of PT, and he was thrilled. He will probably get a tattoo of that guy.

Perhaps every month I should bestow a Procrustean Award on some Show HN like this. I hereby proclaim the September 2026 Procrustean Award goes to vantezzen for their 11-bit flag-encoding.

I will also point out that flags change over time, and there may be more than one flag in use by an entity (the latter is something that Unicode ignores.)

And my favorite flag drama of the 2020s is when Wikipedia "discovered" that its Vatican Flag image was "wrong"... after distributing it far and wide: https://www.ewtnnews.com/world/us/wikipedia-had-the-wrong-va...

dxdm 3 hours ago|
https://en.wikipedia.org/wiki/Procrustes

> In Greek mythology, Procrustes [...] was a rogue smith and bandit from Attica who attacked people by stretching them or cutting off their legs, so as to force them to fit the size of an iron bed.

> The word Procrustean is thus used by analogy to describe, for example, situations where an arbitrary standard is used to measure success, while completely disregarding obvious harm that results from the effort.

akoboldfrying 4 hours ago||
How to encode all flags in a minimum number of bits:

1. Quantise colours to, say, 8 colours that you can confidently distinguish. Use a scheme that prefers "most commonly used" colours that actually appear in the flags.

2. Render each colour-quantised flag to a fixed-size bitmap, e.g., 100x50.

3. We seek a minimum-size subset of pixel locations P such that every pair of flags differs in colour at at least one of these pixel locations. This is the NP-complete problem Minimum Test Set [0] -- in fact, a slight generalisation, because the answer to each "test" (pixel location) is not yes or no but one of 10 colours. You could try to solve this by growing an exactly minimal solution using branch and bound, but this is likely to be too slow for such a large bitmap. Alternatively, I expect repeatedly running a heuristic that builds solutions by randomly adding any pixel location until all flags become distinguishable to be highly effective as there will likely be many equal-size optimal solutions, though of course you won't get an optimality guarantee this way.

4. At this point, since the 8 colours can be represented by 3 bits each, you basically have a 3|P|-bit "hash" that distinguishes all flags. If that is still bigger than log2(nFlags), you could shrink it further with standard minimal perfect hashing techniques.

ETA: There are a few ways to improve this. One thing you want is to choose relatively "stable" pixel locations that are not close to boundaries between colours on any flag, to avoid the problem of slightly different rasterisations of the same flag giving different answers (imagine if you were applying this to scanned photos of flags). To achieve this, you could compute, for each pixel location, a "stability value": The minimum distance in pixels to any differently-coloured pixel, across all flags. Then instead of considering all 100x50 pixel locations, you might consider only the 30 with the highest stability values. With such a small set of pixel locations to consider, it's feasible to consider all ~1 billion subsets of them, giving you a known-optimal solution.

[0]: https://cs.stackexchange.com/a/81189

fercircularbuf 9 hours ago||
you couldn't dedicate one of those bit patterns to nepal?

fun stuff

fercircularbuf 9 hours ago|
or treat the triangles as if they were part of a larger white flag?
01HNNWZ0MV43FF 8 hours ago||
> Some kind of custom rectangle happening in the top left

I believe that is a "canton": https://en.wikipedia.org/wiki/Canton_(flag)

> In vexillography, the canton is a rectangular emblem usually placed in the upper hoist of a flag, usually occupying up to a quarter of a flag's area. The canton of a flag may be a flag in its own right. For instance, British ensigns have the Union Jack as their canton, as do their derivatives such as the national flags of Australia and New Zealand.

They say it's in the "upper hoist" because it's not per se the top left - If the flag is flying and you're seeing it from behind, it may be the top right. Either way it is the side closer to the flag pole, or whatever it's flying from. When shown on a computer screen or in print, usually it is the top left. Some flag codes require flags to be mirrored on the right side of vehicles or uniforms so that it always appears to be flying from the vehicle or person as they move forward.

keeldev 2 hours ago||
Fun demo. One quibble for the compression-as-intelligence discussion below: the honest accounting is 11 bits plus the decoder. If you only count the payload, any dataset compresses to ~nothing -- just bake the whole thing into the decoder. Kolmogorov complexity counts the whole package: data plus decompressor. That's not a knock on this post (11 bits plus a small hand-rolled decoder is still a genuinely tight encoding), it's just the yardstick that keeps these competitions honest -- and it's why prizes like the Hutter Prize score the compressor itself, not just the compressed blob.
AdieuToLogic 10 hours ago|
This reminds me of the old joke[0]:

  There are 10 kinds of people in the world.
  Those who understand binary and those who don't.
0 - https://www.gnu.org/fun/jokes/10-kinds-of-people.html.en