I'm still a haskell newbie, so please excuse my bad code style.
I need all kind of combinations of letters in a box written into a file. In fact I need all this lines for doing a brute force attack on an old enigma puzzle. A line consists of a combination of 26 letters and 10 digits. It is given in the puzzle, that the first 6 characters were letters.
Now this is my code:
import Data.List (delete)
letters = ['A'..'Z']
allChars = letters ++ ['0'..'9']
boxContents :: [Char] -> [Char] -> [[Char]]
boxContents l lp = [a:b:c:d:e:f:delete f(delete e(delete d(delete c (delete b (delete a lp))))) |
a <- l,
b <- delete a l,
c <- delete b (delete a l),
d <- delete c (delete b (delete a l)),
e <- delete d (delete c (delete b (delete a l))),
f <- delete e (delete d (delete c (delete b (delete a l))))
]
main :: IO()
main = writeFile "c:\\bc.txt" $ unlines $ boxContents letters allChars
It eats up my 16 GB ram and than consumes 100 GB pagefile until it dies. I'm sure I can write I simple program in plain old C that uses less than 64 kB RAM to produce this file. But that's not the point: The point is how to make this work in Haskell? Where's my mistake?