Last active
December 20, 2015 22:58
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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