I want to parse a string for all possible character level n-gram combinations, e.g. if the string is 'ab' and n is 2, then the function should return 'aa', 'ab', 'ba' and 'bb'. While I can hard code two nested for loops to generate bi-grams (like above) I rather let n be dynamic so I can easily generate uni - penta grams on the fly.
I'm not sure how to generate dynamic nested for loops in Lua, or for that matter if recursion is a better approach. Can someone give me some advice on the best way to do this?
Thanks!