This commit is contained in:
Maxime Vorwerk
2023-07-19 19:37:50 +02:00
parent c5bf09836f
commit 6657154f41
4 changed files with 107 additions and 168 deletions

56
.cs
View File

@@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
public class Shape {
private int _x;
private int _y;
private int _z;
private SortedDictionary<(int, int, int), int>[] _data;
public bool this[int x, int y, int z] {;
get {
if (x < _x && y < _y && z < _z && x >= 0 && y >= 0 && z >= 0) {
return _data[(x, y, z)];
}
else
throw new IndexOutOfRangeException();
}
}
private Shape(int x, int y, int z) {
_x = x;
_y = y;
_z = z;
_data = new SortedDictionary<(int, int, int), int>[24];
for (int i = 0; i < 24; i++) {
int rot = i%3;
int corner = (i/3)%8;
bool apos = corner%2;
bool bpos = (corner/2)%2;
bool cpos = (corner/4)%2;
Func<Tuple<int, int, int>, Tuple<int, int, int>, int> comparer = (Tuple<int, int, int> A, Tuple<int, int, int> B) => {
int[] d = new int[3];
d[0] = (apos ? 1 : -1)*(B.Item1 - A.Item1);
d[1] = (bpos ? 1 : -1)*(B.Item2 - A.Item2);
d[2] = (cpos ? 1 : -1)*(B.Item3 - A.Item3);
return d[(2+rot)%3] != 0 ? d[(2+rot)%3] : (d[(1+rot)%3] != 0 ? d[(1+rot)%3] : d[rot]);
};
_data[i] = new SortedDictionary<Tuple<int, int, int>, int>(comparer);
}
}
public Shape Grow(int x, int y, int z) {
Tuple<int, int, int> newP = new Tuple<int, int, int>(x, y, z);
if (this._data[0].ContainsKey(newP) throw new InvalidOperationException();
else if (this._data[0].ContainsKey(new Tuple<int, int, int>(x+1, y, z)))
else throw new InvalidOperationException();
}
public static Shape GetCube() {
Shape S = new Shape(1, 1, 1);
S._data[0] = 1;
return S;
}
}

View File

@@ -1,12 +0,0 @@
using System.Collections;
using System.IO.Hashing;
public class AssembledObject {
private static XxHash32 _hash = new XxHash32();
private BitArray _shape;
public override int GetHashCode() {
return 1;
}
}

View File

@@ -1,15 +1,24 @@
namespace CubeShapeCounting { namespace CubeShapeCounting {
internal class Program { internal class Program {
private int _numBlocks = 0; private int _numBlocks = 0;
//private Dictionary<>(); private Dictionary<Shape.ImmutableOrientedShape, int>[] _knownShapes;
public Program(int numBlocks) { public Program(int numBlocks) {
this._numBlocks = numBlocks; _numBlocks = numBlocks;
_knownShapes = new Dictionary<Shape.ImmutableOrientedShape, int>[numBlocks - 1];
for (int i = 0; i < _numBlocks - 1; i++)
_knownShapes[i] = new Dictionary<Shape.ImmutableOrientedShape, int>();
} }
public void Start() { public void Start() {
Stack<Shape> shapes = new Stack<Shape>();
shapes.Push(Shape.GetCube());
while (shapes.Count > 0) {
Shape shape = shapes.Pop();
List<(int, int, int)> next_spaces = shape.GetGrowableSpaces();
} }
}
static void Main(string[] args) { static void Main(string[] args) {
if (args.Length != 1) { if (args.Length != 1) {
@@ -19,8 +28,7 @@
int numBlocks; int numBlocks;
try { try {
numBlocks = Int32.Parse(args[0]); numBlocks = Int32.Parse(args[0]);
} } catch {
catch {
Console.WriteLine("Cannot parse" + args[0] + "as an Int32."); Console.WriteLine("Cannot parse" + args[0] + "as an Int32.");
return; return;
} }

View File

@@ -1,10 +1,9 @@
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.IO.Hashing; using System.IO.Hashing;
using System.Security.Cryptography;
public class Shape { public class Shape {
private int _size;
private (int, int, int) _minp; private (int, int, int) _minp;
private (int, int, int) _maxp; private (int, int, int) _maxp;
private (int, int, int)[] _newest; private (int, int, int)[] _newest;
@@ -13,8 +12,7 @@ public class Shape {
get { get {
if (x <= _maxp.Item1 && y <= _maxp.Item2 && z <= _maxp.Item3 && x >= _minp.Item1 && y >= _minp.Item2 && z >= _minp.Item3) { if (x <= _maxp.Item1 && y <= _maxp.Item2 && z <= _maxp.Item3 && x >= _minp.Item1 && y >= _minp.Item2 && z >= _minp.Item3) {
return _data[0].ContainsKey((x, y, z)); return _data[0].ContainsKey((x, y, z));
} } else
else
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
} }
} }
@@ -24,11 +22,12 @@ public class Shape {
_maxp = maxp; _maxp = maxp;
_newest = newest; _newest = newest;
_data = D; _data = D;
_size = D[0].Count;
} }
public List<(int, int, int)> GetGrowableSpaces() { public List<(int, int, int)> GetGrowableSpaces() {
List<(int, int, int)> L = new List<(int, int, int)>(); List<(int, int, int)> L = new List<(int, int, int)>();
foreach ((int x, int y, int z) in _data[0].Keys) { foreach ((int x, int y, int z) in _newest) {
if (!_data[0].ContainsKey((x + 1, y, z)) && !L.Contains((x + 1, y, z))) if (!_data[0].ContainsKey((x + 1, y, z)) && !L.Contains((x + 1, y, z)))
L.Add((x + 1, y, z)); L.Add((x + 1, y, z));
if (!_data[0].ContainsKey((x - 1, y, z)) && !L.Contains((x - 1, y, z))) if (!_data[0].ContainsKey((x - 1, y, z)) && !L.Contains((x - 1, y, z)))
@@ -60,17 +59,17 @@ public class Shape {
} }
SortedDictionary<(int, int, int), int>[] newD = new SortedDictionary<(int, int, int), int>[24]; SortedDictionary<(int, int, int), int>[] newD = new SortedDictionary<(int, int, int), int>[24];
for (int i = 0; i < 24; i++) { for (int i = 0; i < 24; i++) {
int rot = i%3; int rot = i % 3;
int corner = (i/3)%8; int corner = (i / 3) % 8;
bool apos = corner%2 != 0; bool apos = corner % 2 != 0;
bool bpos = (corner/2)%2 != 0; bool bpos = (corner / 2) % 2 != 0;
bool cpos = (corner/4)%2 != 0; bool cpos = (corner / 4) % 2 != 0;
Comparison<(int, int, int)> comparer = ((int, int, int) A, (int, int, int) B) => { Comparison<(int, int, int)> comparer = ((int, int, int) A, (int, int, int) B) => {
int[] d = new int[3]; int[] d = new int[3];
d[0] = (apos ? 1 : -1)*(B.Item1 - A.Item1); d[0] = (apos ? 1 : -1) * (B.Item1 - A.Item1);
d[1] = (bpos ? 1 : -1)*(B.Item2 - A.Item2); d[1] = (bpos ? 1 : -1) * (B.Item2 - A.Item2);
d[2] = (cpos ? 1 : -1)*(B.Item3 - A.Item3); d[2] = (cpos ? 1 : -1) * (B.Item3 - A.Item3);
return d[(2+rot)%3] != 0 ? d[(2+rot)%3] : (d[(1+rot)%3] != 0 ? d[(1+rot)%3] : d[rot]); return d[(2 + rot) % 3] != 0 ? d[(2 + rot) % 3] : (d[(1 + rot) % 3] != 0 ? d[(1 + rot) % 3] : d[rot]);
}; };
newD[i] = new SortedDictionary<(int, int, int), int>(D, Comparer<(int, int, int)>.Create(comparer)); newD[i] = new SortedDictionary<(int, int, int), int>(D, Comparer<(int, int, int)>.Create(comparer));
} }
@@ -137,6 +136,6 @@ public class Shape {
newD[i] = new SortedDictionary<(int, int, int), int>(); newD[i] = new SortedDictionary<(int, int, int), int>();
newD[i].Add((0, 0, 0), 0); newD[i].Add((0, 0, 0), 0);
} }
return new Shape((1, 1, 1), (1, 1, 1), new (int, int, int)[] {(0, 0, 0)}, newD); return new Shape((0, 0, 0), (0, 0, 0), new (int, int, int)[] { (0, 0, 0) }, newD);
} }
} }