TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Prime Number Regex

5 pointsby Cieplakover 6 years ago
I was messing around representing integers using binary trees, and noticed that a certain tree format makes it trivial to grep for prime numbers. Probably not very novel, but thought y&#x27;all might enjoy it. Here&#x27;s one through sixteen:<p><pre><code> * (()()) * ((()())()) * (((()())())()) (((()())())(()())) * ((((()())())())()) ((((()())())())(()())) * ((((()())())(()()))()) ((((()())())(()()))(()())) ((((()())())(()()))((()())())) ((((()())())(()()))(((()())())())) * (((((()())())())())()) (((((()())())())())(()())) * (((((()())())())(()()))()) (((((()())())())(()()))(()())) (((((()())())())(()()))((()())())) (((((()())())())(()()))(((()())())())) </code></pre> I added asterisks in front of the primes. Here&#x27;s the set of 16-bit ints:<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;cieplak&#x2F;213fb4c88581d8971b274b7ec64787b1" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;cieplak&#x2F;213fb4c88581d8971b274b7ec647...</a><p>The regex just checks if the string ends with &#x27;())&#x27;:<p><pre><code> cat integers.txt | grep &#x27;())$&#x27; | nl | tail -1</code></pre>

no comments

no comments