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

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

1 точки общо

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

 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

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

t1from secret import cluet1from secret import clue
22
3ZERO = 0 3ZERO = 0 
4LEFT_SHIFT_BITS = 54LEFT_SHIFT_BITS = 5
5RIGHT_SHIFT_BITS = 55RIGHT_SHIFT_BITS = 5
6BW_AND_MASK = 166BW_AND_MASK = 16
7BW_OR_MASK = 247  7BW_OR_MASK = 247  
8BW_OR_RESULT = 255  8BW_OR_RESULT = 255  
9FIFTH_BIT_POSITION = 4  9FIFTH_BIT_POSITION = 4  
10FOURTH_BIT_POSITION = 310FOURTH_BIT_POSITION = 3
1111
12def lucky():12def lucky():
13    address = ZERO13    address = ZERO
1414
15    high_bits = clue(left_shift=LEFT_SHIFT_BITS) >> LEFT_SHIFT_BITS15    high_bits = clue(left_shift=LEFT_SHIFT_BITS) >> LEFT_SHIFT_BITS
16    address |= high_bits 16    address |= high_bits 
1717
18    low_bits = clue(right_shift=RIGHT_SHIFT_BITS) << RIGHT_SHIFT_BITS18    low_bits = clue(right_shift=RIGHT_SHIFT_BITS) << RIGHT_SHIFT_BITS
19    address |= low_bits 19    address |= low_bits 
2020
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)
2323
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)
2626
27    return address27    return address
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op