-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindWords.linq
More file actions
94 lines (76 loc) · 2 KB
/
FindWords.linq
File metadata and controls
94 lines (76 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<Query Kind="Program" />
void Main()
{
var words = new List<string>();
printS("thisisawesome", words, new List<string>());
words.Dump();
}
bool isWord(string s) {
var dict = new string[] {"this", "is", "a", "we", "so", "me", "awe", "some", "awesome"};
return dict.Contains(s);
}
/*
void printSentences(String input, List<string> words) {
var characters = input.ToCharArray();
if (input == "") {
words.Dump();
return;
}
for (var i = 0; i < characters.Length; i++)
{
var s = input.Substring(i);
s.Dump();
if (isWord(s))
{
words.Add(s);
if (s.Length > i) {
printS(s.Substring(i), words);
}
}
}
}*/
void printS(String input, List<string> words, List<string> sentences, int lastFound = 0) {
char[] characters = input.ToCharArray();
words = words ?? new List<string>();
for (var i = 0; i <= characters.Length; i++)
{
// end of input string?
if (i == characters.Length) {
sentences.Add(string.Join(" ", words));
words = new List<string>();
sentences.Dump();
break;
}
// too long? shouldn't happen but seems to
if (lastFound + i > characters.Length) return;
var s = input.Substring(lastFound, i);
("Last Found = " + lastFound).Dump();
(s + " isWord = " + isWord(s)).Dump();
if (isWord(s))
{
lastFound = i;
words.Add(s);
printS(input.Substring(i), words, sentences);
}
}
var sentence = string.Join(" ", words);
if (!sentences.Contains(sentence)) {
"new sentence".Dump();
sentences.Add(sentence);
sentence.Dump();
}
//printS(input, words, sentences);
}
List<string> MakeBiggerWord(IEnumerable<string> words)
{
var results = new List<string>();
for (var i = 0; i < words.Count(); i++)
{
var tryMe = words.Skip(i).Take(words.Count() - i);
//if (MakeBiggerWord(tryMe).ToArray())
//{
// results.Add(string.Join(" ", tryMe));
//}
}
return null;
}