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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more 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 void Init(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(Column from, 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(Column from, Column to, Column temp, int num)
{
int C = 1;
if (num == 1)
{
move1(from, to);
}
else
{
C += move(from, temp, to, num - 1);
move1(from, to);
C += move(temp, to, from, num - 1);
}
return C;
}
private static int Main()
{
int NUM = 17;
Column[] cols = new Column[3];
cols[0].Init(NUM, NUM);
cols[1].Init(NUM, 0);
cols[2].Init(NUM, 0);
return 100;
}
}
}
|