From c732563555c1101477bdc379bf1e3ef7fac74a90 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Sun, 18 Jan 2026 13:04:45 -0600 Subject: [PATCH 1/2] Add Zeckendorf Testing --- .glotter.yml | 46 +++++++++++++++++++++++++++++ archive/p/python/zeckendorf.py | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 archive/p/python/zeckendorf.py diff --git a/.glotter.yml b/.glotter.yml index b5f21b8a9..67b9a5155 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -1408,3 +1408,49 @@ projects: expected: "Usage: please enter the dimension of the matrix and the serialized matrix" transformations: - "strip" + zeckendorf: + words: + - "zeckendorf" + requires_parameters: true + tests: + zeckendorf_valid: + params: + - name: "zero" + input: '"0"' + expected: "" + - name: "small fibonacci value" + input: '"55"' + expected: "55" + - name: "small non-fibonacci value" + input: '"67"' + expected: "55, 8, 3, 1" + - name: "large fibonacci value" + input: '"10946"' + expected: "10946" + - name: "large non-fibonacci value" + input: '"16383"' + expected: "10946, 4181, 987, 233, 34, 2" + transformations: + - remove: + - "[" + - "]" + - "strip" + zeckendorf_invalid: + params: + - name: "no input" + input: null + expected: "Usage: please input a non-negative integer" + - name: "empty input" + input: '""' + expected: "Usage: please input a non-negative integer" + - name: "negative input" + input: '"-2"' + expected: "Usage: please input a non-negative integer" + - name: "floating point input" + input: '"2.6"' + expected: "Usage: please input a non-negative integer" + - name: "non-numeric input" + input: '"bad"' + expected: "Usage: please input a non-negative integer" + transformations: + - "strip" diff --git a/archive/p/python/zeckendorf.py b/archive/p/python/zeckendorf.py new file mode 100644 index 000000000..f45384120 --- /dev/null +++ b/archive/p/python/zeckendorf.py @@ -0,0 +1,53 @@ +import sys +from typing import NoReturn + +def usage() -> NoReturn: + print("Usage: please input a non-negative integer") + sys.exit(1) + + +def fibonacci_up_to(n: int) -> list[int]: + result: list[int] = [] + a = 1 + b = 2 + while a <= n: + result.append(a) + a, b = b, a + b + + return result + + +def zeckendorf(n: int) -> list[int]: + result: list[int] = [] + fibs = fibonacci_up_to(n) + idx = len(fibs) - 1 + while idx >= 0 and n > 0: + fib = fibs[idx] + if fib <= n: + n -= fib + result.append(fib) + idx -= 2 + else: + idx -= 1 + + return result + + +def main() -> int: + if len(sys.argv) < 2: + usage() + + try: + n = int(sys.argv[1]) + except ValueError: + usage() + + if n < 0: + usage() + + result = zeckendorf(n) + print(result) + + +if __name__ == "__main__": + main() From 60b405c9c6c56a36bb63533730478c14ebce9673 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Sun, 18 Jan 2026 13:08:49 -0600 Subject: [PATCH 2/2] Fix formatting --- archive/p/python/zeckendorf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archive/p/python/zeckendorf.py b/archive/p/python/zeckendorf.py index f45384120..158a17c9b 100644 --- a/archive/p/python/zeckendorf.py +++ b/archive/p/python/zeckendorf.py @@ -1,6 +1,7 @@ import sys from typing import NoReturn + def usage() -> NoReturn: print("Usage: please input a non-negative integer") sys.exit(1)