1from secret import clue
2
3ZERO = 0
4LEFT_SHIFT_BITS = 5
5RIGHT_SHIFT_BITS = 5
6BW_AND_MASK = 16
7BW_OR_MASK = 247
8BW_OR_RESULT = 255
9FIFTH_BIT_POSITION = 4
10FOURTH_BIT_POSITION = 3
11
12def lucky():
13 address = ZERO
14
15 high_bits = clue(left_shift=LEFT_SHIFT_BITS) >> LEFT_SHIFT_BITS
16 address |= high_bits
17
18 low_bits = clue(right_shift=RIGHT_SHIFT_BITS) << RIGHT_SHIFT_BITS
19 address |= low_bits
20
21 fifth_bit = clue(bw_and=BW_AND_MASK)
22 address |= ((fifth_bit != ZERO) << FIFTH_BIT_POSITION)
23
24 fourth_bit = clue(bw_or=BW_OR_MASK)
25 address |= ((fourth_bit == BW_OR_RESULT) << FOURTH_BIT_POSITION)
26
27 return address
.
----------------------------------------------------------------------
Ran 1 test in 0.004s
OK
t | 1 | from secret import clue | t | 1 | from secret import clue |
2 | 2 | ||||
3 | ZERO = 0 | 3 | ZERO = 0 | ||
4 | LEFT_SHIFT_BITS = 5 | 4 | LEFT_SHIFT_BITS = 5 | ||
5 | RIGHT_SHIFT_BITS = 5 | 5 | RIGHT_SHIFT_BITS = 5 | ||
6 | BW_AND_MASK = 16 | 6 | BW_AND_MASK = 16 | ||
7 | BW_OR_MASK = 247 | 7 | BW_OR_MASK = 247 | ||
8 | BW_OR_RESULT = 255 | 8 | BW_OR_RESULT = 255 | ||
9 | FIFTH_BIT_POSITION = 4 | 9 | FIFTH_BIT_POSITION = 4 | ||
10 | FOURTH_BIT_POSITION = 3 | 10 | FOURTH_BIT_POSITION = 3 | ||
11 | 11 | ||||
12 | def lucky(): | 12 | def lucky(): | ||
13 | address = ZERO | 13 | address = ZERO | ||
14 | 14 | ||||
15 | high_bits = clue(left_shift=LEFT_SHIFT_BITS) >> LEFT_SHIFT_BITS | 15 | high_bits = clue(left_shift=LEFT_SHIFT_BITS) >> LEFT_SHIFT_BITS | ||
16 | address |= high_bits | 16 | address |= high_bits | ||
17 | 17 | ||||
18 | low_bits = clue(right_shift=RIGHT_SHIFT_BITS) << RIGHT_SHIFT_BITS | 18 | low_bits = clue(right_shift=RIGHT_SHIFT_BITS) << RIGHT_SHIFT_BITS | ||
19 | address |= low_bits | 19 | address |= low_bits | ||
20 | 20 | ||||
21 | fifth_bit = clue(bw_and=BW_AND_MASK) | 21 | fifth_bit = clue(bw_and=BW_AND_MASK) | ||
22 | address |= ((fifth_bit != ZERO) << FIFTH_BIT_POSITION) | 22 | address |= ((fifth_bit != ZERO) << FIFTH_BIT_POSITION) | ||
23 | 23 | ||||
24 | fourth_bit = clue(bw_or=BW_OR_MASK) | 24 | fourth_bit = clue(bw_or=BW_OR_MASK) | ||
25 | address |= ((fourth_bit == BW_OR_RESULT) << FOURTH_BIT_POSITION) | 25 | address |= ((fourth_bit == BW_OR_RESULT) << FOURTH_BIT_POSITION) | ||
26 | 26 | ||||
27 | return address | 27 | return address |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|