upvote
Maybe there's an allegory to the sciences. But I rather a model be suboptimal in encoding that can be used to generate hypothetical reasonable flags in its unpopulated states, than having an optimal encoding which doesn't answer questions or reveal possibilities in its unpopulated states. Like what does flag #0xFE look like in an 8-bit encoding? I really like the idea of driving compressed trees in reverse with random data to generate new fascinating (valid) sequences.

Also, for compressing into 8 bits - is this not like saying "I can compress all of Shakespeare's plays in 6 bits" because there are ~39 plays, but then the size of the "shakespearezip" is just the sum of the works?

reply
> But I rather a model be suboptimal in encoding that can be used to generate hypothetical reasonable flags in its unpopulated states, than having an optimal encoding which doesn't answer questions or reveal possibilities in its unpopulated states

This encoding already goes too far towards “support the existing flags”.

As a simple example, look at the pattern of the flag of the Comoros (https://en.wikipedia.org/wiki/Flag_of_the_Comoros). Even using just the top colours (FTA: “red, then white, blue, yellow/gold, green, black and orange”), there already are 7 × 6 × 5 × 5 × 5 = 5,250 ways to colour it so that no two neighbouring colour bands are identical. That alone doesn’t fit into 12 bits.

Even limiting one to all colours different, there still are 7 × 6 × 5 × 4 × 3 = 2,520 colourings using the 7 most popular colours. That’s (just) over 11 bits.

And then, you still have to encode the crescent with the four stars.

reply
Okay, but the article literally uses "Union Jack" as a primative.
reply
That is an orthogonal matter and maybe my imagination is limited. But when I think of realistic new flags I do not think of a union jack missing its right diagonal in the corner (e.g. if we decide to decompose the UJ primitive).

We could also complain that the crescent is a complex primitive. Why not define it with three parameters: two circle radii with a center offset?

Choosing the primitives is hard and requires domain knowledge/taste, and finding a simple enough implementation solving for key usecases (e.g. decent coverage of maps, meaningful bit encoding) and descoping (e.g. deciding on no emblems) is also hard.

But I am personally impressed with the primitives the author created and the scope simplifications done to achieve it.

reply
I don't understand why this is the top comment. The article isn't about encoding a bag of unique items, it's about drawing the flag. So of course you can do it in 8 bits, because you're just storing the "id", not how to draw it.
reply
I've read the requirements [0] section of the article and it doesn't contain anything that would prevent you from just storing all the flags in the decoder and using an id.

In fact, the article says

> With this (rather primitive) format I managed to encode 128 flags with varying success.

Which means that, actually, 7 bits would be enough.

So, this comment is (correctly) pointing out that requirements are imprecise.

You may find such "rules lawyering" obnoxious, but I think that in the real world tasks it is often useful to clarify such things, because it let's you avoid doing hard and complex work that is actually not needed.

I think that every experienced developer has this automatic response to reading a list of requirements: "here is a shortcut that will technically fulfill all the requirements. Please, either tell me that it is okay to do it, or update your requirements to close this loophole".

[0] https://read.vantezzen.io/miniflags#3d8e32040c2a808e8d95c8a0...

reply
Yeah. I had to read the comment a few times to make sure that I'm not missing anything, but you are right. Those are two distinct things.

As a side note, the title is not accurate either because the method in the article can compress only one flag to 11 bits:

> Using this format, the average flag can be represented in 76 bits, with a median of 55 bits.

One can use Huffman encoding (the same encoding the article uses) to compress one of the flags to a single bit.

reply
The actual article borders on just using IDs too. Things like the Union Jack are just stored as is.

The techniques here let you encode the currently existing flags but aren’t really enough to build a flag from scratch.

reply
I’d give it a bit more credit than that. They encoded 128 flags with their scheme, only 5 of which have the union jack. The rest are truly built from scratch.

While in fairness the remaining flags seem like they would need more hard coded symbols, it’s still interesting as a procedural plausible flag generator.

reply
A spec-compliant Unicode renderer is expected to render 259 flags [1]. So 8 bits isn't quite enough. You would need 9.

Obviously an arbitrary bitmap of dimensions that could be used for a recognizable flag would need orders of magnitude more storage. The constraint that we are representing a finite set of flags is what admits such a compact representation.

[1] https://www.unicode.org/Public/emoji/latest/emoji-sequences....

reply
262 if you include the flags of England, Scotland, and Wales, which for some reason are the only flags in their own separate blocs.
reply
I’m surprised that the near-identical flags list omits Slovenia and Slovakia which both have white-blue-red horizontal stripes and a coat of arms (albeit with slightly different placement and different background colors on the coats of arms). A part of me feels like it’s part of a long-time joke the two countries are playing to confuse non-Slavs (the Slovenian word for their language is Slovenščina while the Slovak word for their language is Slovenčina and this is just the beginning of the confusion between the two countries/nationalities).
reply
There are only 500K or so full length feature films so we should be able to encode them in about 18 bits or so. Who needs mp4 anyway!
reply
I can't believe that second article doesn't include images of the flags it is talking about. Not even the links provided for each country show the flag...
reply
Well it uses their emoji so you can see them. At least on my phone using brave. Iirc firefox doesn't reliably render them but I'm not sure
reply
Fennec (F-Droid's Gecko) renders it all greatly.
reply
No emoji in Firefox or Chrome here. Firefox does render emoji reliably, no need for the FUD. On Windows, Firefox even renders flags, which the OS does not due to Microsoft's previous issues with countries complaining about maps with disputed borders.
reply
you could also exploit the fact that some flags may appear more frequently than others and use huffman encoding or something to encode the commonly used flags in a shorter sequence than rarely-mentioned countries, and save some bits on average
reply
but then you have to have the svg built into decoder. will they be smaller than 5KB?

also then it's no different from a svg sprite

reply
I feel like it would be unfair to make them include the SVG decoder, the artical uses TypeScript and I believe that is a feature most runtimes (browsers) provide. However they do have to include the SVG files themselves. The Canadian flag from Wikimedia comes in at 699 bytes and France at 262 bytes. So I'm fairly confident that even with compression they'll be over 5kB
reply
I had exactly the same idea. I would give them even 9 bits to have headroom
reply