Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Very cool! The top answer has a 12,731 character regular expression that matches base 10 numbers that are divisible by 7. (There is an answer with only 105 characters, but that uses .NET "regular expressions" which have some pretty gnarly extensions and are definitely not regular languages).

The regex itself is generated from a relatively simple DFA based on mod 7 arithmetic on digits using a program (JFLAP apparently, not familiar).

Just from looking at the start of the regex you can see some cool things. For instance, TIL that all numbers of the form 1555....55554 and 85555....5554 are multiples of 7. Fun exercise to prove it.



I'm the guy who wrote the original implementation that the question mentions. I have no clue who 'Charles' who asked the question is, or how he found my toy implementation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: