gpt-4o-mini-search-preview· OpenAI
LMArena Search Arena 24K
write me a fibonacci solver in AWK
- User
write me a fibonacci solver in AWK
- Assistant
Certainly! Here's an AWK script that calculates the nth Fibonacci number:
function fibonacci(n) { if (n <= 1) { return n } a = 0 b = 1 for (i = 2; i <= n; i++) { temp = a + b a = b b = temp } return b } BEGIN { n = 10 # Replace with the desired Fibonacci number index print "Fibonacci(" n ") =", fibonacci(n) }In this script:
- The
fibonaccifunction computes the nth Fibonacci number using an iterative approach. - The
BEGINblock sets the desired Fibonacci number index (n) and prints the result.
To use this script:
-
Save it to a file, e.g.,
fibonacci.awk. -
Run it with AWK:
awk -f fibonacci.awk
Replace
n = 10with the desired index to compute a different Fibonacci number. - The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.