-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
81 lines (68 loc) · 2.2 KB
/
functions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import constants as const
#import colors
# Constants
# Get us some fancy colors
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
WHITE = '\033[37m'
END_COLOR = '\033[30m'
# Function declarations
# NOTE: All color altering functions are not used at the moment - they break the program
'''
# printErr(...) prints the given message to the screen in red
def printErr(msg):
print(RED + msg + END_COLOR)
# printGreen(...) prints the given message to the screen in green
def printGreen(msg):
print(GREEN + msg + END_COLOR)
# printYella(...) prints the given message to the screen in yellow
def printYella(msg):
print(YELLOW + msg + END_COLOR)
def output(str):
print(WHITE + str + END_COLOR)
output_file.write(str)
output_file.write("\n")
'''
# sortByCap_Res(...) (bubblesort) sorts the given list first on capacity then on resistance
def sortByCap_Res(list):
n = len(list)
swapped = True
while swapped:
swapped = False
for i in range(1, n):
# if the pair is out of order
if list[i-1].capacity > list[i].capacity:
# swap
tmp = list[i-1]
list[i-1] = list[i]
list[i] = tmp
swapped = True
elif list[i-1].capacity == list[i].capacity:
if list[i-1].resistance > list[i].resistance:
# swap
tmp = list[i-1]
list[i-1] = list[i]
list[i] = tmp
swapped = True
# sortByModule(...) (bubblesort) sorts the given list based on module number
def sortByModule(list):
n = len(list)
swapped = True
while swapped:
swapped = False
for i in range(1, n):
# if the pair is out of order
if list[i-1].module > list[i].module:
# swap
tmp = list[i-1]
list[i-1] = list[i]
list[i] = tmp
swapped = True
# getMaxModule(...) finds the largest module in the given list of batteries
def getMaxModule(list):
maxModule = const.DAMN_SMALL_NUMBER
for batt in list:
if batt.module > maxModule:
maxModule = batt.module
return maxModule