using System; using System.Collections; using System.Collections.Generic; using System.Drawing; namespace A322050 { class Program { static void Main(string[] args) { List generation = new List(); generation.Add(new Point()); for (int n=2; n<65537; n++) { foreach (Point p in generation) { See(p); } List newGeneration = new List(); foreach (Point p in generation) { newGeneration.AddRange(Newcomers(p)); } generation = newGeneration; int total = 0; foreach (Point p in generation) { total += Weight(p); } Console.WriteLine("{0} {1}", n, total/8); } } static Point Normalize(Point p) { int x = Math.Abs(p.X); int y = Math.Abs(p.Y); if (x > y) { return new Point(x, y); } else { return new Point(y, x); } } static int Weight(Point p) { if (p.IsEmpty) { return 1; } else if (p.Y==0 || p.X==p.Y) { return 4; } else { return 8; } } static readonly Size[] KnightMoves = { new Size(+2, +1), new Size(+2, -1), new Size(-2, +1), new Size(-2, -1), new Size(+1, +2), new Size(-1, +2), new Size(+1, -2), new Size(-1, -2) }; static IEnumerable Neighbours(Point p) { foreach (Size knightMove in KnightMoves) { Point neighbour = Normalize(p + knightMove); yield return neighbour; } } static bool Accept(Point p) { bool ok = false; if (!Seen(p)) { foreach (Point neighbour in Neighbours(p)) { if (Seen(neighbour)) { if (ok) { ok = false; break; } else { ok = true; } } } } return ok; } static IEnumerable Newcomers(Point p) { Dictionary once = new Dictionary(); foreach (Point neighbour in Neighbours(p)) { if (Accept(neighbour)) { if (!once.ContainsKey(neighbour)) { once[neighbour] = true; yield return neighbour; } } } } static readonly List Visited = new List(); static bool Seen(Point p) { if (p.X < Visited.Count) { return Visited[p.X].Get(p.Y); } else { return false; } } static void See(Point p) { for (int x=Visited.Count; x<=p.X; x++) { Visited.Add(new BitArray(x+1)); } Visited[p.X].Set(p.Y, true); } } }