
p_27 = -(2 * a - 1) * (a ^ 2 - a + 41) where n = 1000 m = head $ filter (\x -> x ^ 2 - x + 41 > n) [1 ..] a = m - 1
This is the “official” Haskell solution to Euler Problem 27.
This solution is incomprehensible. The following hints are as far as I can get.
Prerequisite Considerations:
bmust be a prime number, sincex^2 + a*x + bmust be a prime number whenn=0.a = m - 1is a choice of the prime numberb(inx^2 + a*x + b) just(?) smaller than 1000.
When a == 32,
(\x -> x^2 - x + 41) 31 == 971
Why not the prime number 997?
— Me@2015.06.14 08:53 AM
.
It is because 997 is not a prime number generated by the formula x^2 - x + 41.
— Me@2015-06-30 11:07:53 AM
.
The code
l = map (\x -> x^2 - x + 41) [0..40]
is for generating 41 primes with the greatest Euler’s lucky number 41.
— Me@2015.06.14 08:34 AM

λ> :set +s λ> p_27 [-59231,-61,971] (0.00 secs, 113,624 bytes) λ>
— Me@2025-03-24 01:20:37 PM
.
.
2015.07.01 Wednesday (c) All rights reserved by ACHK
You must be logged in to post a comment.