So I have to implement a function avalanche :: [Integer]
that returns a sorted, infinite list of the hamming sequence in Haskell.
I'm still very new to Haskell and have tried multiple things with the iterate function, like:
avalanche = sort ((iterate (\x -> 3 ^ x) 1) ++ (iterate (\x -> 5 ^ x) 1) ++ (iterate (\x -> 7 ^ x) 1))
Which doesn't work, cause it only returns the numbers for (i = j = k) > 0.
How can I write a function which uses different permutations and starts at 0?
Some expected sample-output:
ghci> take 10 avalanche
[1,3,5,7,9,15,21,25,27,35]
EDIT:
I'm unable to find an algorithm that predicts the right in-/decrementation of i, j, and k, as they seem to grow and shrink in no concise pattern.
// n i j k
// 01 3^0 * 5^0 * 7^0 0 0 0
// 03 3^1 * 5^0 * 7^0 1 0 0
// 05 3^0 * 5^1 * 7^0 0 1 0
// 07 3^0 * 5^0 * 7^1 0 0 1
// 09 3^2 * 5^0 * 7^0 2 0 0
// 15 3^1 * 5^1 * 7^0 1 1 0
// 21 3^1 * 5^0 * 7^1 1 0 1
// 25 3^0 * 5^2 * 7^0 0 2 0
// 27 3^3 * 5^0 * 7^0 3 0 0
// 35 3^0 * 5^1 * 7^1 0 1 1
// 45 3^0 * 5^1 * 7^1 0 1 1
// 49 3^0 * 5^0 * 7^2 0 0 2