-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
236 lines (212 loc) · 8.55 KB
/
functions.py
File metadata and controls
236 lines (212 loc) · 8.55 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 6 09:41:47 2018
@author: joe
"""
import pandas as pd
import numpy as np
class divider_object:
def __init__(self, array):
self.array = array
self.history = []
def divide(self):
divided = False
for a in range(len(self.array)):
if divided:
break
for b in range(len(self.array) - 1):
b += 1
if (not a == b) and (not divided):
if self.array[a] % self.array[b] == 0:
answer = int(self.array[a] / self.array[b])
self.history.append('{} / {} = {}'.format(self.array[a],
self.array[b], answer))
self.array[a] = answer
self.array.remove(self.array[b])
divided = True
elif self.array[b] % self.array[a] == 0:
answer = int(self.array[b] / self.array[a])
self.history.append('{} / {} = {}'.format(self.array[b],
self.array[a], answer))
self.array[a] = answer
self.array.remove(self.array[b])
divided = True
def adder(array, history, df, target):
l = len(array)
temparr = []
arr_of_dfs = []
arr_of_dfs.append(df)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temphist.append('{} + {} = {}'.format(array[a], array[b], array[a] + array[b]))
if array[a] + array[b] == target:
print(temphist)
temparr = array.copy()
temparr[a] += temparr[b]
temparr.remove(temparr[b])
tempdf = pd.DataFrame({'Numbers': [temparr], 'History': [temphist]})
arr_of_dfs.append(tempdf)
return pd.concat(arr_of_dfs)
def adder_arr(numbers, history, numarr, histarr, target):
l = len(numbers)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temphist.append('{} + {} = {}'.format(numbers[a], numbers[b], numbers[a] + numbers[b]))
if numbers[a] + numbers[b] == target:
print(temphist)
temparr = numbers.copy()
temparr[a] += temparr[b]
temparr.remove(temparr[b])
numarr.append(temparr.copy())
histarr.append(temphist.copy())
return numarr, histarr
def multiplier_arr(numbers, history, numarr, histarr, target):
l = len(numbers)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temphist.append('{} * {} = {}'.format(numbers[a], numbers[b], numbers[a] * numbers[b]))
if numbers[a] * numbers[b] == target:
print(temphist)
temparr = numbers.copy()
temparr[a] *= temparr[b]
temparr.remove(temparr[b])
numarr.append(temparr.copy())
histarr.append(temphist.copy())
return numarr, histarr
def minus_arr(numbers, history, numarr, histarr, target):
numbers.sort(reverse = True)
l = len(numbers)
for a in range(l):
for b in np.arange(a + 1, l):
if numbers[a] > numbers[b]:
temphist = history.copy()
temphist.append('{} - {} = {}'.format(numbers[a], numbers[b], numbers[a] - numbers[b]))
if numbers[a] - numbers[b] == target:
print(temphist)
temparr = numbers.copy()
temparr[a] -= temparr[b]
temparr.remove(temparr[b])
numarr.append(temparr.copy())
histarr.append(temphist.copy())
return numarr, histarr
def divider_arr(numbers, history, numarr, histarr, target):
numbers.sort(reverse = True)
l = len(numbers)
for a in range(l):
for b in np.arange(a + 1, l):
if numbers[a] % numbers[b] == 0:
temphist = history.copy()
temphist.append('{} / {} = {}'.format(numbers[a], numbers[b], numbers[a] / numbers[b]))
if numbers[a] / numbers[b] == target:
print(temphist)
temparr = numbers.copy()
temparr[a] /= temparr[b]
temparr.remove(temparr[b])
numarr.append(temparr.copy())
histarr.append(temphist.copy())
return numarr, histarr
def multiplier(array, history, df, target):
l = len(array)
temparr = []
arr_of_dfs = []
arr_of_dfs.append(df)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temphist.append('{} * {} = {}'.format(array[a], array[b], array[a] * array[b]))
if array[a] * array[b] == target:
print(temphist)
temparr = array.copy()
temparr[a] *= temparr[b]
temparr.remove(temparr[b])
tempdf = pd.DataFrame({'Numbers': [temparr], 'History': [temphist]})
arr_of_dfs.append(tempdf)
return pd.concat(arr_of_dfs)
def multiplier2(array, history, df, target):
l = len(array)
for a in range(l):
for b in np.arange(a + 1, l):
answer = array[a] * array[b]
temphist = history.copy()
temphist.append('{} * {} = {}'.format(array[a], array[b], answer))
if answer == target:
print(temphist)
temparr = np.copy(array)
temparr[a] *= temparr[b]
np.delete(temparr, b)
df = df.append({'Numbers': temparr, 'History': temphist}, ignore_index = True)
return df
def minus(array, history, df, target):
array.sort(reverse = True)
l = len(array)
temparr = []
arr_of_dfs = []
arr_of_dfs.append(df)
for a in range(l):
for b in np.arange(a + 1, l):
if array[a] > array[b]:
temphist = history.copy()
temphist.append('{} - {} = {}'.format(array[a], array[b], array[a] - array[b]))
if array[a] - array[b] == target:
print(temphist)
temparr = array.copy()
temparr[a] -= temparr[b]
temparr.remove(temparr[b])
tempdf = pd.DataFrame({'Numbers': [temparr], 'History': [temphist]})
arr_of_dfs.append(tempdf)
return pd.concat(arr_of_dfs)
def minus2(array, history, df, target):
array.sort(reverse = True)
l = len(array)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temparr = np.copy(array)
if array[a] > array[b]:
answer = array[a] - array[b]
temphist.append('{} - {} = {}'.format(array[a], array[b], answer))
if answer == target:
print(temphist)
temparr[a] -= temparr[b]
np.delete(temparr, b)
df = df.append({'Numbers': temparr, 'History': temphist}, ignore_index = True)
return df
def division(array, history, df, target):
array.sort(reverse = True)
l = len(array)
temparr = []
arr_of_dfs = []
arr_of_dfs.append(df)
for a in range(l):
for b in np.arange(a + 1, l):
if array[a] % array[b] == 0:
temphist = history.copy()
temphist.append('{} / {} = {}'.format(array[a], array[b], array[a] / array[b]))
if array[a] / array[b] == target:
print(temphist)
temparr = array.copy()
temparr[a] /= temparr[b]
temparr.remove(temparr[b])
tempdf = pd.DataFrame({'Numbers': [temparr], 'History': [temphist]})
arr_of_dfs.append(tempdf)
return pd.concat(arr_of_dfs)
def division2(array, history, df, target):
array = np.flipud(np.sort(array))
l = len(array)
for a in range(l):
for b in np.arange(a + 1, l):
temphist = history.copy()
temparr = np.copy(array)
if array[a] % array[b] == 0:
answer = array[a] / array[b]
temphist.append('{} / {} = {}'.format(array[a], array[b], answer))
if answer == target:
print(temphist)
temparr[a] /= temparr[b]
np.delete(temparr, b)
df = df.append({'Numbers': temparr, 'History': temphist}, ignore_index = True)
return df