How on Earth does ^.?$|^(..+?)\1+$ produce primes?
531K views · Oct 31, 2024 · Entertainment
Comments · 2.3K
@standupmaths · 1 year ago · pinned
Take your personal data back with Incogni! Use code standupmaths at the link below and get 60% off an annual plan: <a href="https://incogni.com/standupmaths">https://incogni.com/standupmaths</a><br><br>Don’t use code ^.?$|^(..+?)\1+$.
527
@Graphene_314 · 1 year ago
The plural of regex is regrets.
4.6K
@Yogarine · 1 year ago (edited)
Regular expressions are already scary by nature. Making one that produces primes is truly terrifying.
3.8K
@Cmanorange · 1 year ago
wow, what a neat trick! i'm adding this to my production code immediately, good luck new hires!
4.1K
@scottieapplseed · 1 year ago
I loved the home joke at the end; you're such a good localhost.
284
@RMDragon3 · 1 year ago (edited)
To simplify, this takes the number and expresses it as a unary numeral system, where the number of marks is the value of the number you put in (e.g. 1 is 1, 2 is 11, 3 is 111, ...). The regex then looks to divide the unary representation into exactly N groups of size M, where both N and M are natural numbers with value 2 or larger. For example, you can divide 4 (represented as 1111) into 2 groups of "11". You can divide 6 (represented 111111) into 2 groups of "111" or 3 groups of "11". However, you can't divide 3 (represented as 111) into groups of the same size (technically you can do 3 groups of "1", but then M isn't 2 or larger). Basically, you are checking if the number has any factors bigger than 1, which obviously is only false for prime numbers.
318
@tempest_dawn · 1 year ago
love that the halloween horror episode on a math channel is . . . code
1.6K
@busyfreeguy · 1 year ago
15+ years of programming experience including using regular expressions and I still watched and enjoyed this video. It's a testament to Matt's enthusiasm and his skill as a speaker/teacher.
891
@mckseal · 1 year ago
Regex is already halloween worthy.
1.1K
@tostadojen · 1 year ago
<b>Matt:</b> "What the factor?"<br><b>Primes:</b> "Your factors can't help you here."
56
@linguica · 1 year ago
I love regular expressions. I taught myself to use them in college and then as an intern doing data entry I was able to complete a full day's "work" in like 30 minutes.
12
@Rohanology27 · 1 year ago (edited)
What in the ^.?$|^(..+?)\1+$ did I just watch?<br><br>Edit: Added
764
Up next

Beware the Runge Spikes!
Stand-up Maths · 560K views

How lucky is too lucky?: The Minecraft Speedrunning Dream Controversy Explained
Stand-up Maths · 8.2M views

The Immortal Kangaroo Sequence - Numberphile
Numberphile · 355K views

Calculating pi from coin flips (without randomness)
Stand-up Maths · 387K views

The rest of the world does names differently.
RobWords · 1.1M views

'Experimenting with Primes' - Dr Holly Krieger
Millennium Mathematics Project - maths.org · 348K views

The Professor Who Taught People How To Think (1962)
ABC Science and ABC Australia · 2.9M views

MUST WATCH: Obama Gives Deep Take On AI Threat, Recursive Self-Improvement, & His Suggested Approach
Forbes Breaking News · 720K views

Exploring the mysteries of the Prime (gaps!) Line.
Stand-up Maths · 670K views

The Bingo Paradox: 3× more likely to win
Stand-up Maths · 952K views

So You Want to Understand Quantum Mechanics…
PBS Space Time · 1.8M views

The Most Controversial Idea In Math
Veritasium · 14M views

How (and why) to take a logarithm of an image
3Blue1Brown · 2.2M views

Mathematicians finally find the infinite card game.
Stand-up Maths · 444K views

Why π^π^π^π could be an integer (for all we know!).
Stand-up Maths · 4M views

The Hidden Structure of Rule 30
Eric Rowland · 252K views

Why was this visual proof missed for 400 years? (Fermat's two square theorem)
Mathologer · 990K views

The last IMO problem AI could not solve
3Blue1Brown and PolyaMath · 2.6M views

Anthropic Took On the Riemann Hypothesis. Here’s What Actually Happened
Ellie Sleightholm · 481K views

What happens if you just keep squaring?
Veritasium · 10M views

Why it’s mathematically impossible to share fair
Stand-up Maths · 2.1M views

The hardest "What comes next?" (Euler's pentagonal formula)
Mathologer · 842K views

How Roman numerals broke the official dog database.
Stand-up Maths · 874K views

The biggest hand calculation in a century! [Pi Day 2024]
Stand-up Maths · 547K views

I designed a silly but semi-functional computer.
Stand-up Maths · 328K views

Has a Millennium Prize Problem been solved by AI?
Stand-up Maths · 1.1M views