[Haskell-cafe] Combination-lock problem

ajb at spamcop.net ajb at spamcop.net
Wed Aug 11 00:24:17 EDT 2004


G'day all.

At 06:01 10/08/04 +0200, Florian Boehl wrote:

>If I know the length 'l' of the 'locklist', I can solve the
>problem via generators. E.g.:
>
>l = 2: [[a,b] | a <- [0..locklist!!0], b <- [0..locklist!!1]]
>
>But if the length is unknown (because it's dynamic) this solutions (of
>course) fails. Is it possible to solve this problem in haskell in an
>elegant way?

This is a transformation that it's useful to know about:

    [ E | x <- Xs, y <- Ys ] = concat [ [ E | y <- Ys ] | x <- Xs ]

Whether or not it's any use to you is another matter. :-)

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list