Compare commits
2 Commits
65c850800c
...
967bb947a4
Author | SHA1 | Date | |
---|---|---|---|
967bb947a4 | |||
1193897938 |
@ -187,6 +187,33 @@ def mirror(n: int) -> int;
|
|||||||
return res
|
return res
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Exercise 2.3
|
||||||
|
```python
|
||||||
|
def factorial(limit: n) -> int:
|
||||||
|
n = 0
|
||||||
|
if limit <= n:
|
||||||
|
return n
|
||||||
|
else:
|
||||||
|
f = 1
|
||||||
|
while f < limit:
|
||||||
|
n += 1
|
||||||
|
f *= n
|
||||||
|
if n % 2 == 0:
|
||||||
|
return (n-2)
|
||||||
|
else:
|
||||||
|
return (n-1)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exercise 2.4
|
||||||
|
```python
|
||||||
|
def prime(n: int) -> int:
|
||||||
|
"""
|
||||||
|
Check if n(int) is prime if n > 1, error otherwise
|
||||||
|
"""
|
||||||
|
if n <= 1:
|
||||||
|
raise Exception("prime: n<= 1")
|
||||||
|
elif n % 2 == 0:
|
||||||
|
return n == 2
|
||||||
## Exercise 3.3
|
## Exercise 3.3
|
||||||
```python
|
```python
|
||||||
def quotient(a: int, b: int) -> int:
|
def quotient(a: int, b: int) -> int:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user