-
-
Save 4ft35t/814b5ba8bba6cf1a2fc3dc14db818cb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum(a): 10656 | |
sum(b): 10656 | |
a = 1776 , len(b) = 83, sum(b) = 10656 | |
588 | |
504 | |
280 | |
224 | |
180 | |
a = 2667 , len(b) = 78, sum(b) = 8880 | |
364 | |
336 | |
280 | |
252 | |
224 | |
224 | |
196 | |
196 | |
140 | |
140 | |
120 | |
115 | |
40 | |
40 | |
a = 6213 , len(b) = 64, sum(b) = 6213 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
28 | |
40 | |
40 | |
40 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
56 | |
84 | |
84 | |
84 | |
84 | |
84 | |
84 | |
84 | |
84 | |
84 | |
112 | |
112 | |
112 | |
112 | |
112 | |
120 | |
140 | |
168 | |
345 | |
2492 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
a = [17.76,62.13,26.67] #62.13,17.76,] | |
b = [24.92,5.88,5.04,3.64,3.45,3.36,2.8,2.8,2.52,2.24,2.24,2.24,1.96,1.96,1.8,1.68,1.4,1.4,1.4,1.2,1.2,1.15,1.12,1.12,1.12,1.12,1.12,0.84,0.84,0.84,0.84,0.84,0.84,0.84,0.84,0.84,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.56,0.4,0.4,0.4,0.4,0.4,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28,0.28] | |
a = [round(i*100) for i in a] | |
b = [round(i*100) for i in b] | |
a.sort() | |
b.sort() | |
print("sum(a):", sum(a)) | |
print("sum(b):", sum(b)) | |
def main(a): | |
for aa in a: | |
print(f"a = { aa } , len(b) = { len(b) }, sum(b) = { sum(b) }") | |
# print(b) | |
findAinB(aa, 0) | |
@lru_cache(maxsize=10240) | |
def findAinB(a1, ib): | |
# print(a1, ib) | |
if ib >= len(b): | |
return False | |
if a1 == sum(b[ib:]): | |
for i in b[ib:]: | |
print('\t', i) | |
b.remove(i) | |
return True | |
b1 = b[ib] | |
if a1 < b1: | |
return False | |
elif a1 == b1: | |
print('\t', b1) | |
b.pop(ib) | |
return True | |
if findAinB(a1, ib+1): | |
return True | |
elif findAinB(a1-b1, ib+1): | |
print('\t', b1) | |
b.pop(ib) | |
return True | |
return False | |
main(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment