Convert Between Bases
The same number can be written in different ways, such as binary, decimal, or hexadecimal. The function rebase receives a number as a list of digits in from_base and returns the digits of that same number in to_base. Both bases are at least 2, and all input digits are considered valid.
Примеры
Ввод
(2, [1, 0, 1, 0, 1, 0], 10)Вывод
[4, 2]Ввод
(10, [4, 2], 2)Вывод
[1, 0, 1, 0, 1, 0]Ввод
(2, [1, 1, 1, 1, 1, 1, 1, 1], 16)Вывод
[15, 15]Нужно реализовать
def rebase(from_base: int, digits: list[int], to_base: int) -> list[int]:
Теги
mathlists
Connectez-vous pour voir l'historique des soumissions
Se connecterConnectez-vous pour utiliser le Mentor IA
Se connecterVisible tests
1
Input
2, [1,0,1,0,1,0], 10Expected
[4,2]2
Input
10, [4,2], 2Expected
[1,0,1,0,1,0]3
Input
2, [1,1,1,1,1,1,1,1], 16Expected
[15,15]4
Input
16, [15,15], 2Expected
[1,1,1,1,1,1,1,1]5
Input
10, [0], 2Expected
[0]6
Input
97, [3,46,60], 73Expected
[6,10,45]Focus radio
Paused · SomaFM · Fluid