I am working on a programme that creates jumbled up groups of letters, for this, I am creating 2 weighted letter generators, one for consonants, one for vowels.
Currently I have a weighted number generator using hashes for the weighting, and I can call the letter picking function with the number of letters I want it to return (eg. pick_vowel(3))
def pick_vowel(x)
vowels = { A: 15, E: 21, I: 13, O: 13, U: 5 }
v_choice = []
vowels.map {|letter, number| number.times {v_choice << letter}}
x.times {print v_choice.shuffle!.pop}
end
The idea is then to pass the resulting string to a functions which gives all possible combinations of a certain length, using the code below:
def solver(vowel)
puts (2..9).flat_map{|size| board.combination(size).map(&:join)}
end
but when I pass the string I get the following error message (in this case x = 6):
in `block in solver': undefined method `combination' for 6:Integer (NoMethodError)
I want to convert the output string to an array, but as far as I can tell there is an integer which appears in the output string, so the array method won't apply to it.
How do I prevent my output from containing an integer at the end?
Aucun commentaire:
Enregistrer un commentaire