From e47a5cd2e4fff48a48c5ece4acae544804e8629e Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Thu, 5 May 2022 09:58:01 +0900 Subject: [PATCH 1/2] implement following the text Verifying solution... Test 1 passed! Test 2 passed! Test 3 passed! [Hidden] Test 4 passed! [Hidden] Test 5 failed [Hidden] Test 6 failed [Hidden] Test 7 passed! [Hidden] Test 8 passed! [Hidden] Test 9 failed [Hidden] Test 10 passed! [Hidden] --- extra/queue-to-do/solution.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 extra/queue-to-do/solution.py diff --git a/extra/queue-to-do/solution.py b/extra/queue-to-do/solution.py new file mode 100644 index 0000000..f11590e --- /dev/null +++ b/extra/queue-to-do/solution.py @@ -0,0 +1,16 @@ +def solution(start, length): + checksum = 0 + for i in range(length): + base = start + length * i + for j in range(length - i): + checksum ^= base + j + return checksum + +tests = [ + ([0, 3], 2), + ([17, 4], 14) + ] + +for i, o in tests: + result = solution(*i) + print (i, result == o, result, o) -- 2.47.2 From 10050edd2a1b2acedab6bf6d66cc754276e675e0 Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Thu, 5 May 2022 18:45:57 +0900 Subject: [PATCH 2/2] finish extra/queue-to-do Submitting solution... Submission: SUCCESSFUL. Completed in: 9 hrs, 13 mins, 42 secs. --- README.md | 3 +++ extra/queue-to-do/solution.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba6252b..ca0aec3 100644 --- a/README.md +++ b/README.md @@ -76,3 +76,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM ### fuel-injection-perfection * Completed in: 1 hr, 2 secs. + +### queue-to-do +* Completed in: 9 hrs, 13 mins, 42 secs. diff --git a/extra/queue-to-do/solution.py b/extra/queue-to-do/solution.py index f11590e..4bac795 100644 --- a/extra/queue-to-do/solution.py +++ b/extra/queue-to-do/solution.py @@ -2,8 +2,23 @@ def solution(start, length): checksum = 0 for i in range(length): base = start + length * i - for j in range(length - i): - checksum ^= base + j + checksum ^= calc_checksum_range(base, base + length - i) + return checksum + +# P = [01]* +# P^P = 0 +# P00^P01^P10^P11 = 0 +def calc_checksum_range(_from, _to): # _from included, _to is NOT included + checksum = 0 + remain = (-_from) % 4 + for i in range(_from, min(_from + remain, _to)): + checksum ^= i + checkpoint = _from + remain + + remain = _to % 4 + for i in range(max(_from, checkpoint, _to - remain), _to): + checksum ^= i + return checksum tests = [ -- 2.47.2