2011-04-15 120 views
1

正在尋找想法開始我將稱爲單詞obscurifier單詞列表生成器。從單詞生成單詞列表

它需要一個字符串,例如, 「你好」,基本上看起來產生類似的話還可能出來的,即好像回到了一句:

  • h3ll0
  • he11o
  • HEL10
  • h3LLo
  • ...
  • ...

正如你所看到的,我需要對瓶蓋敏感。

我只是看着想法/我可以啓動它的方式。

也許第一遍做蓋子的東西:

  • 你好
  • 你好
  • 你好
  • 你好
  • 你好
  • ...

,然後喂那個lis t /數組到方法子數字/符號

我有信心並很可能會使用C#(至少啓動)此應用程序。

如果已經寫入了可用的文件,那麼我所說的那種事情就更好了,我很樂意聽到它。

感謝您的閱讀。

回答

2

這過長是一個評論,但它不是一個真正的答案。只是一個建議。首先,考慮此鏈接:

http://ericlippert.com/2010/06/28/computing-a-cartesian-product-with-linq/

你可以把你的問題,因爲計算序列的序列的笛卡爾積。考慮字母數字字符時,它們具有1到3個狀態,例如小寫的原始字符(如果適用),大寫字母(如果適用)和數字替換(再次適用)。或者,如果您是以數字,數字和大寫和小寫字母替換開頭的話。如:

A -> a, A, 4 
B -> b, B, 8 
C -> c, C 
D -> d, D 
// etc. 
1 -> 1, L, l 
2 -> 2 
3 -> 3, e, E 
// etc. 

每一個都是一個序列。因此,在你的問題中,你可能會將原始輸入「hello」轉換成一個過程,在這個過程中,你可以獲取與字符串中每個字符對應的序列,然後獲取這些序列並獲得它們的笛卡爾積。 Eric Lippert的鏈接博客中的方法將成爲繼續從這裏開始的一個很好的指導。

+0

謝謝你,偉大的答案/評論 - 不幸我不能投票了ATM – tanxiong 2011-04-15 04:32:50

+0

@tanxiong:如果這是足以讓你開始,你可以接受的答案。 – 2011-04-15 04:40:22

0

開始用

Dictionary: 
    key: letter  
    value: List of alternate choices for that letter 

create a new empty word 
for each letter in the word, 
    randomly choose an alternate choice and add it to the new word. 
1

此示例把安東尼Pegram的想法轉換成代碼。我對你的字母映射和輸入進行了硬編碼,但你可以很容易地改變它。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace SO5672236 
{ 
    static class Program 
    { 
     static void Main() 
     { 
      // Setup your letter mappings first 
      Dictionary<char,string[]> substitutions = new Dictionary<char, string[]> 
      { 
       {'h', new[] {"h", "H"}}, 
       {'e', new[] {"e", "E", "3"}}, 
       {'l', new[] {"l", "L", "1"}}, 
       {'o', new[] {"o", "O"}} 
      }; 

      // Take your input 
      const string input = "hello"; 

      // Get mapping for each letter in your input 
      IEnumerable<string[]> letters = input.Select(c => substitutions[c]); 

      // Calculate cortesian product 
      var cartesianProduct = letters.CartesianProduct(); 

      // Concatenate letters 
      var result = cartesianProduct.Select(x => x.Aggregate(new StringBuilder(), (a, s) => a.Append(s), b => b.ToString())); 

      // Print out results 
      result.Foreach(Console.WriteLine); 
     } 

     // This function is taken from 
     // http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx 
     static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) 
     { 
      IEnumerable<IEnumerable<T>> emptyProduct = new[] { Enumerable.Empty<T>() }; 
      return sequences.Aggregate(
       emptyProduct, 
       (accumulator, sequence) => 
       from accseq in accumulator 
       from item in sequence 
       select accseq.Concat(new[] { item })); 
     } 

     // This is a "standard" Foreach helper for enumerables 
     public static void Foreach<T>(this IEnumerable<T> enumerable, Action<T> action) 
     { 
      foreach (T value in enumerable) 
      { 
       action(value); 
      } 
     } 
    } 
}