I am looking at some JAVA code and I would like to know how this can be translated into Haskell.
IntStream.range(0, cookedWords.length).parallel().forEach((int i) -> {
int A = cookedWords[i];
for (int j = i + 1; j < cookedWords.length; ++j) {
int B = cookedWords[j];
if ((A & B) != 0) continue;
int AB = A | B;
for (int k = j + 1; k < cookedWords.length; ++k) {
int C = cookedWords[k];
if ((AB & C) != 0) continue;
int ABC = AB | C;
for (int l = k + 1; l < cookedWords.length; ++l) {
int D = cookedWords[l];
if ((ABC & D) != 0) continue;
int ABCD = ABC | D;
for (int m = l + 1; m < cookedWords.length; ++m) {
int E = cookedWords[m];
if ((ABCD & E) != 0) continue;
System.out.printf("%s\n%s\n\n",
stopwatch.elapsedTime(),
decodeWords(A, B, C, D, E));
}
}
}
}
});
This code is taken from here
I am guessing that there are a few things that need to be done here. unboxed vectors
, run parallel
etc. but I don't even know how to start with the indexing the way it is done in the imperative code. Or is this where people start to tell me to stay away from Haskell?
What is a literal translation of this code? And is there a better 'Haskell' way of doing something like this?
This is all I can think of doing. But it is obviously inefficient.
[ (a,b,c,d,e)
| a <- cookedWords, b <- cookedWords, c <- cookedWords, d <- cookedWords, e <- cookedWords
, foldl1' (.|.) [a,b,c,d,e] == 0
]