37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Fib verifier - generates and validates Fibonacci sequence"""
|
|
|
|
def fib(n):
|
|
"""Return nth Fibonacci number (0-indexed)"""
|
|
a, b = 0, 1
|
|
for _ in range(n):
|
|
a, b = b, a + b
|
|
return a
|
|
|
|
def main():
|
|
results = []
|
|
for i in range(15):
|
|
n = fib(i)
|
|
results.append({"n": i, "fib": n})
|
|
|
|
# Verify against known values
|
|
known = {0: 0, 1: 1, 2: 1, 3: 2, 4: 3, 5: 5, 6: 8, 7: 13, 8: 21, 9: 34, 10: 55}
|
|
all_correct = all(r["fib"] == known.get(r["n"], fib(r["n"])) for r in results[:11])
|
|
|
|
output = f"""Fibonacci Verification Report
|
|
{'=' * 40}
|
|
Sequence (first 15 terms):
|
|
{', '.join(str(r['fib']) for r in results)}
|
|
Last computed: F(14) = {results[-1]['fib']}
|
|
Validation: {'PASSED' if all_correct else 'FAILED'}
|
|
Exit code would be: {0 if all_correct else 1}
|
|
"""
|
|
|
|
with open('/root/.hermes/wizard-outputs/spark/fibonacci_output.txt', 'w') as f:
|
|
f.write(output)
|
|
|
|
print(output)
|
|
return 0 if all_correct else 1
|
|
|
|
if __name__ == "__main__":
|
|
exit(main()) |