Skip to content

Commit

Permalink
Added TIL on prime numbers and regular expressions
Browse files Browse the repository at this point in the history
A small entertaining part I picked up on Youtube
  • Loading branch information
jonasbn committed Jan 7, 2025
1 parent 1f7957d commit 5e338ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@
### Regexp - regular expressions

- [Regex Posix](regexp/posix.md)
- [Prime Numbers](regexp/prime_numbers.md)

<a id="renovate"></a>
### Renovate - a bot for automating dependency updates
Expand Down
27 changes: 27 additions & 0 deletions regexp/prime_numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Prime Numbers

I fell over a video on YouTube demonstrating a regular expression that could check if a numbers was a prime.

The video is entitled: "How on Earth does ^.?$|^(..+?)\1+$ produce primes?", well it does not really produce primes it just checks them anyway, fascinating video.

This is the regex:

```regex
^.?$|^(..+?)\1+$
```

And it Perl form:

```regex
^ # beginning of line of line
.?
$ # end of line
| # or
^ # beginning of line of line
(..+?)\1+
$ # end of line
```

## Resources and References

- [YouTube: @standupmaths: "How on Earth does ^.?$|^(..+?)\1+$ produce primes?"](https://youtu.be/5vbk0TwkokM?si=_lNEsO8ZU21MJhG6)

0 comments on commit 5e338ba

Please sign in to comment.