-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-2.linq
38 lines (35 loc) · 957 Bytes
/
6-2.linq
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
<Query Kind="Program" />
void Main()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Util.CurrentQueryPath));
string inputLine = File.ReadAllLines("6.txt").First();
LinkedList<int> nodes = new LinkedList<int>();
foreach (var n in inputLine.Split('\t'))
{
nodes.AddLast(int.Parse(n));
}
HashSet<string> seen = new HashSet<string>();
int count = 0;
while (true)
{
count++;
int max = nodes.Max();
var currentNode = nodes.Find(max);
currentNode.Value = 0;
for (int i = max; i > 0; i--)
{
currentNode = currentNode.Next();
currentNode.Value = currentNode.Value + 1;
}
string result = string.Join(" ", nodes.Select(n => n.ToString()));
if (seen.Contains(result))
{
count.Dump();
return;
}
else
{
seen.Add(result);
}
}
}