diff --git a/problems/fibonacisequence/description.md b/problems/fibonacisequence/description.md new file mode 100644 index 0000000..7d9ab2c --- /dev/null +++ b/problems/fibonacisequence/description.md @@ -0,0 +1,40 @@ +## Fibonacci Number + +Write a function called `fibonacci` that takes a non-negative integer `n` as input and returns the **n-th Fibonacci number**. + +The Fibonacci sequence is defined as: + +* `F(0) = 0` +* `F(1) = 1` +* `F(n) = F(n-1) + F(n-2)` for `n > 1` + +### Function Signature: + +```python +def fibonacci(n): + # return your solution +``` + +#### Requirements + +* The function should return the `n`-th number in the Fibonacci sequence. +* If `n` is less than `0`, print `"Incorrect input"`. +* Your function will be tested with: + + * Base cases (`n = 0` and `n = 1`) + * Small values of `n` + * Larger values of `n` (e.g., 9) + * Multiple test cases in sequence + +#### Example: + +```python +fibonacci(0) # returns 0 +fibonacci(1) # returns 1 +fibonacci(2) # returns 1 +fibonacci(3) # returns 2 +fibonacci(5) # returns 5 +fibonacci(9) # returns 34 +``` + +You can copy this into your problem’s solution description. \ No newline at end of file diff --git a/problems/fibonacisequence/manifest.json b/problems/fibonacisequence/manifest.json new file mode 100644 index 0000000..af6b31f --- /dev/null +++ b/problems/fibonacisequence/manifest.json @@ -0,0 +1,6 @@ +{ + "title": "Fibonacci Sequence", + "description": "Calculate the n-th Fibonacci number using a function. The Fibonacci sequence is defined as follows: F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1.", + "description_md": "problems/fibonacisequence/description.md", + "test_code": "problems/fibonacisequence/test.py" +} \ No newline at end of file diff --git a/problems/fibonacisequence/test.py b/problems/fibonacisequence/test.py new file mode 100644 index 0000000..64e2eac --- /dev/null +++ b/problems/fibonacisequence/test.py @@ -0,0 +1,52 @@ +import unittest + +class TestSolution(unittest.TestCase): + def test_simple(self): + test_cases = [ + (0, 0), # Base case: n = 0 + (1, 1), # Base case: n = 1 + (2, 1), # Fibonacci(2) = 1 + (3, 2), # Fibonacci(3) = 2 + (5, 5), # Fibonacci(5) = 5 + (9, 34), # Fibonacci(9) = 34 + ] + + print("\n=== Function Output Test Results ===") + for input_val, expected in test_cases: + try: + actual = fibonacci(input_val) # pyright: ignore[reportUndefinedVariable] + status = "✓ PASS" if actual == expected else "✗ FAIL" + print(f"{status} | Input: {input_val} -> Got: {actual} | Expected: {expected}") + self.assertEqual(actual, expected) + except Exception as e: + print(f"✗ ERROR | Input: {input_val} -> Exception: {e}") + raise + +if __name__ == "__main__": + unittest.main(verbosity=2) + +""" +def fibonacci(n): + a = 0 + b = 1 + + # Check if n is less than 0 + if n < 0: + print("Incorrect input") + + # Check if n is equal to 0 + elif n == 0: + return 0 + + # Check if n is equal to 1 + elif n == 1: + return b + else: + for i in range(1, n): + c = a + b + a = b + b = c + return b + +print(fibonacci(9)) +""" \ No newline at end of file diff --git a/templates/problem.html b/templates/problem.html index c30a6dc..80aea3a 100644 --- a/templates/problem.html +++ b/templates/problem.html @@ -3,28 +3,270 @@
-