using System; using System.Collections.Generic; namespace A354961 { class Program { static void Main(string[] args) { HashSet gen = new HashSet(); gen.Add(new Point(0, 0, 0)); int N = 1000; for (int n=0; n<=N; n++) { Console.WriteLine($"{n} {gen.Count}"); if (n newgen = new HashSet(); foreach (Point p in gen) { foreach (Point q in Neighbours(p)) { if (!visited.Contains(q)) { newgen.Add(q); } } } gen = newgen; } } } /// /// Neighbours of given point on the Manhattan cubic lattice. /// static IEnumerable Neighbours(Point p) { // don't test parity with "% 2"! if ((p.X & 1) == (p.Y & 1)) { yield return new Point(p.X, p.Y, p.Z + 1); } else { yield return new Point(p.X, p.Y, p.Z - 1); } if ((p.X & 1) == (p.Z & 1)) { yield return new Point(p.X, p.Y + 1, p.Z); } else { yield return new Point(p.X, p.Y - 1, p.Z); } if ((p.Y & 1) == (p.Z & 1)) { yield return new Point(p.X + 1, p.Y, p.Z); } else { yield return new Point(p.X - 1, p.Y, p.Z); } } private static readonly HashSet visited = new HashSet(); } /// /// 3D point (with integer coordinates). /// public struct Point { public Point(int x, int y, int z) { X = x; Y = y; Z = z; } public int X { get; private set; } public int Y { get; private set; } public int Z { get; private set; } public override bool Equals(object other) { Point otherPoint = (Point)other; return X == otherPoint.X && Y == otherPoint.Y && Z == otherPoint.Z; } public override int GetHashCode() { return unchecked(X + (Y<<10) + (Z<<20)); } } }