Raising Stefan is his excellent answer. Given a^3 + b^3 == c^3 + d^3 , we only need to look at integers for which 0 < a < c < b . We introduce this (infinite) iterative structure
-- generates all integers x, y and z for which holds 0 < x < y < z triplets = [(x, y, z) | z <- [3 .. ], y <- [2 .. z - 1], x <- [1 .. y - 1]]
This will give us triplets that are easily accessible from our understanding of the list, which we will present here after. For people with a Python background, this should be equivalent to Python yield .
1 2 3 1 2 4 1 3 4 2 3 4 1 2 5 1 3 5 2 3 5 1 4 5 2 4 5 3 4 5 1 2 6 1 3 6 2 3 6 1 4 6 2 4 6 3 4 6 1 5 6 2 5 6 3 5 6 4 5 6
Next, we need something (quickly) to find the largest cube and check that the integers are a cube, also called an integer cube root. There is this package Math.NumberTheory.Powers.Cubes , which has functions for these tasks. Or just use these
Now your compact list comprehension for the first 50 taxi numbers looks like
*Main> condition = \abc -> and [isCube (a^3 + b^3 - c^3), a^3 + b^3 - c^3 > c^3] *Main> taxi = [(a, b, c, largestCube (a^3 + b^3 - c^3)) | (a, c, b) <- triplets, condition abc] *Main> first50 = take 50 taxi
Print them using
*Main> single_line = \(x, y, z, u) -> unwords [show i | i <- [x, y, z, u]] *Main> putStrLn $ unlines $ map single_line first50
Gives
1 12 9 10 2 16 9 15 2 24 18 20 10 27 19 24 4 32 18 30 2 34 15 33 9 34 16 33 3 36 27 30 17 39 26 36 12 40 31 33 6 48 27 45 4 48 36 40 12 51 38 43 8 53 29 50 20 54 38 48 17 55 24 54 9 58 22 57 3 60 22 59 5 60 45 50 8 64 36 60 30 67 51 58 4 68 30 66 18 68 32 66 42 69 56 61 6 72 54 60 17 76 38 73 5 76 48 69 34 78 52 72 10 80 45 75 15 80 54 71 24 80 62 66 30 81 57 72 51 82 64 75 7 84 63 70 2 89 41 86 11 93 30 92 23 94 63 84 12 96 54 90 50 96 59 93 8 96 72 80 20 97 33 96 47 97 66 90 35 98 59 92 24 98 63 89 29 99 60 92 6 102 45 99 27 102 48 99 23 102 60 95 24 102 76 86 1 103 64 94
Within a few seconds, he returns the first 50 taxi numbers.