1
Awhile back I encountered a simple programming puzzle to determine whether a string was a pangram, or a perfect pangram. (Although it's worth noting that this particular challenge gave a different meaning than the standard definition of a "perfect pangram," to mean any sentence where every letter appears n times for some positive n). And it was a fun challenge. But recently it got me wondering whether it would be possible to solve this challenge purely with regular expressions. If it is, I expect it will be a pretty gnarly regex. But I'm not even sure it is possible.
Still, if anyone is able to do it, it would be the folks here at Code Golf. So here's the challenge:
Write a regular expression which can determine whether or not a given string is a pangram. You can assume that all non-alpha characters have already been stripped out (or don't, if you really want to challenge yourself), and that everything has been transformed into lowercase.
Bonus challenge: write another regular expression to determine whether the given string is a "perfect pangram" by the definition given above.
Examples of an ordinary pangram:
thequickbrownfoxjumpsoverthelazydog
Example of perfect pangrams:
abcdefghijklmnopqrstuvwxyz
jocknymphswaqfdrugvexblitz
squdgykilpjobzarfnthcwmvexhmfjordwaltzcinqbuskpyxveg
I'm not really sure if this is even possible just with regex alone. If you find that it is, kudos!
2Pity that Martin is on leave – Luis Mendo – 2018-09-25T21:53:24.280
1Pangram, not anagram – soapergem – 2018-09-25T22:02:30.227
Quoted verbatim from the question above (read the question): "any sentence where every letter appears n times for some positive n." – soapergem – 2018-09-25T22:05:57.683
8Let me rephrase, as my previous comment was a mess: 1) This needs a winning criterion. Code golf? 2) Bonuses are almost always a bad idea. There should be a single task/objective to the challenge. Having two is confusing, and probably useless, as people will go fot the easier one. 3) What flavours of regexes are allowed? – Luis Mendo – 2018-09-25T22:20:57.937
2
Not sure what regexes are able to do, but the grammar is certainly not regular which can easily be proven with the Pumping Lemma (just set $w = a^p b^p \cdots z^p$) - so it's likely a regex won't not do the job (it's regular-expression after all).
– ბიმო – 2018-09-26T16:09:27.180Thinking about this a bit more: I don't have background in theoretical CS/automata theory, so I could be missing something, but doesn't the pumping lemma allow you to duplicate the entire string? In your example, ww would also be a valid perfect pangram. – Jack Brounstein – 2018-09-26T19:24:25.360
@BMO I'm well aware that regex is not well-suited for this task... but that's part of the fun, and why I'm asking here at code golf. – soapergem – 2018-09-26T19:26:23.963