koala-13b· UC Berkeley
Arena Human Preference 55K
Write me a recursive function in python with a test
- User
Write me a recursive function in python with a test
- Assistant
Here is a simple recursive function in Python:
codedef fibonacci(n): if n < 0: return fibonacci(-n) elif n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2)And here is a test for the function:
codefibonacci = [0, 1, 1, 2, 3, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2554, 3943, 6472, 9989, 14586, 20095, 26609, 33684, 42573, 53107, 64756, 77280, 89965, 103854, 119083, 135707, 153626, 173035, 193843, 217044, 232643, 250641, 269964, 289926, 311455, 334439, 358811, 384599, 411723, 440217, 469996, 500992, 533310, 567963, 597976, 631501, 666714, 694724, 725524, 758971, 794969, 832483, 862489, 894
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.