Остават ли числа, степени на двойка?

Краен срок
11.03.2015 17:00

Срокът за предаване на решения е отминал

В програмисткия свят числото 2 е много много важно. Числата степени на 2 (1, 2, 4, 8, 16.. и т.н.) също. Всяко положително число може да се представи като сбор от числа, които са степени на 2.

Да се напише функция def powers_of_two_remain(numbers), която приема списък от цели положителни числа и връща True или False.

Функцията разсъждава по следния начин:

На входа се подава списъка от числа (например [6, 10, 8, 3, 3])

  • създава нов списък, като представя числата чрез такива, които са степени на 2 и сбора им е равен на числото от списъка. Взима възможно най-големите числа степени на двойка:

      [8]  #=> [8]
      [10]  #=> [8, 2]
      [7, 3] #=> [4, 2, 1, 2, 1]
      [6, 10, 8, 3, 3]  #=> [4, 2, 8, 2, 8, 2, 1, 2, 1]
    

Обръщаме внимание, че 10 може да се разбие като [2, 2, 2, 2, 2], но трябва да вземем най-големите възможни числа степени на 2 и за това задължително го разбиваме във вида [8, 2].

  • от новосъздадения списък, премахваме числата, които се срещат четен брой пъти:

[4, 2, 8, 2, 8, 2, 1, 2, 1] #=> [4]

  • Ако след премахването се окаже че има "оцелели", връщаме True. В противен случай False.

Примери:

    def powers_of_two_remain([])  #=> False
    def powers_of_two_remain([7, 8])  #=> True
    def powers_of_two_remain([4, 8, 12])  #=> False

Решения

Кристиан Ташков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Ташков
import functools
def powers_of_two_remain(numbers):
return bool(functools.reduce(lambda x, y: x ^ y, numbers, 0))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Христиан Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христиан Димитров
from math import log
from math import pow
def powers_of_two_remain(numbers):
powers_of_two = []
for number in numbers:
while number > 0:
max_power_of_two = int(log(number, 2))
max_devisor = pow(2, max_power_of_two)
number -= max_devisor
powers_of_two.append(int(max_devisor))
new_powers_of_two = list(filter(lambda x: powers_of_two.count(x) % 2 != 0,
powers_of_two))
return new_powers_of_two != []
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Калоян Евтимов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Евтимов
def powers_of_two_remain(numbers):
pows = list()
for number in numbers:
bin_presentation = bin(number)[2:]
curr_number_len = len(bin_presentation)
for i in range(0, curr_number_len):
if bin_presentation[i] == '1':
pows += [2 ** (curr_number_len - 1 - i)]
all_numbers = set(pows)
for number in all_numbers:
if pows.count(number) % 2 != 0:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Диана Генева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Диана Генева
from math import floor, log
def powers_of_two(number):
if (number == 0):
return []
else:
largest_power = 2 ** (floor(log(number, 2)))
remainder = number - largest_power
return [largest_power] + powers_of_two(remainder)
def powers_of_two_remain(numbers):
represented_numbers = []
for number in numbers:
represented_numbers.extend(powers_of_two(number))
return set(filter(lambda x: represented_numbers.count(x) % 2 != 0,
represented_numbers)) != set()
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Ангел Ангелов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Ангелов
def powers_of_two(number):
powers = []
power = 1
while number:
if number % 2:
powers.append(power)
number //= 2
power *= 2
return powers
def powers_of_two_remain(numbers):
powers = sum(map(powers_of_two, numbers), [])
return any(map(lambda number: powers.count(number) % 2, powers))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елена Денева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Денева
import functools
def powers_of_two_remain(numbers):
return functools.reduce(lambda x, y: x ^ y, numbers, 0) > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Димитър Влаховски
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Влаховски
from functools import reduce
def powers_of_two_remain(numbers):
return reduce(lambda a, b: a ^ b, numbers, 0) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Георги Чулев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Чулев
import itertools
def largest_powers_of_two(number):
""" Calculates the largest powers of two for a given number. """
return [2 ** index for index, digit in
enumerate(str(bin(number)[:1:-1])) if int(digit) > 0
]
def powers_of_two_remain(numbers):
""" Checks if at least one frequency of occurence is an odd number. """
all_powers_of_two = list(itertools.chain.from_iterable(
[largest_powers_of_two(number)
for number in numbers]))
occurence_frequency = [all_powers_of_two.count(occurences)
for occurences in all_powers_of_two]
return all(occurences % 2 == 0
for occurences in occurence_frequency) is False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Евгения Евлогиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Евгения Евлогиева
def number_to_list_of_powers_of_two(number):
binary = bin(number)
result = []
power = len(binary[2:]) - 1
for digit in binary[2:]:
if digit == '1':
result.append(2 ** power)
power -= 1
return result
def powers_of_two_remain(numbers):
powers_two = []
for number in numbers:
powers_two += number_to_list_of_powers_of_two(number)
result = list(filter(lambda x: powers_two.count(x) % 2 != 0, powers_two))
return bool(result)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Янислав Василев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Янислав Василев
# Version 0.1
def int_to_bin(number):
return str(bin(number))[2:]
def powers_of_two_remain(numbers):
decomposition = []
for number in list(map(int_to_bin, numbers)):
for index, digit in enumerate(number[::-1]):
if digit == '1':
decomposition.append(2 ** index)
return len([number for number in decomposition
if decomposition.count(number) % 2 != 0]) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Красимир Николов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Красимир Николов
import math
def powers_of_two_remain(numbers):
powers = []
power_two = lambda x: int(math.log(x, 2))
for num in numbers:
while num:
result = 2**power_two(num)
powers.append(result)
num -= result
return any([x for x in powers if powers.count(x) % 2 != 0])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Тачо Желев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Тачо Желев
def powers_of_two(num):
pws = []
pow = 0
while num > 0:
while 2**pow <= num:
pow += 1
pws.append(2**(pow-1))
num -= 2**(pow-1)
pow = 0
return pws
def concat_lists(double_list):
return [x for list in double_list for x in list]
def concat_list_powers(mylist):
return concat_lists(list(map(powers_of_two, mylist)))
def remove_even_counts(mylist):
return list( filter((lambda x: mylist.count(x)%2!=0), mylist) )
def powers_of_two_remain(numbers):
return bool( remove_even_counts(concat_list_powers(numbers)) )
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Александър Попов
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Александър Попов
import math
def predicate(list, power_of_two):
return list.count(power_of_two) % 2 != 0
def powers_of_two_remain(numbers):
result = []
for x in numbers:
curr = x
while curr > 0:
power_of_two = math.floor(math.log(curr, 2))
result.append(2**power_of_two)
curr -= 2**power_of_two
return bool(filter(lambda x: predicate(result, x), result))
if __name__ == '__main__':
powers_of_two_remain([])
powers_of_two_remain([7, 8])
powers_of_two_remain([4, 8, 12])
.FF.F
======================================================================
FAIL: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-siiec4/test.py", line 54, in test_empty_list_as_argument
    solution.powers_of_two_remain([])
AssertionError: True is not false

======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-siiec4/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false

======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-siiec4/test.py", line 40, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([8, 8])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.009s

FAILED (failures=3)
Теодор Климентов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Климентов
def add_stuff(list, number):
exp = []
while number > 0:
exp.append((number % 2) * 2**len(exp))
number //= 2
list.extend(filter(lambda x: x > 0, reversed(exp)))
def powers_of_two_remain(numbers):
exp = []
for number in numbers:
add_stuff(exp, number)
return 0 < len(list(filter(lambda x: exp.count(x) % 2, exp)))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Данаил Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Данаил Димитров
def powers_of_two_remain(numbers):
atomicValues = []
for number in numbers:
atomicValues.extend(toAtomicValues(number))
numbersWithCounts = countOccurrences(atomicValues)
for number in numbersWithCounts:
if numbersWithCounts[number] % 2 == 1:
return True
return False
def countOccurrences(atomicValues):
counts = {}
for number in atomicValues:
if number in counts:
counts[number] += 1
else:
counts[number] = 1
return counts
def toAtomicValues(number):
result = []
valueOfBit = 1;
while number > 0:
if number & 1:
result.append(valueOfBit)
number >>= 1
valueOfBit *= 2
return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Ирина Христова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ирина Христова
from math import log
from collections import Counter
def powers_of_two_remain(numbers):
result = []
for number in numbers:
total = 0
while total != number:
num = number - total
total += 2 ** int(log(num, 2))
result.append(2 ** int(log(num, 2)))
counts = Counter(result)
return len(list(filter(lambda k: k % 2 != 0, counts.values()))) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Емил Великов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Емил Великов
def find_nearest_pow_of_2(n):
pow_2 = 1
while pow_2 <= n:
pow_2 = pow_2 * 2
return int(pow_2 / 2)
def find_sum_of_nums_pow_2(numbers):
result = []
for number in numbers:
while number > 0:
num_pow_of_2 = find_nearest_pow_of_2(number)
result.append(num_pow_of_2)
number = number - num_pow_of_2
return result
def remove_even_duplicates(numbers):
for number in numbers:
if (numbers.count(number) % 2 == 0):
numbers = list(filter(lambda x: x != number, numbers))
return numbers
def powers_of_two_remain(numbers):
pow_2_nums = find_sum_of_nums_pow_2(numbers)
removed_even_duplicates = remove_even_duplicates(pow_2_nums)
return len(removed_even_duplicates) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Илиян Якимов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Якимов
def str_to_digits_list(x):
digits = []
for sym in x[2:]:
digits.append(int(sym))
return digits
def fragmentation(digits_list):
i = len(digits_list) - 1
result = []
for d in digits_list:
if d != 0:
result.append(2 ** i)
i -= 1
return result
def fragm_for_every(numbers_list):
fragments = []
for num in numbers_list:
fragments.extend(fragmentation(str_to_digits_list(bin(num))))
return fragments
def powers_of_two_remain(numbers):
nearly_final = fragm_for_every(numbers)
final_list = [x for x in nearly_final if nearly_final.count(x) % 2 != 0]
if len(final_list) > 0:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Цветан Коев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Коев
import itertools
def remove_even(numbers):
return [x for x in numbers if numbers.count(x) % 2 == 1]
def number_to_power_of_twos(number):
power_of_twos = []
binary = [int(i) for i in bin(number)[2:]]
for index, value in enumerate(binary):
if value != 0:
power_of_twos.append(2 ** (len(binary) - index - 1))
return power_of_twos
def powers_of_two_remain(numbers):
numbers = list(map(number_to_power_of_twos, numbers))
return len(remove_even(list(itertools.chain.from_iterable(numbers)))) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Николай Велков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Велков
def powers_by_number(numbers, num):
result = []
for x in numbers:
if num == 0:
break
if x <= num:
num = num - x
result.append(x)
return result
def powers_of_two(number):
return [x for x in
reversed([2 ** i for i in range(0, number+1) if 2 ** i <= number])]
def modify_numbers(numbers):
result = []
for x in numbers:
result.extend(powers_by_number(powers_of_two(x), x))
return result
def remove_even_occurences(numbers):
return [x for x in numbers if numbers.count(x) % 2 == 1]
def powers_of_two_remain(numbers):
return len(remove_even_occurences(modify_numbers(numbers))) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Станислав Гатев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Гатев
import functools
import operator
def powers_of_two_remain(numbers):
return functools.reduce(operator.xor, numbers, 0) > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Калоян Витанов
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Калоян Витанов
def powers_of_two_remain(numbers):
lenght = len(numbers)
for i in range(lenght):
if numbers[i] <= 0 or (type(numbers[i])is not int):
return("Invalid data!")
parts = []
for i in range(lenght):
variable = numbers[i]
while variable >= 2:
k = 2
while k <= variable/2:
k = k * 2
variable = variable-k
parts.append(k)
if variable == 1:
parts.append(variable)
remind_element = []
remind_times_encountered = []
lenght = len(parts)
for i in range(lenght):
variable = parts[i]
k = parts.count(variable)
if (k % 2 == 0)and (variable not in remind_element):
remind_element.append(variable)
remind_times_encountered.append(k)
lenght = len(remind_element)
for i in range(lenght):
for j in range(remind_times_encountered[i]):
parts.remove(remind_element[i])
if parts == []:
return("False")
else:
return("True")
.FF.F
======================================================================
FAIL: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1x2nl9w/test.py", line 54, in test_empty_list_as_argument
    solution.powers_of_two_remain([])
AssertionError: 'False' is not false

======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1x2nl9w/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: 'False' is not false

======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1x2nl9w/test.py", line 40, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([8, 8])
AssertionError: 'False' is not false

----------------------------------------------------------------------
Ran 5 tests in 0.008s

FAILED (failures=3)
Иван Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Иванов
def powers_of_two(number):
return [2 ** (index) for index, value
in enumerate(reversed("{0:b}".format(number))) if int(value) == 1]
def powers_of_two_remain(numbers):
remaining_powers_of_two = []
for number in numbers:
for power_of_two in powers_of_two(number):
remaining_powers_of_two.append(power_of_two)
for element in set(remaining_powers_of_two):
if remaining_powers_of_two.count(element) % 2 == 1:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Минх Нгуен
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Минх Нгуен
from math import log, floor
def powers_of_two_remain(numbers):
if len(numbers) == 0:
return False
power_of_two_numbers = []
for number in numbers:
while number > 0:
max_power_of_two = 2 ** floor(log(number, 2))
number -= max_power_of_two
power_of_two_numbers.append(max_power_of_two)
for number in power_of_two_numbers:
if power_of_two_numbers.count(number) % 2 == 1:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Момчил Сулов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Момчил Сулов
def decomposition_of(number):
decomposed = []
while number > 0:
current = 1
while current <= number:
current *= 2
current //= 2
decomposed.append(current)
number -= current
return decomposed
def decompositions(numbers):
decomposed = []
for e in numbers:
decomposed.extend(decomposition_of(e))
return decomposed
def powers_of_two_remain(numbers):
decomposed = decompositions(numbers)
remaining = [x for x in decomposed if decomposed.count(x) % 2 == 1]
return remaining != []
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Цветан Мадански
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Мадански
import math
def is_power_2(number):
power = int(math.log(number, 2))
return 2 ** power == number
def transform_list_to_pow2(list_of_numbers):
transformed_list = []
for element in list_of_numbers:
if is_power_2(element):
transformed_list.append(element)
else:
help_list = transform_number_to_sum(element)
for elements in help_list:
transformed_list.append(elements)
return transformed_list
def transform_number_to_sum(number):
counter = 0
transformed_number = []
while number:
while not is_power_2(number):
counter = counter + 1
number = number - 1
transformed_number.append(number)
if is_power_2(counter):
transformed_number.append(counter)
return transformed_number
number = counter
counter = 0
def counter_of_element(element, list_of_elements):
return len([x for x in list_of_elements if x == element])
def powers_of_two_remain(numbers):
elements = transform_list_to_pow2(numbers)
return len([x for x in elements
if counter_of_element(x, elements) % 2 == 1]) > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Николай Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Георгиев
def get_powers_of_two(number):
if number <= 0:
return []
i = 1
while i <= number:
i *= 2
i //= 2
return [i] + get_powers_of_two(number - i)
def powers_of_two_remain(numbers):
powers_of_two = []
for number in numbers:
powers_of_two.extend(get_powers_of_two(number))
powers = list(filter(lambda x: powers_of_two.count(x) % 2 != 0,
powers_of_two))
return len(powers) > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Валентина Жекова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Валентина Жекова
from math import log
def powers_of_two_remain(numbers):
if numbers:
power_limit = int(log(max(numbers), 2))
powers_of_two = [2 ** p for p in range(power_limit, -1, -1)]
for number in powers_of_two:
contained_count = len([x for x in numbers if x >= number])
if contained_count % 2:
return True
else:
numbers = [x - number if x >= number else x for x in numbers]
if not any(numbers):
break
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Йоан Динков
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Йоан Динков
import math
import itertools
def to_power_of_two(number):
powers = []
while number > 0:
largest_power = 2 ** int(math.log(number, 2))
powers.append(largest_power)
number -= largest_power
return powers
def powers_of_two_remain(numbers):
powers = map(to_power_of_two, numbers)
result = list(itertools.chain(*powers))
uniques = [x for x in result if result.count(x) == 1]
return bool(uniques)
...F.
======================================================================
FAIL: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-19sqzrz/test.py", line 27, in test_power_of_two_remain_numbers_do_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 1])
AssertionError: False is not true

----------------------------------------------------------------------
Ran 5 tests in 0.006s

FAILED (failures=1)
Мартин Пацов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Пацов
def powers_of_two_remain(numbers):
my_list = []
for number in numbers:
binary = str(bin(number))[2:]
for digit in range(0, len(binary)):
if binary[digit] == "1":
my_list.append(2 ** (len(binary) - digit - 1))
remove_list = []
for element in my_list:
if my_list.count(element) % 2 == 0:
remove_list.append(element)
for element in remove_list:
my_list[:] = [x for x in my_list if x != element]
if my_list == []:
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Иван Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
def decomposition(n):
result = []
for i in range(n, 0, -1):
if bin(i).count('1') == 1 and sum(result) + i <= n:
result.append(i)
return result
def powers_of_two_remain(numbers):
result = []
for number in numbers:
result += decomposition(number)
return bool([x for x in result if result.count(x) % 2])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Валентин Латунов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Латунов
def powers_of_two_remain(numbers):
result = []
for num in numbers[:]:
multiple_of_2 = 1
while num > 0:
if num % 2:
result.append(multiple_of_2)
multiple_of_2 = multiple_of_2 * 2
num = int(num / 2)
count = {x: result.count(x) for x in set(result)}
return bool(list(filter(lambda x: count[x] % 2, count)))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Явор Големанов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Явор Големанов
def sum(numbers):
sum = 0
for it in numbers:
sum += it
return sum
def pow_of_twos(number):
my_number = number
while my_number > 0:
if my_number / 2 == 1 and my_number % 2 == 0:
return True
my_number /= 2
return False
def number_to_twos(number):
my_number = number
result = []
while my_number > 0:
if my_number == 1:
result.append(1)
return result
elif pow_of_twos(my_number) and not sum(result) + my_number == number:
result.append(my_number)
my_number = number - sum(result)
elif pow_of_twos(my_number) and (sum(result) + my_number) == number:
result.append(my_number)
return result
else:
my_number -= 1
def numbers_to_twos_list(my_list):
result = []
for it in my_list:
result += (number_to_twos(it))
return result
def powers_of_two_remain(numbers):
new_numbers = numbers_to_twos_list(numbers)
for it in new_numbers:
counter = 0
for it1 in new_numbers:
if it == it1:
counter += 1
if not counter % 2 == 0:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.193s

OK
Михаел Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Михаел Димитров
def powers_of_two_remain(numbers):
squared_sums = [sum_of_squares(number) for number in numbers]
flattened = get_flattened_list_from(squared_sums)
result = [x for x in flattened if flattened.count(x) % 2 != 0]
return bool(result)
def get_flattened_list_from(lists):
return [item for sublist in lists for item in sublist]
def sum_of_squares(number):
max_power, integer_value = 0, number
while 2 ** max_power < integer_value:
max_power += 1
sum_of_squares = []
for power in range(max_power, -1, -1):
addend = 2 ** power
if addend <= integer_value:
sum_of_squares.append(addend)
integer_value -= addend
return sum_of_squares
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Александър Ваканин
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Ваканин
def powers_of_two_remain(numbers):
result = []
for n in numbers:
result += powers_of_two(n)
return bool(remove_even_elements(result))
def powers_of_two(number):
result = []
while number > 0:
i = 0
while 2 ** i <= number:
i += 1
x = 2 ** (i - 1)
number -= x
result += [x]
return result
def remove_even_elements(numbers):
elements_to_remove = []
for e in numbers:
if numbers.count(e) % 2 == 0:
elements_to_remove += [e]
return set(numbers) - set(elements_to_remove)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Венцислав Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Димитров
import math
def powers_of_two_remain(numbers):
crushing = []
for number in numbers:
crushing = crushing + generate_degree(number)
for num in crushing:
if crushing.count(num) % 2 != 0:
return True
return False
def generate_degree(num):
if math.sqrt(num) % 1 == 0 or num == 1:
return [num]
degree_numbers = []
while True:
degree = return_degree(num)
degree_numbers.append(degree)
num = num - degree
if num <= 0:
break
return degree_numbers
def return_degree(num):
while num >= 0:
if math.log(num, 2) % 1 == 0:
return num
num = num - 1;
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Марина Узунова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Марина Узунова
import collections
def powers_of_two_remain(numbers):
powers_of_two = []
for number in numbers:
for i in range(0, 32):
mask = 1 << i
if (number & mask) != 0:
powers_of_two.append(mask)
powers_of_two = dict(collections.Counter(powers_of_two))
odd_counts = [key for key, x in powers_of_two.items() if x % 2 == 1]
return bool(odd_counts)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Димитрина Гецкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитрина Гецкова
def fritter_elem(number, fritters_numbers):
degree_two = 2
while degree_two <= number:
degree_two *= 2
degree_two /= 2
# the bigest degree of two for this number
fritters_numbers.append(int(degree_two))
residue = number - degree_two
if residue > 0:
# result.append(int(residue))
fritter_elem(residue, fritters_numbers)
return fritters_numbers
def powers_of_two_remain(numbers):
result = []
index_count_to_del = set([])
# print(type(index_count_to_del))
for number in numbers:
result = fritter_elem(number, result)
# print(result)
for elem in result:
count_congregation_elem = result.count(elem)
if count_congregation_elem % 2 == 0:
# print(elem, result.count(elem))
# must be tuple (only mutable in set)
index_count_to_del.add((elem, result.count(elem)))
# print(index_count_to_del)
for index in index_count_to_del:
num_to_remove = index[0]
count_of_occure_num = index[1]
# print ("result :::", result , "numto remove",num_to_remove, index )
while count_of_occure_num:
result.remove(num_to_remove)
count_of_occure_num -= 1
# print(result)
# print(index_count_to_del)
return len(result) is not 0
# powers_of_two_remain([7, 8, 7, 8])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Михаил Здравков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Михаил Здравков
import math
def power_factorization(num):
# get the highest power of two that is smaller or equal to num
power = 2 ** math.floor(math.log(num, 2))
if num == power:
return [num]
else:
return [power] + power_factorization(num - power)
def powers_of_two_remain(numbers):
factorization = list(sum(map(power_factorization, numbers), []))
histogram = {num: factorization.count(num) for num in set(factorization)}
remains = list(filter(lambda v: v % 2 != 0, histogram.values()))
return len(remains) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Виктория Терзиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Виктория Терзиева
from operator import xor
def is_number_power_of_two(number):
return number is not 0 and not(number & (number - 1))
def make_number_as_sum_of_powers(number):
copy = number
result = []
while number > 0:
while not is_number_power_of_two(copy):
copy -= 1
result.append(copy)
number -= copy
copy = number
return result
def make_list_of_powers(numbers):
result = list()
for number in numbers:
result.extend(make_number_as_sum_of_powers(number))
return result
def powers_of_two_remain(numbers):
new_numbers = make_list_of_powers(numbers)
if len(numbers) > 0:
result = numbers[0]
else:
result = 0
for number in numbers[1:]:
result = xor(result, number)
return result > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Виктор Цонев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Цонев
def powers_of_two_remain(numbers):
while sum(numbers) != 0:
if sum(numbers) % 2 == 1:
return True
else:
new = []
for i in numbers:
new.append(i // 2)
numbers = new
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Любослав Кънев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Любослав Кънев
def is_power_of_two(number):
return number > 0 and number & (number - 1) == 0
def get_powers_of_two(number):
current_sum = 0
current_number = number
result = []
while current_sum < number:
if is_power_of_two(current_number):
current_sum += current_number
result.append(current_number)
current_number = number - current_sum
else:
current_number -= 1
return result
def flatten(l):
items = []
for sublist in l:
for item in sublist:
items.append(item)
return items
def powers_of_two_remain(numbers):
powers = flatten(map(get_powers_of_two, numbers))
for x in powers:
if powers.count(x) % 2 != 0:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Цветан Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Иванов
def is_power_of_two(number):
return (number & (number-1) == 0) and (number != 0)
def is_even(number):
return number % 2 == 0
def powers_of_two_for_number(number):
powers_of_two = []
current_number = number
while current_number > 0:
if is_power_of_two(current_number):
powers_of_two.append(current_number)
number = number - current_number
current_number = number + 1
current_number -= 1
return powers_of_two
def powers_of_two_for_numbers(numbers):
powers_of_two = []
for x in numbers:
powers_of_two.extend(powers_of_two_for_number(x))
return powers_of_two
def remove_even_elements(numbers):
unique_elements = []
for x in numbers:
if not is_even(numbers.count(x)):
unique_elements.append(x)
return unique_elements
def powers_of_two_remain(numbers):
power_of_two_list = powers_of_two_for_numbers(numbers)
remaining_numbers = remove_even_elements(power_of_two_list)
return len(remaining_numbers) > 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Спасимир Нонев
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Спасимир Нонев
import itertools
def powers_of_two_remain(numbers):
new_list = []
for number in numbers:
while number > 0:
for i in itertools.count():
if 2 ** i > number:
new_list.append(2 ** (i - 1))
number -= 2 ** (i - 1)
break
for element in new_list:
if new_list.count(element) % 2 == 0:
while element in new_list:
new_list.remove(element)
if len(new_list) == 0:
return False
else:
return True
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1vyjmcm/test.py", line 43, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([7, 7])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.006s

FAILED (failures=1)
Явор Михайлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Явор Михайлов
import math
import itertools
def powers_of_two_remain(numbers):
powers = []
for number in numbers:
powers.append(max_powers_of_two_for(number))
powers = list(itertools.chain(*powers))
powers_with_even_repeats = []
for number in powers:
if powers.count(number) % 2 > 0:
powers_with_even_repeats.append(number)
return bool(powers_with_even_repeats)
def max_powers_of_two_for(number):
numbers = []
for i in range(number, 0, -1):
log_of_two = math.log(i, 2)
new_sum = sum(numbers) + i
if log_of_two.is_integer() and new_sum <= number:
numbers.append(i)
return numbers
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Георги Павлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Павлов
def formula(index, number):
return int(number[index]) * 2**(len(number) - (index+1))
def powers_of_two(number):
return [formula(i, number) for i
in range(0, len(number)) if number[i] is not '0']
def powers_of_two_remain(numbers):
powers = []
for number in numbers:
binary_number = bin(number)[2:]
powers.extend(powers_of_two(binary_number))
for number in powers:
if powers.count(number) % 2 is not 0:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елена Орешарова
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Елена Орешарова
def powers_of_two_remain(numbers):
result_set = []
for number in numbers:
if is_power_of_two(number):
result_set.append(number)
else:
result_set.extend(decompose_number(number))
for number in result_set:
if result_set.count(number) % 2 == 0:
while number in result_set:
result_set.remove(number)
return True if result_set else False
def is_power_of_two(number):
return (number & (number - 1) == 0) and (number != 0)
def decompose_number(number):
pow_two = []
iterator = number
while iterator > 0:
if is_power_of_two(iterator) and sum(pow_two) != number:
pow_two.append(iterator)
iterator -= 1
return pow_two
..F.F
======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1l6vyt2/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false

======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1l6vyt2/test.py", line 43, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([7, 7])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=2)
Вера Бойчева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Вера Бойчева
def powers_of_two_remain(numbers):
def is_power_of_two(number):
if number == 1:
return True
elif number % 2 == 0:
return is_power_of_two(number / 2)
else:
return False
def max_power_in(number):
if is_power_of_two(number) == True:
return number
else:
return max_power_in(number - 2)
def convert_number(number):
if number <= 0:
return []
elif is_power_of_two(number) == True:
return [number]
elif number % 2 == 0:
max_num = max_power_in(number)
return [max_num]+convert_number(number-max_num)
else:
return convert_number(number-1)+[1]
def odd_times(numbers):
result = []
for number in numbers:
if (numbers.count(number) % 2) != 0:
result.append(number)
return result
new_numbers = []
for number in numbers:
new_numbers.extend(convert_number(number))
print(new_numbers)
if odd_times(new_numbers) == []:
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Марио Даскалов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Даскалов
from functools import reduce
from operator import xor
def powers_of_two_remain(numbers):
return bool(reduce(xor, numbers, 0))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Христо Тодоров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Тодоров
def powers_of_two_remain(numbers):
numbers_grades_of_two = []
for i in numbers:
number = str(bin(i))
for j in range(-1, 1 - len(number), -1):
n = 2 ** (abs(j + 1)) * int(number[j])
if n != 0:
numbers_grades_of_two.append(n)
if not list(filter(
lambda x: predicate(x, numbers_grades_of_two), numbers_grades_of_two)):
return False
else:
return True
def predicate(x, l):
return int(l.count(x)) % 2 != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Ангел Венчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Венчев
import functools
def powers_of_two_remain(numbers):
return bool(functools.reduce(lambda x,y : x ^ y, numbers, 0))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Цвета Кандиларова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цвета Кандиларова
import math
from collections import Counter
def powers_of_two(number):
powers2 = []
while number > 0:
powers2.append(2 ** math.floor(math.log2(number)))
number -= 2 ** math.floor(math.log2(number))
return powers2
def powers_of_two_remain(numbers):
powers = []
for number in numbers:
powers.extend(powers_of_two(number))
powers_count = Counter(powers)
for key in powers_count:
if powers_count[key] % 2 == 1:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Александър Танков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Танков
def list_of_powers_of_two_to_num(number):
powers_of_two = []
for num in range(0, number):
if pow(2, num) <= number:
powers_of_two.append(pow(2, num))
else:
break
return powers_of_two
def dropping_number(number, powers_of_two):
result = []
while len(powers_of_two) != 0:
i = powers_of_two.pop()
if number - i >= 0:
number -= i
result.append(i)
return result
def is_result_valid(list_of_result):
while len(list_of_result) != 0:
try:
num = list_of_result.pop()
list_of_result.remove(num)
except ValueError:
return True
return False
def powers_of_two_remain(numbers):
if len(numbers) == 0:
return False
result = []
while len(numbers) != 0:
number_from_list = numbers.pop()
powers_of_two = list_of_powers_of_two_to_num(number_from_list)
result.extend(dropping_number(number_from_list, powers_of_two))
return is_result_valid(result)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Илиан Стаменов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Илиан Стаменов
from functools import reduce
def powers_of_two_remain(numbers):
return reduce(int.__xor__, numbers, 0) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Никола Терзиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Терзиев
def number_powers_of_two(number):
bin_representation = bin(number)[2:][::-1]
number_powers, pow = [], 0
for step in bin_representation:
if (step == '1'):
number_powers.append(2 ** pow)
pow += 1
return number_powers
def list_of_numbers_powers_of_two(numbers):
numbers_powers = []
for number in numbers:
numbers_powers.extend(number_powers_of_two(number))
return numbers_powers
def powers_of_two_remain(numbers):
number_powers = list_of_numbers_powers_of_two(numbers)
result = 0
for number in numbers:
result = result ^ number
return True if (result != 0) else False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Йордан Михайлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Михайлов
def powers_of_two_for_number(number):
powers = []
pow = 0
while number > 0:
if number % 2 == 1:
powers.append(2**pow)
number //= 2
pow += 1
return powers
def powers_of_two_for_list(numbers):
powers = list(map(powers_of_two_for_number, numbers))
return [number for list_of_numbers in powers for number in list_of_numbers]
def remove_odd_time_duplicate(powers):
return list([number for number in powers if powers.count(number) % 2 == 1])
def powers_of_two_remain(numbers):
return bool(remove_odd_time_duplicate(powers_of_two_for_list(numbers)))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.008s

OK
Георги Димов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димов
def closest_power_of_two(number):
closest_power = 0
while pow(2, closest_power + 1) <= number:
closest_power += 1
return pow(2, closest_power)
def split_to_powers_of_two(number):
powers = []
while number > 0:
closest_power = closest_power_of_two(number)
powers.append(closest_power)
number -= closest_power
return powers
def count_of_duplicates(array, value):
counter = 0
for element in array:
if element == value:
counter += 1
return counter
def powers_of_two_remain(numbers):
powers_of_all_numbers = []
for number in numbers:
powers_of_all_numbers.extend(split_to_powers_of_two(number))
unique_powers_of_numbers = set()
for number in powers_of_all_numbers:
if count_of_duplicates(powers_of_all_numbers, number) % 2 != 0:
unique_powers_of_numbers.add(number)
return len(unique_powers_of_numbers) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Добромир Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Добромир Иванов
import math
def sums_upto(number):
member = 2**int(math.log(number, 2))
if number - member > 0:
return [member] + sums_upto(number - member)
else:
return [member]
def powers_of_two_remain(numbers):
powers = [sums_upto(x) for x in numbers]
flat = [item for sublist in powers for item in sublist]
remaining = [x for x in flat if flat.count(x) % 2 != 0]
return not not remaining
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Стилиян Стоянов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стилиян Стоянов
def sum_of_powers(string_of_bin_number):
sum_of_powers = []
for index, bit in enumerate(string_of_bin_number):
if bit == '1':
sum_of_powers += [2 ** index]
return sum_of_powers
def list_of_odd_times(powers_of_two):
flattened_list = [y for x in powers_of_two for y in x]
uniq_numbers = set(flattened_list)
return [num for num in uniq_numbers if flattened_list.count(num) % 2]
def powers_of_two_remain(numbers):
powers_of_two = []
for number in numbers:
reversed_bin_number = bin(number)[::-1]
powers_of_two += [sum_of_powers(reversed_bin_number)]
if not list_of_odd_times(powers_of_two):
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Светлин Славов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Светлин Славов
from collections import Counter
def find_highest_power_of_two(number):
base = -1
result = 2 ** base
while result < number:
base += 1
result = 2 ** base
if result > number:
return int(result/2)
else:
return int(result)
def powers_of_two_remain(numbers):
powers = []
for each in numbers:
while each > 0:
power = find_highest_power_of_two(each)
powers.append(power)
each -= power
occurences = dict(Counter(powers))
length = 0
for item in occurences:
if occurences[item] % 2 != 0:
length += 1
if length:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Даниел Ангелов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Даниел Ангелов
def powers_of_two_remain(numbers):
rs = []
final = []
for number in numbers:
binary = "{0:b}".format(number)
digits = list(binary)
nDigits = len(digits)
for (i,digit) in enumerate(digits):
if digit == "1":
rs.append(2**(nDigits - i - 1))
counter = 0
i = 0
while counter < len(rs):
if (rs.count(2**i) % 2 != 0) :
final.append(2**i)
counter = counter + rs.count(2**i)
i = i+1
if len(final) > 0:
return True
return False;
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Цветелина Александрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветелина Александрова
def powers_of_two_remain(numbers):
if not check_valid_arguments(numbers):
return "Invalid arguments."
all_powers_of_two = []
for number in numbers:
all_powers_of_two += get_powers_of_two(number)
return has_elem_with_uneven_occurances(all_powers_of_two)
def get_powers_of_two(number):
powers = []
while number > 0:
found_power_of_two = get_biggest_power_of_two(number)
if found_power_of_two == -1:
return powers
powers.append(found_power_of_two)
number -= found_power_of_two
return powers
def get_biggest_power_of_two(number):
if number < 1:
return -1
for i in range(0, int(number/2 + 1)):
if 2**i == number:
return number
return get_biggest_power_of_two(number - 1)
def has_elem_with_uneven_occurances(powers):
uneven_counts_removed = []
for power in powers:
if powers.count(power) % 2:
uneven_counts_removed.append(power)
return len(uneven_counts_removed) > 0
def check_valid_arguments(numbers):
if not isinstance(numbers, list):
return False
for number in numbers:
if not isinstance(number, int) or number < 0:
return False
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Николина Тодорова
  • Некоректно
  • 0 успешни тест(а)
  • 5 неуспешни тест(а)
Николина Тодорова
def power_of_one_remain(numbers):
list_new = []
for number in numbers:
list_new += power_of_two_remain(number)
for new in list_new:
count = 0
for n in list_new:
if n == new:
count += 1
if count % 2 == 1:
return True
return False
def power_of_two_remain(number):
new_list = []
numbers = []
sum_1 =[]
counter = 0
n = number
while n != 0:
if n % 2 == 0:
new_list += [0]
n = n // 2
elif n % 2 == 1:
new_list += [1]
n = n // 2
for new in new_list:
l = len(new_list)
number = 2 ** counter
sum_1 += [new * number]
if counter == l:
break
counter += 1
for new_1 in sum_1:
if new_1 != 0:
numbers += [new_1]
return (numbers)
EEEEE
======================================================================
ERROR: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1pswh5a/test.py", line 35, in test_dont_break_down_power_of_two_numbers
    solution.powers_of_two_remain([8])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'

======================================================================
ERROR: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1pswh5a/test.py", line 54, in test_empty_list_as_argument
    solution.powers_of_two_remain([])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'

======================================================================
ERROR: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1pswh5a/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'

======================================================================
ERROR: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1pswh5a/test.py", line 27, in test_power_of_two_remain_numbers_do_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 1])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'

======================================================================
ERROR: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1pswh5a/test.py", line 40, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([8, 8])
AttributeError: 'module' object has no attribute 'powers_of_two_remain'

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (errors=5)
Радослав Комитов
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Радослав Комитов
def powers_of_two_remain(numbers):
lizt = []
for n in numbers:
lizt += po(n)
max_lizt = lizt[0]
for n in numbers:
if n > max_lizt:
max_lizt = n
fl = False
for i in range(1, max_lizt):
br = 0
for n in numbers:
if n == i:
br += 1
if br % 2 == 1:
fl = True
break
return fl
def po(n):
n_list = []
while n > 0:
counter = 1
while counter <= n:
counter = counter * 2
counter = counter // 2
n_list += [counter]
n = n - counter
return n_list
FEF..
======================================================================
ERROR: test_empty_list_as_argument (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1yiph40/test.py", line 54, in test_empty_list_as_argument
    solution.powers_of_two_remain([])
  File "/tmp/d20150321-24164-1yiph40/solution.py", line 6, in powers_of_two_remain
    max_lizt = lizt[0]
IndexError: list index out of range

======================================================================
FAIL: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1yiph40/test.py", line 35, in test_dont_break_down_power_of_two_numbers
    solution.powers_of_two_remain([8])
AssertionError: False is not true

======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1yiph40/test.py", line 16, in test_power_of_two_remain_no_numbers_remain
    solution.powers_of_two_remain([1, 2, 8, 15, 15, 10, 1, 2, 4, 7, 1])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.008s

FAILED (failures=2, errors=1)
Божидар Григоров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Григоров
def is_power2(num):
return num != 0 and ((num & (num - 1)) == 0)
def find_max_power2_addend(number):
for i in range(number, int(number/2), -1):
if is_power2(i):
return i
def powers_of_two(number):
while number > 0:
num = find_max_power2_addend(number)
number -= num
yield num
def remove_even_count_values(numbers):
for num in numbers:
if numbers.count(num) % 2 != 0:
return True
return False
def powers_of_two_remain(numbers):
result = []
for num in numbers:
for power2 in powers_of_two(num):
result.append(power2)
return remove_even_count_values(result)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Галина Димитрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Галина Димитрова
def remove_even_times_numbers(powers):
result = []
checked_elem = []
for i in range(0, len(powers)):
condition1 = powers.count(powers[i]) % 2 != 0
condition2 = powers[i] not in checked_elem
if condition1 and condition2:
result.append(powers[i])
checked_elem.append(powers[i])
return result
def check_sum(powers, number):
result = []
# this for will finish when i == 0
for i in range(len(powers) - 1, -1, -1):
if number - powers[i] >= 0:
number -= powers[i]
result.append(powers[i])
return result
def find_powers_of_a_number(number):
degree = 0
all_powers = []
while 2**degree <= number:
all_powers.append(2**degree)
degree += 1
# if there is only one power in the list and
# if the last power is == number
# we don't need to check the sum.
if len(all_powers) == 1:
return all_powers
elif all_powers[-1] == number:
return [all_powers[-1]]
else:
return check_sum(all_powers, number)
def check_final_result(result):
if result != []:
return True
else:
return False
# if the given list contains only one number,
# it will always return True
def powers_of_two_remain(numbers):
if numbers == []:
return False
elif len(numbers) == 1:
return True
all_powers = []
result = []
for i in range(0, len(numbers)):
all_powers += find_powers_of_a_number(numbers[i])
if len(all_powers) != 1:
result = remove_even_times_numbers(all_powers)
else:
result = all_powers
return check_final_result(result)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Христо Владев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Владев
import functools
import operator
def powers_of_two_remain(numbers):
return functools.reduce(operator.xor, numbers, 0) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK
Васил Малчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Малчев
def powers_of_two_remain(numbers):
sum = 0
powers_two = []
for num in numbers:
for i in range(num // 2, -1, -1):
if(pow(2, i) > num):
continue
if(sum + pow(2, i) > num):
continue
sum += pow(2, i)
powers_two.append(pow(2, i))
if(num == sum):
sum = 0
break
return any(list(powers_two.count(pow_two) % 2 != 0
for pow_two in powers_two))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.039s

OK
Христо Петков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Петков
import itertools
from collections import Counter
def powers_of_two_remain(elements):
flat_elements = list(itertools.chain(*map(split_power_two, elements)))
elements_cnt = dict(Counter(flat_elements))
return bool(list(filter(lambda x: x % 2 != 0, list(elements_cnt.values()))))
def split_power_two(number):
binary_num = list(bin(number)[2:])
enumerated_binary_num = [{'num': x, 'rank': i}
for i, x in enumerate(reversed(binary_num))]
return list(filter(lambda x: x > 0, list(map(power_two_by_key,
enumerated_binary_num))))
def power_two_by_key(number):
return int(number['num'])*pow(2, int(number['rank']))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Мартин Стоев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Стоев
def powers_of_two_remain(numbers):
result = []
for current_element in numbers:
div_nums = [1]
counter = 2
while counter <= current_element:
div_nums.append(counter)
counter = counter*2
div_nums.reverse()
div_result = []
for sub_element in div_nums:
if sum(div_result) + sub_element <= current_element:
div_result.append(sub_element)
result.extend(div_result)
temporary_numbers = []
for sub_element in result:
if sub_element not in temporary_numbers:
if result.count(sub_element) % 2 == 0:
temporary_numbers.append(sub_element)
else:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Мартина Тонковска
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мартина Тонковска
import math
def nearest_power_of_two(number):
p = math.pow(2, math.ceil(math.log(number, 2)))
if number == p:
return int(p)
else:
return int(p/2)
def dissect_number(number):
parts = []
while number > 0:
nearest_power = nearest_power_of_two(number)
parts.append(nearest_power)
number = number - parts[-1]
return parts
def flatten(l):
flattened_list = []
for i in l:
for j in i:
flattened_list.append(j)
return flattened_list
def powers_of_two_remain(numbers):
l = flatten(list(map(dissect_number, numbers)))
l.sort()
for i in l:
occurances = l.count(i)
if occurances % 2 != 0:
return True
else:
l = l[occurances:]
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Екатерина Горанова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Екатерина Горанова
def powers_of_two_remain(numbers):
result = []
for n in numbers:
binary = bin(n)[2:]
powers = [2**(len(binary) - i - 1) for i in range(len(binary)) if int(binary[i])]
result.extend(powers)
return len([item for item in result if result.count(item) % 2]) != 0
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Георги Мавридис
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Мавридис
import math
def remove_values_from_list(the_list, val):
return [value for value in the_list if value != val]
def powers_of_two_remain(numbers):
my_list = list()
for number in numbers:
while number > 0:
my_list.append(2**int(math.log(number, 2)))
number = number - 2**int(math.log(number, 2))
for num in my_list:
if my_list.count(num) % 2 == 0:
my_list = remove_values_from_list(my_list, num)
if len(my_list) > 0:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Клара Кайралах
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Клара Кайралах
def remove_values_from_list(the_list, val):
while val in the_list:
the_list.remove(val)
return the_list
def powers(number):
ls = []
numb = 0
for j in range(0, 32):
numb = 1 << j
if number & numb != 0:
ls.append(numb)
return ls
def flatten(list_of_lists):
flattened = []
for sublist in list_of_lists:
for val in sublist:
flattened.append(val)
return flattened
def list_of_powers_of_two(list_of_numbers):
new_list = list(map(powers, list_of_numbers))
l = flatten(new_list)
for item in l:
if l.count(item) % 2 == 0:
l = remove_values_from_list(l, item)
return list(l)
def powers_of_two_remain(numbers):
list_of_powers = list_of_powers_of_two(numbers)
if not list_of_powers:
return False
else:
return True
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-14cs4l3/test.py", line 43, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([7, 7])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=1)
Никола Монов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Монов
def check_if_pow_of_two(num):
return num != 0 and ((num & (num - 1)) == 0)
def break_up_num(num, arr):
if check_if_pow_of_two(num):
arr.append(num)
return arr
else:
x = num - 1
while not check_if_pow_of_two(x):
x -= 1
arr.append(x)
return break_up_num(num - x, arr)
def break_up_nums(array, new_array):
for element in array:
break_up_num(element, new_array)
return new_array
def remove_nums(arr):
for el in set(arr):
if arr.count(el) % 2 == 0:
arr = [x for x in arr if x != el]
if len(arr) > 0:
return True
else:
return False
def powers_of_two_remain(numbers):
arr = []
return remove_nums(break_up_nums(numbers, arr))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Людмил Делчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Людмил Делчев
def is_power_of_two(number):
return number != 0 and ((number & (number - 1)) == 0)
def represent_as_sum(number):
sum_elements = []
sum_element = number
while number > 0:
if is_power_of_two(sum_element) and sum_element <= number:
sum_elements.append(sum_element)
number -= sum_element
sum_element -= 1
return sum_elements
def odd(number):
return number % 2 != 0
def powers_of_two_remain(numbers):
array = []
for number in numbers:
array.extend(represent_as_sum(number))
return any(map(odd, (map(array.count, set(array)))))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Васил Пачеджиев
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Васил Пачеджиев
def to_bin_arr(number):
binary = bin(number)
arr = list(binary)
arr.pop(0)
arr.pop(0)
result = list()
cnt = 0
while cnt < len(arr):
temp = int(arr[len(arr) - cnt - 1]) * 2**cnt
if not temp == 0:
result.append(temp)
cnt += 1
return result
def powers_of_two_remain(numbers):
all_lists = [to_bin_arr(number) for number in numbers]
result = list()
for lst in all_lists:
result.extend(lst)
cnt = 0
while cnt < len(result):
if result.count(result[cnt]) % 2 == 0:
temp = result[cnt]
while temp in result:
result.remove(temp)
cnt += 1
return not len(result) == 0
....F
======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-1hmv4g7/test.py", line 43, in test_two_same_numbers_always_false
    solution.powers_of_two_remain([7, 7])
AssertionError: True is not false

----------------------------------------------------------------------
Ran 5 tests in 0.007s

FAILED (failures=1)
Иван Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Димитров
import math
def get_sum_of_powers_of_two(number):
result = []
while number > 0:
result.append(2 ** math.trunc(math.log2(number)))
number -= 2 ** math.trunc(math.log2(number))
return result
def is_evenly_encountered(numbers, number):
count = 0
for current in numbers:
if current == number:
count += 1
if count % 2 == 0 and count != 0:
return True
else:
return False
def powers_of_two_remain(numbers):
powers_of_two = []
for current_number in numbers:
powers_of_two.extend(get_sum_of_powers_of_two(current_number))
remaining = []
for current_number in powers_of_two:
if not is_evenly_encountered(powers_of_two, current_number):
remaining.append(current_number)
if not remaining:
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Цветомир Цанов
  • Некоректно
  • 1 успешни тест(а)
  • 4 неуспешни тест(а)
Цветомир Цанов
def powers_of_two_remain(numbers):
pow_of_two = 1
my_list = []
for number in numbers:
while number != 0:
if pow_of_two < number:
pow_of_two *= 2
elif pow_of_two > number:
pow_of_two /= 2
number -= pow_of_two
my_list.append(pow_of_two)
elif pow_of_two == number:
number -= pow_of_two
my_list.append(pow_of_two)
pow_of_two = 1
F.FFF
======================================================================
FAIL: test_dont_break_down_power_of_two_numbers (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150321-24164-vyjq31/test.py", line 35, in test_dont_break_down_power_of_two_numbers
    solution.powers_of_two_remain([8])
AssertionError: None is not true

======================================================================
FAIL: test_power_of_two_remain_no_numbers_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 56, in thread
    it._stop()
  File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
    assert not lock.locked()
AssertionError

======================================================================
FAIL: test_power_of_two_remain_numbers_do_remain (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 56, in thread
    it._stop()
  File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
    assert not lock.locked()
AssertionError

======================================================================
FAIL: test_two_same_numbers_always_false (test.TestNoNumbersRemain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 56, in thread
    it._stop()
  File "/home/pyfmi/Python-3.4.2/Lib/threading.py", line 990, in _stop
    assert not lock.locked()
AssertionError

----------------------------------------------------------------------
Ran 5 tests in 6.215s

FAILED (failures=4)
Емине Башева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Емине Башева
from collections import Counter
def powers_of_two_remain(numbers):
addends = []
for number in numbers:
while number > 1:
great_number = 2 ** greatest_power(number)
addends.append(great_number)
number = number - great_number
if number == 1:
addends.append(1)
count_items = dict(Counter(addends))
result = [key for key in count_items if count_items[key] % 2]
return result != []
def greatest_power(number):
count = 0
while 2 ** count <= number:
count += 1
return count - 1
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
Галин Ангелов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Галин Ангелов
def list_of_powers(number):
powers = []
k = 1
p = pow(2, k-1)
while p <= number:
powers.append(p)
p = pow(2, k)
k += 1
powers.reverse()
return powers
def power_of_two(number):
lis = []
powers = list_of_powers(number)
for i in powers:
if number - i >= 0:
number -= i
lis.append(i)
return lis
def is_even(number):
if number % 2 == 0:
return True
else:
return False
def remove_reapeted_elements(numbers):
result = list(filter(lambda x: not is_even(numbers.count(x)), numbers))
return result
def powers_of_two_remain(numbers):
result = []
for number in numbers:
result += power_of_two(number)
result = remove_reapeted_elements(result)
if not result:
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.007s

OK
София Петрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
import math
def powers_of_two_remain(numbers):
values = []
for number in numbers:
values += extract_powers_of_two(number)
return [value for value in values if values.count(value) % 2 == 1] != []
def extract_powers_of_two(number):
power = 2 ** int(math.floor(math.log(number, 2)))
if power == number:
return [number]
else:
return [power] + extract_powers_of_two(number - power)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Елица Илиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Елица Илиева
import itertools
def powers_of_two_remain(numbers):
remaining = []
for number in numbers:
remaining.append([
int(value) * 2 ** key
for key, value in enumerate(bin(number)[2:][::-1]) if int(value)])
remaining = list(itertools.chain(*remaining))
return bool(len([num for num in remaining if remaining.count(num) % 2 != 0]))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK
Мартин Филипов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Филипов
def break_number_to_powers(number):
binary_number = bin(number)
digits = list(binary_number[2:])
highest_power = len(digits) - 1
result = []
for digit in digits:
if digit == '1':
result.append(2 ** highest_power)
highest_power -= 1
return result
def powers_of_two_remain(numbers):
broken_down_powers = []
for number in numbers:
broken_down_powers.extend(break_number_to_powers(number))
for number in broken_down_powers:
if broken_down_powers.count(number) % 2 == 0:
broken_down_powers = [x for x in broken_down_powers if x != number]
if not broken_down_powers:
return False
else:
return True
.....
----------------------------------------------------------------------
Ran 5 tests in 0.006s

OK