-
-
Save trichoplax/bc5dcc53c6bdd111a3a51c294fc86df9 to your computer and use it in GitHub Desktop.
Test for python entry to https://codegolf.codidact.com/posts/287131
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
def r(i): | |
y,z=65537,1+(1<<32);s=257*y*z;n=(i|(i&252*s)*y>>10|(i&254*s)*z>>17|(i&127*s)*z>>15|(i&63*s)*y>>6)&(1<<64)-1 | |
return 64-n.bit_count() | |
test_case_string = """0 : 18446744073709551615 : 64 | |
18446744073709551615 : 0 : 0 | |
12273903644374837845 : 6172840429334713770 : 0 | |
9819010546270478865 : 8627733527439072750 : 16 | |
9223372036854775808 : 9223372036854775807 : 61 | |
144115188075855872 : 18302628885633695743 : 60 | |
4 : 18446744073709551611 : 59 | |
16384 : 18446744073709535231 : 59 | |
9007199254740992 : 18437736874454810623 : 57 | |
35184372088832 : 18446708889337462783 : 55 | |
8796361457664 : 18446735277348093951 : 48 | |
17609903308800 : 18446726463806242815 : 36 | |
18441077155848519679 : 5666917861031936 : 1 | |
18440988645153550335 : 5755428556001280 : 2 | |
9214294468855857151 : 9232449604853694464 : 1 | |
18300371588261871615 : 146372485447680000 : 1 | |
18446744073708891899 : 659716 : 1 | |
18446744071024132079 : 2685419536 : 1 | |
8637754208117850111 : 9808989865591701504 : 1 | |
12643820184012849151 : 5802923889696702464 : 1 | |
35184372089472 : 18446708889337462143 : 47""" | |
test_cases = [ | |
line.split(" : ") | |
for line in test_case_string.split("\n") | |
] | |
results = [ | |
(int(test_case[0]), int(test_case[2]), r(int(test_case[0]))) | |
for test_case in test_cases | |
] | |
labelled_results = [ | |
(*result, "MISMATCH" if result[1] != result[2] else "") | |
for result in results | |
] | |
result_strings = [ | |
f"Input: {item[0]:20} Expected: {item[1]:2} Actual: {item[2]:2} {item[3]}" | |
for item in labelled_results | |
] | |
print("\n".join(result_strings)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment