Today I’ve red about brute-force implementation in Ruby and decided to make up another one. The only thing i’m not quite sure of is whether it’s possible to make an in-place conversion of Here it comes.
alphabet = [('a'..'z').to_a, ('A'..'Z').to_a, ('0'..'9').to_a].flatten
def r (str, depth, alphabet, &block)
depth == 0 ? yield(str) : (0..(alphabet.length-1)).each {|i| r(str + alphabet[i], depth-1, alphabet, &block) }
end
r("", 5, alphabet) { |str| print str + "\n"}