zajebis
This commit is contained in:
40
src/problems/fibonacisequence/description.md
Normal file
40
src/problems/fibonacisequence/description.md
Normal file
@@ -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.
|
||||
7
src/problems/fibonacisequence/manifest.json
Normal file
7
src/problems/fibonacisequence/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"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",
|
||||
"difficulty": "medium",
|
||||
"test_code": "problems/fibonacisequence/test.py"
|
||||
}
|
||||
52
src/problems/fibonacisequence/test.py
Normal file
52
src/problems/fibonacisequence/test.py
Normal file
@@ -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))
|
||||
"""
|
||||
29
src/problems/reversedstring/description.md
Normal file
29
src/problems/reversedstring/description.md
Normal file
@@ -0,0 +1,29 @@
|
||||
## Reversed String
|
||||
|
||||
Write a function called ```revstring``` that takes a string as input and returns the reversed string.
|
||||
|
||||
### Function Signature:
|
||||
```python
|
||||
def revstring(x).
|
||||
# return your solution
|
||||
```
|
||||
|
||||
#### Requirements
|
||||
- The function should return the input string reversed
|
||||
- Your function will be tested with various cases, including:
|
||||
- An empty string
|
||||
- A single character
|
||||
- A palindrome ("racecar")
|
||||
- A string of numbers ("12345")
|
||||
- Special characters
|
||||
- A normal string ( "Hello World" )
|
||||
|
||||
#### Example:
|
||||
```python
|
||||
revstring("Hello World") # returns "dlroW olleH"
|
||||
revstring("") # returns ""
|
||||
revstring("racecar") # returns "racecar"
|
||||
revstring("12345") # returns "54321"
|
||||
revstring("!@# $%") # returns "%$ #@!"
|
||||
```
|
||||
You can copy this into your problems solution
|
||||
7
src/problems/reversedstring/manifest.json
Normal file
7
src/problems/reversedstring/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"title":"Reversed String",
|
||||
"description":"Reverse a String using a Function ; Try to write as little code as possible",
|
||||
"description_md":"problems/reversedstring/description.md",
|
||||
"difficulty":"easy",
|
||||
"test_code":"problems/reversedstring/test.py"
|
||||
}
|
||||
26
src/problems/reversedstring/test.py
Normal file
26
src/problems/reversedstring/test.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import unittest
|
||||
|
||||
class TestSolution(unittest.TestCase):
|
||||
def test_simple(self):
|
||||
test_cases = [
|
||||
("Hello World", "dlroW olleH"),
|
||||
("", ""),
|
||||
("a", "a"),
|
||||
("racecar", "racecar"),
|
||||
("12345", "54321"),
|
||||
("!@# $%", "%$ #@!")
|
||||
]
|
||||
|
||||
print("\n=== Function Output Test Results ===")
|
||||
for input_val, expected in test_cases:
|
||||
try:
|
||||
actual = revstring(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)
|
||||
1
src/problems/sortlist/description.md
Normal file
1
src/problems/sortlist/description.md
Normal file
@@ -0,0 +1 @@
|
||||
this is a easy sorting problem **it is solvable in less than 2 seconds**
|
||||
7
src/problems/sortlist/manifets.json
Normal file
7
src/problems/sortlist/manifets.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Sort List",
|
||||
"description": "Sort a List with a Function (sortlist); the function is supposed to take the list as an argument and is supposed to return the sorted list and print it.",
|
||||
"description_md": "problems/sortlist/description.md",
|
||||
"difficulty": "easy",
|
||||
"test_code": "problems/sortlist/test.py"
|
||||
}
|
||||
17
src/problems/sortlist/test.py
Normal file
17
src/problems/sortlist/test.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import unittest
|
||||
|
||||
# This is the function the user is expected to write.
|
||||
# Its a really simple one, the user can choose not to type tho.
|
||||
|
||||
#def sortlist(lst = [4,3,2,1]) -> list:
|
||||
#return sorted(lst)
|
||||
|
||||
class TestSolution(unittest.TestCase):
|
||||
def test_sort(self):
|
||||
# define x as a empty array.
|
||||
# this will be used for the functiun ; a empty var does not work.
|
||||
self.x = []
|
||||
self.assertEqual(sortlist(self.x), sorted(self.x)) # pyright: ignore[reportUndefinedVariable]
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user