diff --git a/README.md b/README.md index 513c313..d76d93a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ## Encrypted message CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQMQVBkPERkECQAWDVwXX1BGEwgJBAwCBFRVHQRGUlFBShwaDVZTGBUFVUdBShsVA1tZBwNGUlFB ShoVB1wXX1BGFAQOSklOQR5HGh5AVRY= -## Extra +## Extra Level * Requested problems after level 5 clear ### dodge-the-laser @@ -68,5 +68,9 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM * Reference * [Maximum Matching in General Graph](https://www.secmem.org/blog/2020/04/18/Blossom/) -### extra/prepare-the-bunnies-escape +### prepare-the-bunnies-escape * Completed in: 3 hrs, 17 mins, 20 secs. + +### find-the-access-codes +* Completed in: 1 hr, 6 mins, 52 secs. + diff --git a/extra/find-the-access-codes/solution.py b/extra/find-the-access-codes/solution.py index 3bcc114..cbdb8d3 100644 --- a/extra/find-the-access-codes/solution.py +++ b/extra/find-the-access-codes/solution.py @@ -1,30 +1,15 @@ def solution(l): - edges = {n : {'count': 1, 'multiple': set(), 'divisor': set()} for n in set(l)} + nodes = {i: [] for i in range(len(l))} for i in range(len(l)): - x = l[i] - if edges[x]['count'] > 1: - continue for j in range(i+1, len(l)): - y = l[j] - if x == y: - edges[x]['count'] += 1 - elif x > y and x % y == 0: - edges[x]['divisor'].add(y) - edges[y]['multiple'].add(x) - elif y > x and y % x == 0: - edges[x]['multiple'].add(y) - edges[y]['divisor'].add(x) + x, y = l[i], l[j] + if y % x == 0: + nodes[i] += [j] result = 0 - for x in edges: - # 1. (d, x, m) - result += len(edges[x]['divisor']) * len(edges[x]['multiple']) - # 2. (d, x, x) (x, x, m) - if edges[x]['count'] >= 2: - result += len(edges[x]['divisor']) + len(edges[x]['multiple']) - # 3. (x, x, x) - if edges[x]['count'] >= 3: - result += 1 + for i in nodes: + for j in nodes[i]: + result += len(nodes[j]) return result @@ -32,9 +17,7 @@ tests = [ ([1, 1, 1], 1), ([1, 2, 3, 4, 5, 6], 3), ([2, 3, 4], 0), - ([1, 1, 2, 3, 4, 5, 6], 8), - ([3 for i in range(2000)], 1), - ([i for i in range(1, 2000)], 40777), + ([1, 1, 2, 3, 4, 5, 6], 11), ] for i, o in tests: