3 ms·
Just because I can't resist writing little math things in Haskell: primes = 2 : filter isPrime [3..] isPrime n = let divisors = takeWhile (\d ->
by piinbinary 7y ago
Just because I can't resist writing little math things in Haskell:
primes = 2 : filter isPrime [3..]
isPrime n =
let divisors = takeWhile (\d -> d * d <= n) primes
in not $ any (\d -> n `mod` d == 0) divisors
strongPrimes =
let primeTriples = zip3 primes (drop 1 primes) (drop 2 primes)
in [b | (a, b, c) <- primeTriples, b*2 > a + c]
- kdmccormick 7y agoProof that you can write something elegant in Haskell and use comprehensible variable names.
- moomin 7y agoI like the zip3, I should have thought of that. I think I prefer the mapMaybe, but then I avoid list comprehensions.