Topics /

Math & Algorithms

The most popular blog posts about math & algorithms on Hacker News. 2,851 posts.

Any year
2133

A Perl Regular Expression That Matches Prime Numbers

Take a look at this Perl regular expression: perl -lne '(1x$_) =~ /^(11+?)\1+$/ && print "$_ is composite"' This regular expression matches only the composite numbers (and doesn't match prime numbers). Can you figure out how it works? I'll give the explanation below but try to figure it…

2134

Understanding Convolutions in Probability

In this post we take a look a how the mathematical idea of a convolution is used in probability. In probability a convolution is a way to add two random variables. Using a slightly ridiculous, mad-science, example we walk through multiple way to compute a convolution and ultimate arrive at the formu

2142

Parser Combinators Beat Regexes

Someone online was solving Advent of Code problems, and had a question about last years’ day 3 . They had a working solution using regular expressions (regexes) on String values, but they wanted to use ByteString values instead for performance reasons. They were surprised, however, that there seems to be a lack of…

2156

The Shape of Inequalities

…symmetry isn’t just a preference for “pretty” shapes. Contents Introduction The HM-GM-AM-QM Inequality The two circles The Semicircle The Container The 3D container The Sum of Squares Inequality Nesbitt’s Inequality Conclusion Introduction While I was randomly browsing the web, I came across this nice picture: Roland…

2157

Bounty to Recover NIST's Elliptic Curve Seeds

This is a fun challenge: The NIST elliptic curves that power much of modern cryptography were generated in the late ’90s by hashing seeds provided by the NSA. How were the seeds generated? Rumor has it that they are in turn hashes of English sentences, but the person who picked them, Dr. Jerry Solinas, passed away in…

2158

Hacking physics from the back of a napkin (2020)

February 24, 2020. The computational power of a humble napkin is awesome. I discuss three napkin algorithms — dimensional analysis, Fermi estimates, and random walks — and use them to figure out why rain falls, the length of the E. coli genome, and the mass of a proton, among other things. These examples suggest a…