finish extra/queue-to-do

Submitting solution...
Submission: SUCCESSFUL. Completed in: 9 hrs, 13 mins, 42 secs.
This commit is contained in:
Seongbeom Park 2022-05-05 18:45:57 +09:00
parent e47a5cd2e4
commit 10050edd2a
2 changed files with 20 additions and 2 deletions

View File

@ -76,3 +76,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM
### fuel-injection-perfection ### fuel-injection-perfection
* Completed in: 1 hr, 2 secs. * Completed in: 1 hr, 2 secs.
### queue-to-do
* Completed in: 9 hrs, 13 mins, 42 secs.

View File

@ -2,8 +2,23 @@ def solution(start, length):
checksum = 0 checksum = 0
for i in range(length): for i in range(length):
base = start + length * i base = start + length * i
for j in range(length - i): checksum ^= calc_checksum_range(base, base + length - i)
checksum ^= base + j 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 return checksum
tests = [ tests = [