spark: fibonacci verifier artifact with validation output
This commit is contained in:
1 parent
5cbe4447a8
commit
c470766858
2 files changed
+44
-21
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#!/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())
|
||||
@@ -1,21 +1,7 @@
|
||||
First 20 Fibonacci numbers:
|
||||
1: 0
|
||||
2: 1
|
||||
3: 1
|
||||
4: 2
|
||||
5: 3
|
||||
6: 5
|
||||
7: 8
|
||||
8: 13
|
||||
9: 21
|
||||
10: 34
|
||||
11: 55
|
||||
12: 89
|
||||
13: 144
|
||||
14: 233
|
||||
15: 377
|
||||
16: 610
|
||||
17: 987
|
||||
18: 1597
|
||||
19: 2584
|
||||
20: 4181
|
||||
Fibonacci Verification Report
|
||||
========================================
|
||||
Sequence (first 15 terms):
|
||||
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
|
||||
Last computed: F(14) = 377
|
||||
Validation: PASSED
|
||||
Exit code would be: 0
|
||||
Reference in new issue
Block a user