4 ms·
The same sensibilities apply in Haskell. These sort of longer, more structured problems are exactly when do notation comes out do a <- [1 .. 29] b <
by tel 7y ago
The same sensibilities apply in Haskell. These sort of longer, more structured problems are exactly when do notation comes out
do a <- [1 .. 29]
b <- [a+1 .. 29]
guard $ gcd a b == 1
c <- [b+1 .. 29]
guard $ gcd a c == 1
guard $ gcd b c == 1
let z = a ** 3 + b ** 3 + c ** 3
let d = z ** (1/3) + 0.5
guard $ z == d ** 3
return (a, b, c)
Translation of this into HOFs is straightforward (the method guard uses helps tremendously), but it's not worth it most of the time. In Python where HOFs are so restricted it would be even worse.