nowfound

Life & fun · August 23, 2018

PN

Prime Number Regex

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'all might enjoy it. Here's one through sixteen: * (()()) * ((()())()) * (((()())())()) (((()())())(()())) * ((((()())())())()) ((((()())())())(()())) * ((((()())())(()()))()) ((((()())())(()()))(()())) ((((()())())(()()))((()())())) ((((()())())(()()))(((()())())())) * (((((()())())())())()) (((((()())())())())(()())) * (((((()())())())(()()))()) (((((()())())())(()()))(()()))…

What it does

In the maker’s words, at launch

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'all might enjoy it. Here's one through sixteen: * (()()) * ((()())()) * (((()())())()) (((()())())(()())) * ((((()())())())()) ((((()())())())(()())) * ((((()())())(()()))()) ((((()())())(()()))(()())) ((((()())())(()()))((()())())) ((((()())())(()()))(((()())())())) * (((((()())())())())()) (((((()())())())())(()())) * (((((()())())())(()()))()) (((((()())())())(()()))(()())) (((((()())())())(()()))((()())())) (((((()())())())(()()))(((()())())())) I added asterisks in front of the primes. Here's the set of 16-bit ints: https://gist.github.com/cieplak/213fb4c88581d8971b274b7ec647... The regex just checks if the string ends with '())': cat integers.txt | grep '())$' | nl | tail -1

Does the same job

all alternatives →
  • IW
    I wrote a book on Python regular expressions2019 · ▲193

    My book titled "Python re(gex)?" is free to download through this weekend [1][2] The book covers both 're' and 'regex' modules, has plenty of examples and chapters also have cheatsheets and exercises. Code snippets, exercises, sample chapters, etc are available on GitHub repo [3] I used pandoc+xelatex [4] to generate the pdf. [1] https://gumroad.com/l/py_regex [2] https://leanpub.com/py_regex [3] https://github.com/learnbyexample/py_regular_expressions [4]…

  • IW
    I wrote a book on GNU grep and ripgrep2019 · ▲182

    My book on "GNU grep and ripgrep" is free to download today and tomorrow [1][2] Code snippets, example files and sample chapters are available on GitHub [3] The book uses plenty of examples and regular expressions are also covered from scratch. The book is suitable for beginners as well as serves as a reference. Hope you find it useful, I would be grateful for your feedback and suggestions. I used pandoc+xelatex [4] to generate the pdf. [1] https://gumroad.com/l/gnugrep_ripgrep [2] https://leanpub.com/gnugrep_ripgrep [3]…

  • GG
  • /^[a-z0-9_-]{3,16}$/2020 · ▲106

    A podcast about regular expressions

  • Regex library2022 · ▲276

    A curated list of most commonly used regular expressions

  • RegexLearn2021 · ▲336

    Learn RegEx step by step, from zero to advanced

More life & fun this month

the category →
  • TL

    Life & fun · 10d ago · louisabraham.github.io

  • Photosynthesis fires two of your iPhone

    Life & fun · 28d ago · photosynthesis.camera

  • SoloUno310

    Take control of hair pulling, nail biting & skin picking

    Life & fun · 28d ago · solouno.io

  • Scroll through all 43,252,003,274,489,856,000 reachable Rubik's Cube permutations.

    Life & fun · 26d ago · everycube.alen.is

  • The Interactive 3D Encyclopedia

    Life & fun · 21d ago · expeditione.fun

  • Hi HN, I built Eigendrum, a web tool that solves the 2D wave equation for arbitrary shapes so you can hear what they sound like as drums. How it works: * Solves -∇²u = λu using finite element analysis (Kφ = λMφ) on a triangle mesh. * Validated to <0.1% error against closed-form solutions for circles (Bessel zeros) and rectangles. * Sound model factors in strike location, Rayleigh damping, and mallet width. * Includes Kac drums I & II to demonstrate identical sound spectra from different geometries. * No frameworks, build steps, or dependencies. Repo and tests:…

    Life & fun · 26d ago · baselashraf81.github.io

Launched alongside, August 2018

the whole month →