Skip to content

Instantly share code, notes, and snippets.

@jpiccari
Last active December 20, 2015 22:58
Show Gist options
  • Save jpiccari/6208562 to your computer and use it in GitHub Desktop.
Save jpiccari/6208562 to your computer and use it in GitHub Desktop.
Weekend puzzle. Recursively generates all possible vowel combinations in the word metadata. The main function, dfs(), is basically a DFS but instead of exploring unexplored adjacent nodes we explore all nodes in 'set' while watching our current tree depth to figure out when we have enough vowels to generate a new result. (310 bytes; 190 bytes mi…
var result = [];
(function dfs(set, len, stack) {
if(len === 0)
return result.push(Array.prototype.map.call('metadata', function(x, i) {
return i%2 ? stack[i>>1] : x;
}).join(''));
for(var i = 0; i < set.length; dfs(set, len-1, (stack || []).concat(set[i++])));
}(['a', 'e', 'i', 'o', 'u', 'y'], 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment