Programming isn't about being able to write code, anyone can type on a keyboard as long as they have half a brain. Programming is all about problem solving and you seem to have come across a problem, and instead of facing it and trying all possible methods (which I highly doubt you did), all you did was ask for some code. Since I won't stand around and tell you about how you made a mistake, I'll give you a hint in solving this issue because giving you the code doesn't help anyone :
Read these :
Wikipedia - Permutations
Wikipedia - Combinations
then create a function that uses a formula instead of arrays and such and calculates the value. Counting chars would work too.
Hope this helps, in a way.