private IEnumerable <IEnumerable <T> > Analyze(UnorderChars chars, IEnumerable <T> currentInput, int skipCount) { if (chars.IsEmpty) { yield return(currentInput); yield break; } #if SHOW Console.WriteLine($"採用:{string.Join(" + ", currentInput.Select(x => this.getStringFunction(x)))}\t残り:{chars.ToString()}、単語数:{sortedWords.Skip(skipCount).Where(x => x.Chars.PrimaryChar == chars.PrimaryChar).Count()}"); #endif if (this.failsBorder.ContainsKey(chars) && this.failsBorder[chars] <= skipCount) { yield break; } int i = skipCount; int count = 0; while (i < this.sortedWords.Length && this.sortedWords[i].Chars.PrimaryChar != chars.PrimaryChar) { i++; } while (i < this.sortedWords.Length && this.sortedWords[i].Chars.PrimaryChar == chars.PrimaryChar) { var word = this.sortedWords[i++]; if (!chars.IsInclude(word.Chars)) { continue; } var found = chars.Subtract(word.Chars); var result = this.Analyze(found, currentInput.Concat(new[] { word.Body }), i); foreach (var r in result) { yield return(r); count++; } } if (count == 0) { if (this.failsBorder.ContainsKey(chars)) { this.failsBorder[chars] = skipCount; } else { this.failsBorder.Add(chars, skipCount); } } }
/// <summary> /// アナグラムとして指定した文章を作ることのできる単語の組み合わせを列挙する /// </summary> /// <param name="v"></param> /// <returns></returns> public IEnumerable <IEnumerable <T> > Analyze(string v) { if (string.IsNullOrEmpty(v)) { return(Enumerable.Empty <IEnumerable <T> >()); } //集計処理と並べ替え var target = new UnorderChars(v, this.ranker); return(this.Analyze(target, Enumerable.Empty <T>(), 0)); }
public WordNode(T2 body, UnorderChars chars) { Body = body; Chars = chars; }