Reputation: 35
I want to make in Haskell a application that gives from a couple of characters all possibilities. That works with the permutation function. But now I want to add to the output of every word in the list a prefix and a suffix. Like:
Input:
combinations "prefix" "sufix" "randomletters"
Output (something like this)
["prefixrandomletters", "prefixrandomletters","prefixrandomletters","prefixrandomletters","suffixrandomletters","suffixrandomletters","suffixrandomletters","suffixrandomletters","suffixrandomletters",]
Background of the application: Like scrabble. First the prefix is like 2 letters that the word can start with. Then 2 letters that the word can end with. Then the letters you have in your hand.
Upvotes: 0
Views: 153
Reputation: 102106
You can map
a function that adds the prefix:
combinations pre suf letters = prefixed ++ suffixed
where
perms = permutations letters
prefixed = map (\x -> pre ++ x) $ perms
suffixed = ...
The way to solve this is to break the problem down, as you have started doing:
permutation
)\x -> pre ++ x
etc)map
) to create two lists of words++
)Upvotes: 1