-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexotic_mod.py
60 lines (42 loc) · 1.13 KB
/
exotic_mod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Jacobus Burger (2022)
# I thought about exotic ways of doing a simple evenness test in python
from random import randint as random
def index_even(n):
return ["Even", "Odd"][n % 2]
def recursive_even(n):
if n == 0:
return "Even"
if n == 1 or n == -1:
return "Odd"
return recursive_even(n - 2)
def iterative_even(n):
for i in range(0, n + 1, 2):
if i == n:
return "Even"
return "Odd"
def membership_even(n):
even_numbers = [i for i in range(0, n + 1, 2)]
if n in even_numbers:
return "Even"
return "Odd"
def curry_even(n):
# npm joke
def is_odd(n):
def is_even(n):
return n % 2 == 0
return is_even
return "Even" if is_odd(n)(n) == True else "Odd"
# precondition: user must know if n is even and specify ahead of time
def insist_even(n, is_even):
return is_even
def not_odd(n):
if n % 2 != 1:
return "Even"
return "Odd"
def probably_even(n):
if random(0, 1) == 0:
return "Even"
else:
return "Odd"
def guess_even(n):
return "Even" # This will be right 50% of the time!