From 4035ed4e2f2a6b7e2af815834fce8a735e36afb7 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 29 Dec 2018 21:02:44 +0100 Subject: [PATCH] Add generator and call it --- Python/hilbertgenerator.py | 16 ++++++++++++++++ Python/test2.py | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100755 Python/test2.py diff --git a/Python/hilbertgenerator.py b/Python/hilbertgenerator.py index b29b76b..7cbb1e1 100644 --- a/Python/hilbertgenerator.py +++ b/Python/hilbertgenerator.py @@ -43,3 +43,19 @@ def hilbert(center, x, y): hilbert(center + x - y, x, y) hilbert(center + x + y, ~x, ~y) + +def hilbertgenerator(center, x, y): + if abs(x) < 1: + yield center + else: + x /= 2 + y /= 2 + for r in hilbertgenerator(center - x + y, -~x, -~y): + yield r + for r in hilbertgenerator(center - x - y, x, y): + yield r + for r in hilbertgenerator(center + x - y, x, y): + yield r + for r in hilbertgenerator(center + x + y, ~x, ~y): + yield r + diff --git a/Python/test2.py b/Python/test2.py new file mode 100755 index 0000000..6c893a9 --- /dev/null +++ b/Python/test2.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 +from hilbertgenerator import Vector, hilbertgenerator + +n = 8 +for r in hilbertgenerator(Vector(n, n), Vector(n, 0), Vector(0,n)): + print(r)