Zeckendorf in TypeScript

Published on 24 April 2026 (Updated: 24 April 2026)

Welcome to the Zeckendorf in TypeScript page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

const arg = process.argv[2];

if (process.argv.length !== 3 || !/^\d+$/.test(arg)) {
    console.log("Usage: please input a non-negative integer");
    process.exit(0);
}

let n = parseInt(arg, 10);

if (n === 0) {
    console.log("");
    process.exit(0);
}

let a = 1;
let b = 2;

while (b <= n) {
    [a, b] = [b, a + b];
}

const result: number[] = [];

while (n > 0 && a > 0) {
    if (a <= n) {
        result.push(a);
        n -= a;

        let prevA = b - a;
        let prevPrevA = a - prevA;
        [a, b] = [prevPrevA, prevA];
    } else {
        let prevA = b - a;
        [a, b] = [prevA, a];
    }
}

console.log(result.join(", "));

Zeckendorf in TypeScript was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.