Generating all combinations of 6 Xs with 3 Qs in Haskell -


i trying generate list of strings consist of 6 xs , 3 qs.

a subset of list trying generate follows:

["xxxxxxqqq", "xqxxqxxqx", "qxqxqxxxx",... 

what way go this?

here dynamic programming solution using data.array. mem stores memoized values.

import data.array  strings :: int -> int -> [string] strings n m = strings' n m       mem :: array (int,int) [string]     mem = array ((0,0),(n,m)) [ ((i,j), strings' j) | <- [0..n], j <- [0..m] ]      strings' 0 m = [replicate m 'x']     strings' n 0 = [replicate n 'q']     strings' n m = (('q':) <$> mem ! (n-1,m)) ++ (('x':) <$> mem ! (n,m-1)) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -