Нарцистични числа

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

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

Леко встъпление

Нарцисизъм означава любов към себе си и се свързва с преследването на удовлетворение от суетата или егоистично възхищение на собстевните физически или умствени качества. Произлиза във връзка с Нарцис) от древногръцката митология, който се влюбил във собственото си отражение.

И сега Narcissistic числата ...

Неформално

Числа влюбени в себе си (очевидно).

Формално

Естественото (в рамките на тази задача ще считаме и 0 за естествено) число n се нарича нарцистично, ако изпълнява следното условие:

$$ n = a_k^k + a_{k-1}^k + \ldots + a_2^k + a_1^k $$

Тоест сумата от цифрите на числото, повдигнати на степен броя на цифрите, да е самото число.

Примери

$$ 370_{(10)} = 3^3 + 7^3 + 0^3 = 27 + 343 + 0 = 370_{(10)} $$

$$ 5_{(10)} = 12_{(3)} = 1^2 + 2^2 = 1 + 4 = 5_{(10)} $$

Аналогично стоят нещата и при числа в произволна бройна система.

Да проследим един пример с 223 в 4-ична бройна система:

  1. Представяме числото в десетична бройна система: 223(4) = 43(10)
  2. Сумираме цифрите повдигнати на степен 3(броя на цифрите в 4-ична): $$ 2 ^ 3 + 2 ^ 3 + 3 ^ 3 = 8 + 8 + 27 = 43 $$
  3. Проверяваме дали сумата(43) е равна на числото в 10-ична бройна система(43). Очевидно са равни, следователно 223 в 4-ична е нарцистично.

Ако числото е в 11-ична бройна система, включва цифрата A и се чудите как да повдигнете A на дадена степен, просто повдигнете 10 на тази степен, което е същото, защото A в 11-ична е 10 в 10-ична.

След всичките дефиниции ето и самото условие

Като видни нарцисисти напишете функция предикат is_narcissistic, която, по дадено число и бройна система(2-36), ви помага да разберете дали числото е нарцистично, или не.

base параметърът указва бройната система, в която е number и по подразбиране е 10. number е числото, представено като низ.

Сигнатура

def is_narcissistic(number, base=10)
    ...

Примери

>> is_narcissistic('10')
False
>> is_narcissistic('223', 4)
True
>> is_narcissistic('115132219018763992565095597973971522401')
True

Решения

Йосиф Цветков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Йосиф Цветков
def is_narcissistic(num, base=10):
return (sum([int(i, base) ** len(num) for i in num])) == int(num, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Георги Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димитров
def is_narcissistic(number, base=10):
char_set = '0123456789abcdefghijklmnopqrstuvwxyz'
char_map = {char: digit for digit, char in enumerate(char_set)}
in_base10 = int(number, base)
digit_count = len(number)
sum_of_digits = sum(
char_map[digit.lower()] ** digit_count for digit in number)
return sum_of_digits == in_base10
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Ралица Цанова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Цанова
import math
def is_narcissistic(number, base=10):
value = int(number, base)
return sum(map(lambda x: pow(int(x, base), len(number)), number)) == value
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Драгомир Тунчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Драгомир Тунчев
HIGHER_NUMBERS = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14,
'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19,
'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24,
'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29,
'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34, 'Z': 35}
def convert_to_decimal(number, base):
result, exponent = 0, len(number) - 1
for digit in range(len(number)):
if number[digit] in HIGHER_NUMBERS.keys():
result += (HIGHER_NUMBERS[number[digit]]) * base ** exponent
else:
result += (int(number[digit])) * base ** exponent
exponent -= 1
return result
def is_narcissistic(number, base=10):
number = number.upper()
if list(number)[0] == '-':
return False
elif base is 10:
decimal_number = int(number)
else:
decimal_number = convert_to_decimal(number, base)
result, exponent = 0, len(number)
for digit in range(len(number)):
if number[digit] in HIGHER_NUMBERS.keys():
result += HIGHER_NUMBERS[number[digit]] ** exponent
else:
result += (int(number[digit])) ** exponent
return result == decimal_number
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стефани Цакова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стефани Цакова
def is_narcissistic(number, base=10):
number_digits = len(number)
decimal_number = int(number, base)
return sum([int(digit, base) ** number_digits
for digit in number]) == decimal_number
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Виктор Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Иванов
def value(digit):
digit = ord(digit.lower())
if digit >= ord('0') and digit <= ord('9'):
return digit - ord('0')
return digit - ord('a') + 10
def is_narcissistic(number, base=10):
digits_count = len(number)
digits_sum = 0
for digit in number:
digits_sum += value(digit) ** digits_count
return digits_sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Филип Митов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Филип Митов
def is_narcissistic(number, base=10):
digits_in_base = [int(digit, base) ** len(number) for digit in number]
return int(number, base) == sum(digits_in_base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Иван Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
def transform(letter):
if ord(letter.lower()) in range(ord('a'), ord('z') + 1):
return 10 + ord(letter.lower()) - ord('a')
else:
return int(letter)
def sum_of_digits(number):
return sum([transform(digit)**len(number) for digit in number])
def is_narcissistic(number, base=10):
return sum_of_digits(number) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Георги Шопов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Шопов
def is_narcissistic(number, base=10):
return (sum([int(digit, base) ** len(number) for digit in number]) ==
int(number, base))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Георги Стайков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стайков
def is_narcissistic(num, base=10):
return sum([int(x, base) ** len(num) for x in num]) == int(num, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стоян Цветков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Цветков
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ALPHABET_DICT = {ALPHABET[pos]: pos for pos in range(0, len(ALPHABET))}
def is_narcissistic(number, base=10):
digits = [ALPHABET_DICT[digit] for digit in number[::-1]]
if base != 10:
other_base = digits[:]
for digit in range(0, len(other_base)):
other_base[digit] = other_base[digit] * (base ** digit)
base_ten = sum(other_base)
else:
base_ten = int(number)
raise_num = lambda x: x ** len(digits)
return (sum([num ** len(digits) for num in digits]) == base_ten)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Цветелина Борисова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Цветелина Борисова
HEX_TO_DIGIT = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
def number_to_dec(number, base):
number_in_base = 0
power = len(number) - 1
for digit in number:
if digit in HEX_TO_DIGIT.keys():
digit = HEX_TO_DIGIT[digit]
number_in_base += base**power * int(digit)
power -= 1
return number_in_base
def is_narcissistic(number, base=10):
number = number.upper()
power = len(number)
if base != 10:
number_in_dec = number_to_dec(number, base)
else:
number_in_dec = int(number)
return number_in_dec == sum([int(digit)**power for digit in number])
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-5t0s36/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-5t0s36/solution.py", line 24, in is_narcissistic
    return number_in_dec == sum([int(digit)**power for digit in number])
  File "/tmp/d20140318-21201-5t0s36/solution.py", line 24, in <listcomp>
    return number_in_dec == sum([int(digit)**power for digit in number])
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Данаил Койчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Данаил Койчев
def is_narcissistic(number, base=10):
digits_pow = sum([(int(digit, base) ** len(number)) for digit in number])
return digits_pow == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Гергана Петрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Гергана Петрова
def is_narcissistic(number, base=10):
n = int(number, base)
digits = len(number)
return n == sum(map(lambda x: pow(int(x, base), digits), number))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.021s

OK
Иван Бобев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Бобев
def is_narcissistic(number, base=10):
n = int(number, base)
l = len(number)
return sum(int(digit, base) ** l for digit in number) == n
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Станислав Гатев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Гатев
def is_narcissistic(number, base=10):
powered_digits = [int(digit, base) ** len(number) for digit in number]
return sum(powered_digits) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Никола Ненков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
def is_narcissistic(number, base=10):
return sum(int(digit, base)**len(number) for digit in number) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Димитър Чаушев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Чаушев
numbers = [chr(i) for i in range(48,58)]
def is_narcissistic(number, base=10):
deg = len(number)
ans = 0
for i in number:
if i not in numbers:
i = 10 + (ord(i) - ord('A'))
ans += int(i)**deg
if ans == int(number, base):
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Тихомир Янев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Тихомир Янев
import math
def is_narcissistic(number, base=10):
power = len(number)
return sum(map(lambda y: math.pow(y, power),
[int(x, base) for x in number])) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Елица Илиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Елица Илиева
def is_narcissistic(number, base=10):
dec_number = int(number, base)
digit_count = len(number)
sum_of_digits = 0
for digit in number:
sum_of_digits += int(digit, base) ** digit_count
return sum_of_digits == dec_number
.....
----------------------------------------------------------------------
Ran 5 tests in 0.002s

OK
Стефан Маринов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Маринов
def is_narcissistic(number, base=10):
return int(number, base) == sum([int(digit, base) ** len(number)
for digit in number])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Никола Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Димитров
def is_narcissistic(number, base=10):
base_10 = int(number, base)
length = len(number)
return base_10 == sum([int(digit, base) ** length for digit in number])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Антонио Николов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
import string
def is_narcissistic(number, base=10):
powered_digits = []
for digit in number:
if digit in string.ascii_uppercase:
digit = ord(digit) - 55
powered_digits.append(int(digit)**len(number))
return sum(powered_digits) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Теодор Драганов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Теодор Драганов
def is_narcissistic(number, base=10):
return sum([int(digit)**len(number) \
for digit in number]) == int(number, base)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-r6pegp/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-r6pegp/solution.py", line 3, in is_narcissistic
    for digit in number]) == int(number, base)
  File "/tmp/d20140318-21201-r6pegp/solution.py", line 3, in <listcomp>
    for digit in number]) == int(number, base)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Атанас Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
def is_narcissistic(number, base=10):
length = len(number)
dictionary = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5':5, '6': 6, '7': 7,
'8': 8, '9': 9, 'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14,
'f': 15, 'g': 16, 'h': 17, 'i': 18, 'j': 19, 'k': 20, 'l': 21,
'm': 22, 'n': 23, 'o': 24, 'p': 25, 'q': 26, 'r': 27, 's': 28,
't': 29, 'u': 30, 'v': 31, 'w': 32, 'x': 33, 'y': 34, 'z': 35
}
decimal_value = 0
narcissistic_sum = 0
index_of_power = length - 1
for symbol in number:
decimal_value += dictionary[symbol.lower()] * (base ** index_of_power)
index_of_power = index_of_power - 1
narcissistic_sum += dictionary[symbol.lower()] ** length
return decimal_value == narcissistic_sum
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Евгени Евлогиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Евгени Евлогиев
def is_narcissistic(number, base=10):
number_in_decimal = int(number, base)
sum_of_digits = 0
for symbol in number:
sum_of_digits += int(symbol, base) ** len(number)
return number_in_decimal == sum_of_digits
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Ивайло Дянков
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Ивайло Дянков
def is_narcissistic(number, base=10):
power = number.__len__()
result = 0
for digit in number:
result += int(digit) ** power
return result == int(number, base)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-pnaick/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-pnaick/solution.py", line 5, in is_narcissistic
    result += int(digit) ** power
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Кирил Киров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Кирил Киров
def is_narcissistic(number, base=10):
len_num = len(number)
alone_ints = []
for _ in number.lower():
if _ in '0123456789':
alone_ints.append(int(_) ** len_num)
else:
alone_ints.append(digits[_] ** len_num)
sum_of_ints = sum(alone_ints)
ten_based_number = number
if base != 10:
ten_based_number = str(to_ten(number, base))
return sum_of_ints == int(ten_based_number)
def to_ten(number, base):
num_digits = [i for i in str(number.lower())]
sum_digits = 0
previous_sum = 0
for i in num_digits:
if i in '0123456789':
sum_digits = previous_sum * base + int(i)
previous_sum = sum_digits
else:
sum_digits = previous_sum * base + digits[i]
previous_sum = sum_digits
return sum_digits
digits = {
'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15, 'g': 16, 'h': 17, 'i': 18, 'j': 19,
'k': 20, 'l': 21, 'm': 22, 'n': 23, 'o': 24, 'p': 25, 'q': 26, 'r': 27, 's': 28, 't': 29, 'u': 30,
'v': 31, 'w': 32, 'x': 33, 'y': 34, 'z': 35}
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Денис Бялев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Денис Бялев
def is_narcissistic(number, base=10):
return sum([char_to_int(x) ** len(number)
for x in number]) == to_10_num_system(number, base)
def to_10_num_system(number, base):
if base != 10:
return sum([char_to_int(number[x]) * (base**(len(number)-1 - x))
for x in range(len(number))])
else:
return int(number)
def char_to_int(number):
if number.isdigit():
return int(number)
else:
return ord(number) - ord('A') + 10
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Теодор Халваджиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Халваджиев
def is_narcissistic(number, base=10):
num_base_10 = int(number, base)
cubed = sum([int(digit, base) ** len(number) for digit in str(number)])
return cubed == num_base_10
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Момчил Станчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Момчил Станчев
num_rep = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15, 'g':16, 'h':17, 'i':18, 'j':19,
'k':20, 'l':21, 'm':22, 'n':23, 'o':24, 'p':25, 'q':26, 'r':27, 's':28, 't':29,
'u':30, 'v':31, 'w':32, 'x':33, 'y':34, 'z':35}
def convert_to_dec(number, base):
if base != 10:
decimal_number = 0
power = 0
for digit in reversed(number.lower()):
decimal_number += num_rep[digit] * (base ** power)
power +=1
else:
return number
return str(decimal_number)
def is_narcissistic(number, base=10):
converted_num = convert_to_dec(number, base)
return int(converted_num) == sum([int(num_rep[digit]) ** len(number) for digit in number.lower()])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Димитър Трендафилов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Трендафилов
def is_narcissistic(number, base=10):
sum_of_pow_digits = sum(int(c, 36) ** len(number) for c in number)
return sum_of_pow_digits == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Деян Камбуров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Камбуров
def is_narcissistic(number, base=10):
power = len(number)
sum_digit_squares = sum(int(digit, base) ** power for digit in number)
return sum_digit_squares == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Иван Върбанов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Върбанов
def get_digit_numbers(number):
character_dic = {}
value = 9
for index in range(65, 91):
value += 1
character_dic[chr(index)] = value
digit_numbers = []
for digit in number:
if digit in character_dic:
digit_numbers.append(character_dic[digit])
else:
digit_numbers.append(int(digit))
return digit_numbers
def is_narcissistic(number, base=10):
digit_numbers = get_digit_numbers(number)
sum_of_digits = sum([digit ** len(digit_numbers) for digit in digit_numbers])
if int(number, base) == sum_of_digits:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Мария Кръстева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Кръстева
def power(number):
result = 0
for digit in number:
if digit.isdigit():
result += int(digit) ** len(number)
if digit.isalpha():
result += (ord(digit) - 55) ** len(number)
return result
def is_narcissistic(number, base=10):
return power(number) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Елена Желева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Желева
def is_narcissistic(number, base=10):
length = len(number)
sumproduct = 0
for i in number:
if i.isdigit():
sumproduct += int(i) ** length
else:
sumproduct += (ord(i) - 55) ** length
return sumproduct == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Николай Масларски
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Масларски
def is_narcissistic(number, base=10):
split_number = [int(digit, base) for digit in list(number)]
sum_of_square_digits = 0
number_of_digits = 0
for digit in split_number:
number_of_digits += 1
for digit in split_number:
sum_of_square_digits += digit**number_of_digits
if sum_of_square_digits == int(number, base):
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Васил Тодоров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Тодоров
def is_narcissistic(number, base=10):
sum_of_powers = sum([int(digit, base) ** len(number) for digit in number])
return sum_of_powers == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Елена Димитрова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Елена Димитрова
def get_digit(digit):
if digit >= '0' and digit <= '9':
return ord(digit) - ord('0')
else:
return ord(digit.lower()) - ord('a')
def to_decimal(number, base):
if base == 10:
return number
decimal = 0
power = len(number) - 1
for digit in number:
decimal += get_digit(digit) * (base ** power)
power -= 1
return str(decimal)
def is_narcissistic(number, base=10):
decimal_number = to_decimal(number, base)
power = len(number)
sum_of_digits = 0
for digit in number:
sum_of_digits += get_digit(digit) ** power
return str(sum_of_digits) == decimal_number
..F..
======================================================================
FAIL: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-ja1otk/test.py", line 26, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('C60E7', 16))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (failures=1)
Веляна Димова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Веляна Димова
def is_narcissistic(number, base=10):
result = 0
count_digits = 0
for i in number:
count_digits += 1
for i in number:
if i.isdigit():
result += int(i)**count_digits
else:
result += (ord(i) - 55)**count_digits
return result == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Теодора Добрева
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Теодора Добрева
def is_narcissistic(number, base=10):
sum_base = 0
power = len(number) - 1
for digit in number:
sum_base += int(digit) * base ** power
power -= 1
return sum_base == sum(int(digit) ** len(number) for digit in number)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-i4ih1b/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-i4ih1b/solution.py", line 5, in is_narcissistic
    sum_base += int(digit) * base ** power
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Веселин Генадиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Генадиев
def is_narcissistic(number, base=10):
powered_sum = sum(int(digit, base) ** len(number) for digit in number)
return powered_sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Любослав Павлов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Любослав Павлов
def is_narcissistic(number, base=10):
digits_sum = 0
for i in number:
digits_sum += int(i) ** len(number)
return int(number, base) == digits_sum
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1xii06k/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1xii06k/solution.py", line 4, in is_narcissistic
    digits_sum += int(i) ** len(number)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Ангел Новоселски
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Ангел Новоселски
def sum(a):
b = 0
d=len(a)
c = list(map(int,str(int(a))))
for i in c:
b += pow(i,d)
return b
def is_narcissistic(number, base=10):
b = int(number, base)
return b==sum(number)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-kqcr9l/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-kqcr9l/solution.py", line 12, in is_narcissistic
    return b==sum(number)
  File "/tmp/d20140318-21201-kqcr9l/solution.py", line 4, in sum
    c = list(map(int,str(int(a))))
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Ангел Цанев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Цанев
def is_narcissistic(number, base=10):
size, decimal = len(number), int(number, base)
return decimal == sum([int(char, base)**size for char in number])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Стефан Василев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Василев
def is_narcissistic(number, base=10):
return (sum([int(digit) ** len(number) for digit in number if ord(digit) < 58]) +
sum([(ord(digit) - 55) ** len(number) for digit in number if ord(digit) > 58])) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Герасим Станчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Герасим Станчев
def is_narcissistic(number, base = 10):
if base == 10:
digits = []
for digit in range(len(number)):
digits.append(number[digit:digit+1])
sum = int(number)
for element in digits:
sum -= int(element) ** len(digits)
return sum == 0
else:
all_bases_chars = {}
counter = 0
numbers = [chr(i) for i in range(ord('0'), ord('9') + 1)]
for num in numbers:
all_bases_chars[num] = counter
counter += 1
alphabet = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
for char in alphabet:
all_bases_chars[char] = counter
counter += 1
converted = 0
for digit in number[::-1]:
converted += int(all_bases_chars[digit]) ** len(number)
return converted == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Милица Борисова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Милица Борисова
DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def convert(number, base):
return sum([DIGITS.index(number[i]) * base ** (len(number) - i - 1)
for i in range(len(number))])
def is_narcissistic(number, base=10):
return sum([DIGITS.index(number[i]) ** len(number)
for i in range(len(number))]) == convert(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Пламен Димитров
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Пламен Димитров
def calculate(number):
lenth_number = len(number)
result = 0
for i in number:
result += int(i)**lenth_number
return result
def is_narcissistic(expresion, number=10):
if number != 10:
temp_number = int(expresion,number)
return temp_number == calculate(expresion)
else:
return int(expresion) == calculate(expresion)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-18m3nrl/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-18m3nrl/solution.py", line 12, in is_narcissistic
    return temp_number == calculate(expresion)
  File "/tmp/d20140318-21201-18m3nrl/solution.py", line 5, in calculate
    result += int(i)**lenth_number
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Димитър Желев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Желев
DIGITS_VALUE = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5,
'6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11,
'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16,
'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21,
'M': 22, 'N': 23, 'O': 24, 'I': 25, 'Q': 26,
'R': 27, 'S': 28, 'T': 29, 'U': 30, 'V': 31,
'W': 32, 'X': 33, 'Y': 34, 'Z': 35}
def is_narcissistic(number, base=10):
"""checks if number is nacissistic"""
if get_number_in_base_ten(number, base) == get_number_powered_sum(number):
return True
return False
def get_number_in_base_ten(number, base):
"""returns number in base 10"""
if base == 10:
return int(number)
base_ten_number = 0
power_index = len(number) - 1
for digit in number:
base_ten_number += DIGITS_VALUE[digit.upper()] * (base ** power_index)
power_index -= 1
return base_ten_number
def get_number_powered_sum(number):
"""returns sum of powered digits in number"""
return sum([DIGITS_VALUE[digit.upper()] ** len(number) for digit in number])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Снежана Спасова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Снежана Спасова
def is_narcissistic(number, base = 10):
return int(number, base) == sum(list_of_powered_digits(number, base))
def list_of_powered_digits(number, base):
convert_number = list(map(lambda x: int(x, base), list(number)))
return list(map(lambda x: x**len(number), convert_number))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.094s

OK
Емилиан Станков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def is_narcissistic(number, base=10):
sum_digits_powered = 0
number_in_base_ten = 0
letters_to_numbers = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14,
'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19,
'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24,
'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29,
'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34,
'Z': 35}
if base != 10:
for i in range(len(number) - 1, -1, -1):
__index = number[len(number) - 1 - i]
number_in_base_ten += letters_to_numbers[__index] * (base ** i)
else:
number_in_base_ten = int(number)
for digit in number:
sum_digits_powered += letters_to_numbers[digit] ** len(number)
if sum_digits_powered == number_in_base_ten:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Константин Паенов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Паенов
import string
def is_narcissistic(number, base=10):
digits = len(str(number))
num_ten = 0
if base < 10:
num_base = 0
num_comp = 0
num = list(map(int, str(number)))
for i in range(0, digits):
num_ten = num_ten + num[i] * base**(digits-1-i)
num_base = num_base + num[i]**digits
if num_base == num_ten:
return True
else:
return False
elif base == 10:
num = list(map(int,str(number)))
for i in range(0, digits):
num_ten = num_ten + num[i]**digits
if num_ten == int(number):
return True
else:
return False
elif base > 10:
num = list(number)
alphabet = string.ascii_uppercase
numb_abet = {}
num_base = 0
for i in range(0 , 26):
numb_abet[alphabet[i]] = i + 10
for k in range(0, digits):
if num[k] in numb_abet:
num[k] = numb_abet[num[k]]
else:
num[k] = int(num[k])
for i in range(0,digits):
num_base = num_base + num[i]**digits
num_comp = int(number,base)
if num_base == num_comp:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Димитър Мутафчиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутафчиев
def is_narcissistic(number, base=10):
digits = [i for i in number]
values_digits = [int(i, base) for i in digits]
num_len = len(number)
sum_digits = sum(map(lambda x: x ** num_len, values_digits))
return sum_digits == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стоян Христов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Христов
def is_narcissistic(number, base=10):
in_decimal = int(number, base)
sum_of_digits = sum(int(symbol, base) ** len(number) for symbol in number)
return sum_of_digits == in_decimal
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стоянка Йовкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стоянка Йовкова
def is_narcissistic(number, base=10):
dictionary = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
'G': 16, 'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21, 'M': 22, 'N': 23,
'O': 24, 'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29, 'U': 30, 'V': 31,
'W': 32, 'X': 33, 'Y': 34, 'Z': 35, '0': 0, '1': 1, '2': 2, '3': 3,
'4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
sum_digits = 0
degree = len(number)
for item in list(number.upper()):
for key in dictionary.keys():
if item == key:
sum_digits += dictionary[key] ** degree
new_number = int(number, base)
if new_number == sum_digits:
result = True
else:
result = False
return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Ангел Ангелов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Ангел Ангелов
def from_base(digits, base):
result = 0
while digits:
digit = digits.pop(0)
result += digit * (base ** len(digits))
return result
def is_narcissistic(number, base=10):
digits = [int(digit_chr) for digit_chr in number]
narcissistic_sum = sum([digit ** len(digits) for digit in digits])
return (narcissistic_sum == from_base(digits, base))
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1l7fgy5/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1l7fgy5/solution.py", line 9, in is_narcissistic
    digits = [int(digit_chr) for digit_chr in number]
  File "/tmp/d20140318-21201-1l7fgy5/solution.py", line 9, in <listcomp>
    digits = [int(digit_chr) for digit_chr in number]
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Емануел Стоянов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Емануел Стоянов
def is_narcissistic(number, base=10):
values = {'A': 10, 'B': 11, 'C': 12, 'D': 13,
'E': 14, 'F': 15, 'G': 16, 'H': 17,
'I': 18, 'J': 19, 'K': 20, 'L': 21,
'M': 22, 'N': 23, 'O': 24, 'P': 25,
'Q': 26, 'R': 27, 'S': 28, 'T': 29,
'U': 30, 'V': 31, 'W': 32, 'X': 33,
'Y': 34, 'Z': 35}
number_base_ten = 0
for i in range(len(number)-1, -1, -1):
if number[len(number) - i - 1].isupper():
number_base_ten += values[number[len(number) - i - 1]] * base ** i
else:
number_base_ten += int(number[len(number) - i - 1]) * base ** i
sum_digits = 0
for digit in number:
if digit.isupper():
sum_digits += values[digit] ** len(number)
else:
sum_digits += int(digit) ** len(number)
return sum_digits == number_base_ten
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стоян Ефтимов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Ефтимов
def is_narcissistic(number, base=10):
number_in_decimal = int(number, base)
sum = 0
count_of_digits = len(number)
for digit in number:
sum = sum + int(digit, base)**count_of_digits
return sum == number_in_decimal
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Мартин Георгиев
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Мартин Георгиев
def num_digits( n ):
if n < 10:
return 1
return num_digits( n // 10 ) + 1
def sum( n , k ):
if n == 0:
return 0
return ( n % 10 ) ** k + sum( n // 10 , k )
def is_narcissistic( number , base=10 ):
base10 = int( number , base )
digits = num_digits( int( number ) )
if base10 == sum( int( number ) , digits ):
return True
return False
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1hbk4y7/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1hbk4y7/solution.py", line 14, in is_narcissistic
    digits = num_digits( int( number ) )
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Лъчезар Николов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Лъчезар Николов
def is_narcissistic(n, b=10):
p = len(str(n))
return int(n, b) == sum([digit_value(d)**p for d in n.lower()])
def digit_value(digit):
if digit >= '0' and digit <= '9':
return int(digit)
else:
return ord(digit) - ord('a') + 10
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Йордан Дикманов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Йордан Дикманов
def is_narcissistic(number, base=10):
return sum([(int(i)**len(number))
for i in number]) == int(number, base)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1d39y3s/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1d39y3s/solution.py", line 3, in is_narcissistic
    for i in number]) == int(number, base)
  File "/tmp/d20140318-21201-1d39y3s/solution.py", line 3, in <listcomp>
    for i in number]) == int(number, base)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Венцислав Велков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Велков
def is_narcissistic(number, base=10):
sum_of_digits = 0
number_of_digits = len(str(number))
for digit in str(number):
sum_of_digits += int(digit, base) ** number_of_digits
return sum_of_digits == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Александър Златков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Златков
def reverse_string(str):
return str[::-1]
def digit_value(digit):
value = ord(digit)
if value >= ord('0') and value <= ord('9'):
return value - ord('0')
else:
return value - ord('A') + 10
def convert_to_decimal(number, base):
number = reverse_string(number)
decimal_number = 0
coefficient = 1
for digit in number:
decimal_number += digit_value(digit)*coefficient
coefficient *= base
return decimal_number
def is_narcissistic(number, base=10):
number_of_digits = len(number)
number_in_decimal = convert_to_decimal(number, base)
sum = 0
for digit in number:
sum += digit_value(digit)**number_of_digits
return sum == number_in_decimal
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Петър Камбуров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Камбуров
def is_narcissistic(number, base=10):
length = len(number)
sum_of_digits = 0
for digit in number:
sum_of_digits += int(digit, base) ** length
return sum_of_digits == (int(number, base))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Велина Дойчева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Велина Дойчева
def is_narcissistic(number, base=10):
narcissus_sum = sum([int(digit, base) ** len(number) for digit in number])
return narcissus_sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Янислав Василев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Янислав Василев
def sum_powers(num, power, base=10):
sum = 0
for digit in num:
digit = int(digit, base)
sum += pow(digit, power)
return sum
def is_narcissistic(num, base=10):
return sum_powers(num, len(num), base) == int(num, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Даяна Маринова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Даяна Маринова
def is_narcissistic(number, base=10):
char_value_to36 = {
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
'G': 16, 'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21,
'M': 22, 'N': 23, 'O': 24, 'P': 25, 'Q': 26, 'R': 27,
'S': 28, 'T': 29, 'U': 30, 'V': 31, 'W': 32, 'X': 33,
'Y': 34, 'Z': 35
}
sum_digits = 0
sum_in10 = 0
array_of_numbers = []
for num in number:
if num in char_value_to36:
num = char_value_to36[num]
int_num = int(num)
array_of_numbers.append(int_num)
sum_digits += int_num ** len(number)
array_of_numbers.reverse()
if base != 10:
for item in range(len(array_of_numbers) - 1, -1, -1):
sum_in10 += array_of_numbers[item] * (base ** item)
if sum_in10 == sum_digits:
return True
else:
return False
if int(number) == sum_digits:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Моника Димитрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Димитрова
def is_narcissistic(number, base=10):
digits = str(number)
sum = 0
for digit in digits:
sum += int(digit, base) ** len(digits)
return sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.154s

OK
Моника Илиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Илиева
LETTERS = {"A": "10", "B": "11",
"C": "12", "D": "13",
"E": "14", "F": "15",
"G": "16", "H": "17",
"I": "18", "J": "19",
"K": "20", "L": "21",
"M": "22", "N": "23",
"O": "24", "P": "25",
"Q": "26", "R": "27",
"S": "28", "T": "29",
"U": "30", "V": "31",
"W": "32", "X": "33",
"Y": "34", "Z": "35"
}
def to_digit(number):
return list(int(digit) for digit in str(number))
def with_letters(number):
return [item for item in ' '.join(number) if item.isalpha()]
def calculate(numbers, base):
sum_of_numbers = 0
pow_ = 0
for number in numbers:
sum_of_numbers += (int(number) * (base ** pow_))
pow_ += 1
return sum_of_numbers
def to_numbers(letters):
letters_to_numbers = []
for item in letters.split():
letters_to_numbers.append(LETTERS.get(item.upper(), item))
return letters_to_numbers
def to_base_10(number, base):
if with_letters(number):
all_items = ' '.join(digit for digit in number)
with_numbers = to_numbers(all_items)
reversed_numbers = reversed(with_numbers)
return calculate(reversed_numbers, base)
else:
reversed_numbers = list(reversed(to_digit(int(number))))
return calculate(reversed_numbers, base)
def is_narcissistic(number, base=10):
if base != 10:
number_to_base_10 = to_base_10(number, base)
with_numbers = to_numbers(' '.join(num for num in number))
pow_ = len(with_numbers)
sum_of_numbers = sum([int(number) ** pow_
for number in with_numbers])
return number_to_base_10 == sum_of_numbers
else:
pow_ = len(list(to_digit(number)))
sum_of_digits = sum([digit ** pow_ for digit in to_digit(number)])
return int(number) == sum_of_digits
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Любомир Коев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Коев
def is_narcissistic(number, base=10):
return int(number, base) == sum(
[int(digit, base) ** len(number) for digit in number]
)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.098s

OK
Мария Кърчева
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Мария Кърчева
def char_to_10(char):
return '0123456789abcdefghijklmnopqrstuvwxyz'.index(char)
def is_narcissistic(number_string, base=10):
number = int(number_string, base)
k = len(number_string)
return number == sum([(char_to_10(digit))** k for digit in number_string])
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1p6bbve/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1p6bbve/solution.py", line 7, in is_narcissistic
    return number == sum([(char_to_10(digit))** k for digit in number_string])
  File "/tmp/d20140318-21201-1p6bbve/solution.py", line 7, in <listcomp>
    return number == sum([(char_to_10(digit))** k for digit in number_string])
  File "/tmp/d20140318-21201-1p6bbve/solution.py", line 2, in char_to_10
    return '0123456789abcdefghijklmnopqrstuvwxyz'.index(char)
ValueError: substring not found

----------------------------------------------------------------------
Ran 5 tests in 0.005s

FAILED (errors=1)
Божидар Карааргиров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Карааргиров
def is_narcissistic(number, base=10):
return int(number, base) == sum([int(x, base) ** len(number) for x in number])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.114s

OK
Аделина Рудова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Аделина Рудова
def is_narcissistic(number, base=10):
return (sum([int(digit, base) ** len(number) for digit in number])
== int(number, base))
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Божидар Михайлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
def is_narcissistic(number, base=10):
def char_to_int(c):
return int(c) if c.isdigit() else 10 + ord(c) - ord('a')
digit_list = [char_to_int(c) for c in reversed(number.lower())]
in_base_10 = sum(d * base**p for p, d in enumerate(digit_list))
return in_base_10 == sum(digit**len(number) for digit in digit_list)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Христо Петков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Петков
def is_narcissistic(number, base=10):
sum_numbers = 0
len_number = len(number)
for i in number:
sum_numbers += int(i, base) ** len_number
return sum_numbers == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Милен Христов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Милен Христов
def is_narcissistic(number, base=10):
based_digits = str(int(number))
digits_sum = sum([int(digit)**len(based_digits) for digit in based_digits])
if int(digits_sum) == int(number, base):
return True
return False
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-12akiuu/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-12akiuu/solution.py", line 2, in is_narcissistic
    based_digits = str(int(number))
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Александър Чешмеджиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Чешмеджиев
def is_narcissistic(number, base=10):
letter_to_number = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
'G': 16, 'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21,
'M': 22, 'N': 23, 'O': 24, 'P': 25, 'Q': 26, 'R': 27,
'S': 28, 'T': 29, 'U': 30, 'V': 31, 'W': 32, 'X': 33,
'Y': 34, 'Z': 35}
sum_in_decimal = 0
sum_by_power = 0
n = len(number) - 1
for digit in number:
if ord(digit) > 57:
sum_by_power += letter_to_number[digit] ** len(number)
sum_in_decimal += letter_to_number[digit] * (base ** n)
n -= 1
else:
sum_by_power += int(digit) ** len(number)
sum_in_decimal += int(digit) * (base ** n)
n -= 1
if sum_in_decimal == sum_by_power:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Иван Латунов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Латунов
def is_narcissistic(number, base=10):
number_array = list(number)
base_sum = 0
power = len(number_array)
for i in number_array:
base_sum += int(i, base) ** power
return base_sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Георги Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Георгиев
import string
SYMBOLS = string.digits + string.ascii_uppercase
SYMBOLS_TO_NUMBERS = {symbol: number
for symbol, number
in zip(SYMBOLS, range(36))}
def decimal(number, base):
numbers = [SYMBOLS_TO_NUMBERS[symbol] for symbol in number]
numbers_powers = zip(list(reversed(numbers)), range(len(numbers)))
return sum([number * pow(base, power) for number, power in numbers_powers])
def is_narcissistic(number, base=10):
decimal_number = decimal(number, base)
numbers = [pow(SYMBOLS_TO_NUMBERS[symbol], len(number))
for symbol in number]
return sum(numbers) == decimal_number
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Дамян Манев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Дамян Манев
def is_narcissistic(number, base=10):
sum_of_digits = sum([int(x, base)**len(number) for x in number])
return sum_of_digits == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Мария Донева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Донева
alphabet = {chr(65 + i - 10): i for i in range(10, 36)}
def convert_to_decimal(number, base=10):
reversed_number = number[::-1]
index = 1
num = 0
for digit in reversed_number:
if digit in alphabet:
digit = alphabet[digit]
num += int(digit)*index
index *= base
return num
def narcissistic_sum(number):
length = len(number)
sum = 0
for digit in number:
if digit in alphabet:
digit = alphabet[digit]
sum += int(digit)**length
return sum
def is_narcissistic(number, base=10):
return narcissistic_sum(number) == convert_to_decimal(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Стефан Колчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Колчев
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def convert_to_base_ten(number, base):
number_to_base_ten = 0
power = len(number) - 1
for digit in number:
if digit.isdigit():
number_to_base_ten += base**power * (int(digit))
power -= 1
else:
letter = letters.index(digit) + 10
number_to_base_ten += base**power * (letter)
power -= 1
return number_to_base_ten
def is_narcissistic(number, base=10):
sum_of_digits = 0
number_of_digits = len(number)
for digit in number:
if digit.isdigit():
sum_of_digits += int(digit)**number_of_digits
else:
letter = letters.index(digit) + 10
sum_of_digits += letter**number_of_digits
return sum_of_digits == convert_to_base_ten(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Таня Христова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Таня Христова
def convert_to_base_ten(number, base):
all_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
number = str(number)
base = int(base)
converted_sums = []
for i in range(len(number)):
digit = all_digits.index(number[i])
position_in_number = len(number) - 1 - i
converted_sums.append(digit * (base ** position_in_number))
return sum(converted_sums)
def is_narcissistic(number, base=10):
base_ten_number = convert_to_base_ten(number, base)
number = str(number)
narcissistic_candidate = 0
for digit in number:
narcissistic_candidate += int(digit) ** len(number)
return narcissistic_candidate == base_ten_number
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1ixr1wz/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1ixr1wz/solution.py", line 18, in is_narcissistic
    narcissistic_candidate += int(digit) ** len(number)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Ирина Иванова
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Ирина Иванова
def is_narcissistic(number, base=10):
return sum(int(x) ** len(number) for x in number) == int(number, base)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-177xzhz/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-177xzhz/solution.py", line 2, in is_narcissistic
    return sum(int(x) ** len(number) for x in number) == int(number, base)
  File "/tmp/d20140318-21201-177xzhz/solution.py", line 2, in <genexpr>
    return sum(int(x) ** len(number) for x in number) == int(number, base)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Йончо Йончев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Йончо Йончев
def is_narcissistic(num, base=10):
a = sum([int(el, base) ** len(str(num)) for el in str(num)])
return a == int(str(num), base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Петър Парушев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Парушев
def is_narcissistic(number, base=10):
sum_of_squares = 0
length_of_number = number.__len__()
for current_digit in number:
sum_of_squares += int(current_digit, base) ** length_of_number
return int(number, base) == sum_of_squares
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Спасимир Тупаров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Спасимир Тупаров
NUMBER_SYSTEM_ALPHABET = {chr(65+i): i+10 for i in range(26)}
def transform_to_decimal(number, base):
lenth_numb = len(number)
result_decimal = 0
index_symbol = lenth_numb
for degree in range(lenth_numb):
index_symbol -= 1
if number[index_symbol] in NUMBER_SYSTEM_ALPHABET:
result_decimal += NUMBER_SYSTEM_ALPHABET[number[index_symbol]] \
* base**degree
else:
result_decimal += int(number[index_symbol]) * base**degree
return result_decimal
def is_narcissistic(number, base=10):
number = number.upper()
digit_numbers = len(number)
power_to_number = digit_numbers
if base != 10:
decimal_narcissistic = transform_to_decimal(number, base)
else:
decimal_narcissistic = int(number)
is_n = 0
for counter in range(digit_numbers):
if number[counter] in NUMBER_SYSTEM_ALPHABET:
is_n += NUMBER_SYSTEM_ALPHABET[number[counter]]**power_to_number
else:
is_n += int(number[counter])**power_to_number
return is_n == decimal_narcissistic
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Цветислав Викторов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветислав Викторов
def sum_digits_pow(number, k, br_syst):
numbers = []
sums = 0
for digit in number:
sums = sums + int(digit,br_syst) ** k
return sums
def is_narcissistic(number,base=10):
return int(number,base) == sum_digits_pow(number,len(number),base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Михаил Станин
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Михаил Станин
def toDigits(number, base):
digits = []
while number > 0:
digits.insert(0, number % base)
number = number // base
return digits
def fromDigits(digits, base):
number = 0
for digit in digits:
number = base * number + digit
return number
def convertNumber(digits, b, c):
return toDigits(fromDigits(digits, b), c)
def is_narcissistic(number, base=10):
if number == '0':
return True
converted_number = convertNumber([int(c) for c in number], base, 10)
num = sum([int(c) ** len(number) for c in number])
return str(num) == ''.join(str(e) for e in converted_number)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-4ahl76/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-4ahl76/solution.py", line 23, in is_narcissistic
    converted_number = convertNumber([int(c) for c in number], base, 10)
  File "/tmp/d20140318-21201-4ahl76/solution.py", line 23, in <listcomp>
    converted_number = convertNumber([int(c) for c in number], base, 10)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.005s

FAILED (errors=1)
Мариан Ламбовски
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мариан Ламбовски
def is_narcissistic(number, base=10):
decimal_repr = int(number, base)
sum = 0
for digit in number:
sum += int(digit, base)**len(number)
return sum == decimal_repr
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Георги Харизанов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Харизанов
def is_narcissistic(number, base=10):
digits = sum(i ** len(number) for i in [int(j, base) for j in number])
return digits == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Иван Котов
  • Некоректно
  • 0 успешни тест(а)
  • 5 неуспешни тест(а)
Иван Котов
def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])
def is_narcissistic(number, base):
power = len(str(number))
narcissistic_sum = 0
for digits in number:
narcissistic_sum += int(digits) ** power
print (narcissistic_sum)
convert = baseN(int(number), base)
converted_num_sum = 0
convert_power = len(str(convert))
for digits in convert:
converted_num_sum += int(digits) ** convert_power
print (converted_num_sum)
if converted_num_sum == convert:
return True
else:
return False
EEEF
Stdout:
1
1
F
Stdout:
684
243
738
128

======================================================================
ERROR: test_default_base_is_ten (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1gw268a/test.py", line 8, in test_default_base_is_ten
    self.assertTrue(solution.is_narcissistic('153'))
TypeError: is_narcissistic() missing 1 required positional argument: 'base'

======================================================================
ERROR: test_with_numbers_in_base_ten (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1gw268a/test.py", line 11, in test_with_numbers_in_base_ten
    self.assertTrue(solution.is_narcissistic('32164049651'))
TypeError: is_narcissistic() missing 1 required positional argument: 'base'

======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1gw268a/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-1gw268a/solution.py", line 10, in is_narcissistic
    narcissistic_sum += int(digits) ** power
ValueError: invalid literal for int() with base 10: 'A'

======================================================================
FAIL: test_with_numbers_in_lower_bases (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1gw268a/test.py", line 15, in test_with_numbers_in_lower_bases
    self.assertTrue(solution.is_narcissistic('1', 2))
AssertionError: False is not true

Stdout:
1
1

======================================================================
FAIL: test_with_with_numbers_in_higher_bases_with_digits_less_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1gw268a/test.py", line 21, in test_with_with_numbers_in_higher_bases_with_digits_less_than_9
    self.assertTrue(solution.is_narcissistic('192', 23))
AssertionError: False is not true

Stdout:
684
243
738
128

----------------------------------------------------------------------
Ran 5 tests in 0.005s

FAILED (failures=2, errors=3)
Антония Чекръкчиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Антония Чекръкчиева
def get_letter_value(digit):
for number in range(65, 91):
if digit == chr(number):
return number - 55
def is_narcissistic(number, base=10):
digit_sum = 0
for i in number:
if i.isdigit():
digit_sum += int(i) ** len(number)
else:
number_digit = get_letter_value(i)
digit_sum += number_digit ** len(number)
return digit_sum == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Дарина Кръстева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Дарина Кръстева
def is_narcissistic(number, base=10):
powed_digits_of_number = [int(digit, base) ** len(number) for digit in number]
return sum(powed_digits_of_number) == int(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Георги Йорданов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Йорданов
DIGITS = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8,
'9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16,
'H': 17, 'I': 18, 'G': 19, 'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24,
'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T': 29, 'U': 30, 'V': 31, 'W': 32,
'X': 33, 'Y': 34, 'Z': 35
}
def turn_to_decimal(number, base):
reversed_number = number[:: -1]
number_to_decimal = 0
for i in range(0, len(reversed_number)):
number_to_decimal += DIGITS[reversed_number[i]] * base**i
return number_to_decimal
def get_powers_sum(number):
return sum([DIGITS[digit.upper()] ** len(number) for digit in number])
def is_narcissistic(number, base=10):
powers_sum = get_powers_sum(number)
if base == 10:
return powers_sum == int(number)
else:
return powers_sum == turn_to_decimal(number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Валентин Петров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Петров
def is_narcissistic(number,base=10):
return sum([int(i,base)**len(number) for i in number]) == int(number,base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Илиян Влахов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Влахов
ALP = {
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15,
'G': 16, 'H': 17, 'I': 18, 'J': 19, 'K': 20, 'L': 21, 'M':22,
'N': 23, 'O': 24, 'P': 25, 'Q': 26, 'R': 27, 'S': 28, 'T':29,
'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34, 'Z': 35
}
def get_deg(number):
degree = len(number)
digit_holder = []
for num in number:
if num in ALP.keys():
digit_holder.append(str(ALP[num]))
else:
digit_holder.append(num)
return sum(int(x) ** degree for x in digit_holder)
def is_narcissistic(number, base=10):
if base == 10 and get_deg(number) == int(number):
return True
elif base != 10 and int(number, base) == get_deg(number):
return int(number, base)
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Ивайло Бъчваров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Бъчваров
def get_digits(number, base):
digits = []
for char in number:
digits.append(int(char, base))
return digits
def is_narcissistic(number, base=10):
digits = get_digits(number, base)
number_to_hex = int(number, base)
sum = 0
for digit in digits:
sum += digit ** len(digits)
return sum == number_to_hex
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Светлозар Йовчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Светлозар Йовчев
def is_narcissistic(number, base=10):
sum_of_raised_digits = 0
for digit_or_letter in range(0,len(number)):
if number[digit_or_letter].isdigit():
sum_of_raised_digits += int(number[digit_or_letter])**len(number)
else:
sum_of_raised_digits += (ord(number[digit_or_letter])-55)**len(number)
converted_number = int(number,base)
if sum_of_raised_digits == converted_number:
return True
else:
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Атанас Пройчев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Пройчев
ALPHABET = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
def get_as_int(digit_as_string):
if digit_as_string.isdigit():
return int(digit_as_string)
else:
return ALPHABET.index(digit_as_string.upper()) + 10
def to_base_10(number, base):
number_in_base_10 = 0
for i in range(len(number)):
number_in_base_10 += get_as_int(number[len(number) - 1 - i]) * base**i
return number_in_base_10
def is_narcissistic(number_as_string, base=10):
number_in_base_10 = to_base_10(number_as_string, base)
power = len(number_as_string)
sum_of_digits = 0
for digit in number_as_string:
sum_of_digits += get_as_int(digit) ** power
return sum_of_digits == number_in_base_10
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Иван Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Иванов
def is_narcissistic(number, base=10):
sum_of_digits = 0
for digit in number:
sum_of_digits += (int(digit, base)) ** len(number)
return (int(number, base)) == sum_of_digits
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Владимир Начев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Начев
def convert_to_decimal(number, base): # number = str, base = int
k = 1
num = 0
length = len(number)
for i in range(length - 1, -1, -1):
if number[i] in "0123456789":
num += (ord(number[i]) - ord('0')) * k
else:
num += (ord(number[i]) - ord('A') + 10) * k
k *= base
return num
def is_narcissistic(number, base=10):
upper_number = number.upper()
num = 0
length = len(upper_number)
for i in range(0, length):
if number[i] in "0123456789":
num += (ord(upper_number[i]) - ord('0')) ** length
else:
num += (ord(upper_number[i]) - ord('A') + 10) ** length
return num == convert_to_decimal(upper_number, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Марио Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Димитров
from functools import reduce
def is_narcissistic(number, base=10):
converted = int(number, base)
number_str = str(number)
numlen = len(number)
sum = reduce(lambda a, b: a + int(b, base)**numlen, number_str, 0)
return sum == converted
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Симеон Цветков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Цветков
def __int__(number, base):
num = 0
index = len(digit) - 1
current_digit
for digit in number:
index -= 1
if digit <= '0' and digit >= '9':
current_digit = int(digit)
elif digit == 'A':
current_digit = 10
elif digit == 'B':
current_digit = 11
elif digit == 'C':
current_digit = 12
elif digit == 'D':
current_digit = 13
elif digit == 'E':
current_digit = 14
elif digit == 'F':
current_digit = 15
elif digit == 'G':
current_digit = 16
elif digit == 'H':
current_digit = 17
elif digit == 'I':
current_digit = 18
elif digit == 'J':
current_digit = 19
elif digit == 'K':
current_digit = 20
elif digit == 'L':
current_digit = 21
elif digit == 'M':
current_digit = 22
elif digit == 'N':
current_digit = 23
elif digit == 'O':
current_digit = 24
elif digit == 'P':
current_digit = 25
elif digit == 'Q':
current_digit = 26
elif digit == 'R':
current_digit = 27
elif digit == 'S':
current_digit = 28
elif digit == 'T':
current_digit = 29
elif digit == 'U':
current_digit = 30
elif digit == 'V':
current_digit = 31
elif digit == 'W':
current_digit = 32
elif digit == 'X':
current_digit = 33
elif digit == 'Y':
current_digit = 34
elif digit == 'Z':
current_digit = 35
num += current_digit * base ** len(index)
return num
def is_narcissistic(number, base=10):
summator = 0
if base >=2 and base <= 36:
num = int(number, base)
size = len(number)
for digit in number:
summator += int(digit, base) ** size
if summator == num:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.057s

OK
Гергана Маврова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Гергана Маврова
def to_base_10(number, base):
to_single_character = list(number)
decimal_number = 0
for position, character in enumerate(reversed(to_single_character)):
to_integer = int(character, base)
decimal_number += to_integer*base**position
return str(decimal_number)
def check_narcissism(number, base):
to_single_character = list(number)
exponential = len(number)
total = 0
for position in to_single_character:
to_integer_2 = int(position, base)
total += to_integer_2**exponential
return str(total)
def is_narcissistic(number, base=10):
if base == 10:
if check_narcissism(number, base) == number:
return True
return False
else:
new_number = to_base_10(number, base)
if check_narcissism(number, base) == new_number:
return True
return False
.....
----------------------------------------------------------------------
Ran 5 tests in 0.003s

OK
Йордан Петров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Петров
def is_narcissistic(number, base=10):
number_string = str(number)
number_of_digits = len(number_string)
digits_squares = []
for digit in number_string:
digits_squares.append(int(digit, base) ** number_of_digits)
return sum(digits_squares) == int(number_string, base)
.....
----------------------------------------------------------------------
Ran 5 tests in 0.004s

OK
Стефан Владков
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Стефан Владков
def convert_to_decimal(number, base):
decimal = 0
power = len(number) - 1
for char_digit in number:
if char_digit < '0' or char_digit > '9':
digit = ord(char_digit) - ord('A') + 10
else:
digit = int(char_digit)
decimal = decimal + digit * (base ** power)
power = power - 1
return decimal
def is_narcissistic(number, base=10):
temp_number = number
if base != 10:
temp_number = str(convert_to_decimal(number, base))
number_length = len(number)
polynomial = 0
for digit in number:
polynomial = polynomial + int(digit) ** number_length
return polynomial == int(temp_number)
..E..
======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-15mqc1r/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-15mqc1r/solution.py", line 20, in is_narcissistic
    polynomial = polynomial + int(digit) ** number_length
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (errors=1)
Александър Михайлов
  • Некоректно
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)
Александър Михайлов
def is_narcissistic(number, base=10):
power = len(number)
result = 0
for figure in range(len(number)):
if ord(number[figure]) >= ord('A') and ord(number[figure]) <= ord('Z'):
result += ord(number[figure]) - ord('7') ** power
else:
result += int(number[figure]) ** power
number_to_decimal = convert_to_dec(number, base)
return result == number_to_decimal
def convert_to_dec(number, base):
power = len(number) - 1
result = 0
for figure in number:
if ord(figure) >= ord('A') and ord(figure) <= ord('Z'):
result += base**power * (ord(figure) - (ord('A') - 10))
power -= 1
else:
result += base**power * int(figure)
power -= 1
return result
..F..
======================================================================
FAIL: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-1hvrpe8/test.py", line 26, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('C60E7', 16))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 5 tests in 0.004s

FAILED (failures=1)
Димитър Димитров
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Димитър Димитров
def convert_to_decimal(num, num_sys):
pow = 0
result = 0
for ch in reversed(num):
result += int(ch)*(num_sys**pow)
pow += 1
return result
def is_narcissistic(num, num_sys):
strn = num
for_check = int(num)
power = len(strn)
sum = 0
for n in strn:
sum += int(n)**power
if num_sys != 10:
for_check = convert_to_decimal(num, num_sys)
if sum == for_check:
return True
else:
return False
EEE..
======================================================================
ERROR: test_default_base_is_ten (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-ag8nm2/test.py", line 8, in test_default_base_is_ten
    self.assertTrue(solution.is_narcissistic('153'))
TypeError: is_narcissistic() missing 1 required positional argument: 'num_sys'

======================================================================
ERROR: test_with_numbers_in_base_ten (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-ag8nm2/test.py", line 11, in test_with_numbers_in_base_ten
    self.assertTrue(solution.is_narcissistic('32164049651'))
TypeError: is_narcissistic() missing 1 required positional argument: 'num_sys'

======================================================================
ERROR: test_with_numbers_in_higher_bases_with_digits_greater_than_9 (test.TestNarcissisticNumbers)
----------------------------------------------------------------------
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/d20140318-21201-ag8nm2/test.py", line 25, in test_with_numbers_in_higher_bases_with_digits_greater_than_9
    self.assertTrue(solution.is_narcissistic('A', 11))
  File "/tmp/d20140318-21201-ag8nm2/solution.py", line 13, in is_narcissistic
    for_check = int(num)
ValueError: invalid literal for int() with base 10: 'A'

----------------------------------------------------------------------
Ran 5 tests in 0.005s

FAILED (errors=3)