Предизвикателства > Осем-измерна битова баница с късмет > Решения > Решението на Марина Господинова

Резултати
1 точки от тестове
0 точки от учител

1 точки общо

1 успешни теста
0 неуспешни теста
Код

 1from secret import clue
 2
 3
 4def lucky():
 5    """Find the lucky number"""
 6
 7    first_three_bits = clue(right_shift=5)
 8    fourth_bit = clue(bw_or=239) # 11101111(239) | my_num -> saves 4th bit, sets others to 1
 9    fifth_bit = clue(bw_and=8) # 00001000(8) & my_num -> saves 5th bit, sets others to 0
10    last_three_bits = clue(left_shift=5)
11
12    last_three_bits >>= 5
13    first_three_bits <<= 5
14    fourth_bit ^= 239 # 11101111(239) ^ fourth_bit -> saves 4th bit, sets 1s to 0s
15
16    address = 0 # 00000000 for mask
17    address |= first_three_bits
18    address |= fourth_bit
19    address |= fifth_bit
20    address |= last_three_bits
21
22    return address

.
----------------------------------------------------------------------
Ran 1 test in 0.004s

OK

Дискусия
История

f1from secret import cluef1from secret import clue
22
nn3 
3def lucky():4def lucky():
nn5    """Find the lucky number"""
6 
4    first_three_bits = clue(right_shift=5)7    first_three_bits = clue(right_shift=5)
t5    fourth_bit = clue(bw_or=239) # 11101111(239) | myNum -> saves 4th bit, sets others to 1t8    fourth_bit = clue(bw_or=239) # 11101111(239) | my_num -> saves 4th bit, sets others to 1
6    fifth_bit = clue(bw_and=8) # 00001000(8) & myNum -> saves 5th bit, sets others to 09    fifth_bit = clue(bw_and=8) # 00001000(8) & my_num -> saves 5th bit, sets others to 0
7    last_three_bits = clue(left_shift=5)10    last_three_bits = clue(left_shift=5)
811
9    last_three_bits >>= 512    last_three_bits >>= 5
10    first_three_bits <<= 513    first_three_bits <<= 5
11    fourth_bit ^= 239 # 11101111(239) ^ fourth_bit -> saves 4th bit, sets 1s to 0s14    fourth_bit ^= 239 # 11101111(239) ^ fourth_bit -> saves 4th bit, sets 1s to 0s
1215
13    address = 0 # 00000000 for mask16    address = 0 # 00000000 for mask
14    address |= first_three_bits17    address |= first_three_bits
15    address |= fourth_bit18    address |= fourth_bit
16    address |= fifth_bit19    address |= fifth_bit
17    address |= last_three_bits20    address |= last_three_bits
1821
19    return address22    return address
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op