-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TIL on prime numbers and regular expressions
A small entertaining part I picked up on Youtube
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |