Write a Rust function to compute the Fibonnaci sequence. Respond with only the code…
- User
Write a Rust function to compute the Fibonnaci sequence. Respond with only the code block and nothing else.
Assistant
fn fibonacci(n: u32) -> u32 { let mut a = 0; let mut b = 1; for _ in 0..n { let c = a + b; a = b; b = c; } a }- User
Rewrite the function recursively with memoization.
Assistant
fn fibonacci(n: u32) -> u32 { let mut memoized = Memo::new(fn(i) -> u32 { if i == 0 || i == n { return i; } else { return fibonacci(i - 1) + fibonacci(i - 2); } }); return memoized.get(n); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.