forked from matsci/python-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq1.py
More file actions
49 lines (31 loc) · 909 Bytes
/
q1.py
File metadata and controls
49 lines (31 loc) · 909 Bytes
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
# ONLY EDIT FUNCTIONS MARKED CLEARLY FOR EDITING
import numpy as np
# modify this function, and create other functions below as you wish
def question01(portfolios):
portfolios.sort(reverse=True)
print portfolios
binaryIndexList = []
x = 0
for item in portfolios:
binaryNumber = bin(item)[2:]
x += 1
binaryIndexList.append([int(binaryNumber), inverseBinary(binaryNumber)])
if binaryIndexList[0][1] == 0:
binaryIndexList.remove(binaryIndexList[0])
#test for perfect matches for longest lengths
longestLengths = len(str(binaryIndexList[0][0]))
for binaryNumber in binaryIndexList:
if len(str(binaryIndexList))
print binaryIndexList
answer = 0
return answer
def inverseBinary(num):
result = ""
for binaryNumber in list(num):
if binaryNumber == "0":
result += "1"
elif binaryNumber == "1":
result += "0"
return int(result)
#test
print question01([15, 8, 6, 7])