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
|
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace JitTest
{
internal struct Ring
{
public int size;
}
internal struct Column
{
public Ring[] rings;
private int[] _heightPtr;
public int height
{
get { return _heightPtr[0]; }
set { _heightPtr[0] = value; }
}
public Column(int maxHeight, int curHeight)
{
rings = new Ring[maxHeight];
for (int i = 0; i < curHeight; i++)
{
rings[i].size = maxHeight - i;
}
_heightPtr = new int[] { curHeight };
}
public void Validate()
{
for (int i = 1; i < _heightPtr[0]; i++)
{
if (rings[i - 1].size <= rings[i].size)
throw new Exception();
}
}
private static void move1(ref Column from, ref Column to)
{
to.rings[to.height] = from.rings[from.height - 1];
to.height = to.height + 1;
from.height = from.height - 1;
to.Validate();
from.Validate();
}
private static int move(ref Column from, ref Column to, ref Column temp, int num)
{
to.Validate();
from.Validate();
temp.Validate();
int C = 1;
if (num == 1)
{
move1(ref from, ref to);
}
else
{
C += move(ref from, ref temp, ref to, num - 1);
move1(ref from, ref to);
C += move(ref temp, ref to, ref from, num - 1);
}
return C;
}
private static int Main()
{
Column c1 = new Column(17, 17);
Column c2 = new Column(17, 0);
Column c3 = new Column(17, 0);
int ec = move(ref c1, ref c2, ref c3, 17) - 130971;
c1.Validate();
c2.Validate();
c3.Validate();
return ec;
}
}
}
|