math/fibonacci.py
The Nth Fibonacci number (0-indexed: F(0)=0, F(1)=1). Pure computation, no network.
Use when the user asks for a Fibonacci number by index.
- the file
- math/fibonacci.py
- its skill
- math/SKILL.md (the whole math pack)
- as knowledge
- okf/math/fibonacci.md
- on GitHub
- math/fibonacci.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/math/fibonacci.py && chmod +x fibonacci.py && ./fibonacci.py --fraglet-help
3. Run it.
./fibonacci.py -p n="<n>"
Parameters
| name | type | requirement | description |
|---|---|---|---|
| n | string | required | 0-indexed position of the Fibonacci number to compute |
Outputs
stdout
Provenance
- image
- ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
- reach
network=none— a run is a pure function of its inputs; results are safe to memoize.- procedure_hash
- sha256:fda98b6e5ff83936164a74f8463b970034e0b838406ee0e41027d72abcbc3de3
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
fibonacci.py · 15 lines · sha256 fda98b6e5ff8…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=The Nth Fibonacci number (0-indexed: F(0)=0, F(1)=1). Pure computation, no network.
#: when=Use when the user asks for a Fibonacci number by index.
#: network=none
#: stdin=none
#: param=n:required:d=0-indexed position of the Fibonacci number to compute
import os
n = int(os.environ["N"])
if n < 0:
raise SystemExit("n must be non-negative")
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
print(f"Value: {a}")