Created
February 26, 2023 01:16
-
-
Save hachy/96759e61661859b678b2b012ade4fb43 to your computer and use it in GitHub Desktop.
ゲームのステータス cf. https://algo-method.com/tasks/1073
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
STATUS = 10 | |
DIGIT = 5 | |
def change_status(i, val, cur_val): | |
bit = (1 << (STATUS * DIGIT)) - 1 | |
idx = i * DIGIT | |
s = (1 << (idx + DIGIT)) - (1 << idx) | |
mask = bit ^ s | |
cur_val &= mask | |
cur_val |= 2**idx * val | |
return cur_val | |
def get_val(i, cur_val): | |
return (cur_val >> (DIGIT * i)) & ((1 << DIGIT) - 1) | |
cur = 0 | |
cur = change_status(4, 2, cur) | |
cur = change_status(1, 4, cur) | |
cur = change_status(10, 22, cur) | |
print(cur) | |
print(bin(cur)) | |
print(get_val(4, cur)) | |
print(get_val(1, cur)) | |
print(get_val(10, cur)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment