Find All Possible Permutations In Certain Range C# -


i want make program find valid stock symbols yahoo finance , found this: quickest way enumerate alphabet however, wan't go - z , aa - az , aba - abz , on , forth. best way this? more clear example: b c d ect. aa ab ac ad ect. aba abb abc abd ect.

using eric lippert's cartesian product,

var chars = "abcdefghijklmnopqrstuvwxyz"; int maxlen = 3;  var query = enumerable.range(1, maxlen)             .selectmany(i => enumerable.repeat(chars, i)                              .cartesianproduct()                              .select(x => string.concat(x)));   foreach(var str in query) {     console.writeline(str); } 

ps: completeness:

public static ienumerable<ienumerable<t>> cartesianproduct<t>(this ienumerable<ienumerable<t>> sequences) {     // base case:     ienumerable<ienumerable<t>> result = new[] { enumerable.empty<t>() };     foreach (var sequence in sequences)     {         var s = sequence; // don't close on loop variable                             // recursive case: use selectmany build new product out of old 1         result =             seq in result             item in s             select seq.concat(new[] { item });     }     return result; } 


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -