Skip to content

Instantly share code, notes, and snippets.

@thquinn
Created August 1, 2023 07:55
Show Gist options
  • Save thquinn/f488d24d94d90a84f3d048dc827cb837 to your computer and use it in GitHub Desktop.
Save thquinn/f488d24d94d90a84f3d048dc827cb837 to your computer and use it in GitHub Desktop.
In the limit Hilbert curve, what percentage of order 1 Hilbert curves that appear in it are "right side up"?
using System;
// In the limit Hilbert curve, what percentage of order 1 Hilbert curves that appear in it are "right side up"?
namespace HilbertCalc {
class Program {
static void Main(string[] args) {
ulong[] curves = new ulong[] { 1, 0, 0, 0 }; // index 0 is "right side up," each subsequent index is 90 degrees counterclockwise
for (int i = 1; i <= 20; i++) {
Console.WriteLine($"Order {i} Hilbert curve:");
ulong sum = curves[0] + curves[1] + curves[2] + curves[3];
Console.WriteLine($"{curves[0]}/{sum} right side up");
Console.WriteLine($"{curves[1]}/{sum} CCW");
Console.WriteLine($"{curves[3]}/{sum} CW");
Console.WriteLine($"{curves[2]}/{sum} upside down");
// Each iteration of the curve contains:
// two right-side-up copies of the previous iteration
// one copy rotated clockwise
// one copy rotated counterclockwise
curves = new ulong[] {
curves[3] + 2 * curves[0] + curves[1],
curves[0] + 2 * curves[1] + curves[2],
curves[1] + 2 * curves[2] + curves[3],
curves[2] + 2 * curves[3] + curves[0],
};
}
Console.ReadLine();
}
// It seems that the answer for all orientations is 25%. It's kind of like a modular "blur" convolution: each bucket ends up
// iteratively bleeding into adjacent buckets, around and around in a circle, until all buckets are pretty much equally full.
// In the limit, I imagine that all buckets ARE equally full.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment