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
PostgreSQLv16

Your code output will appear here

Visible tests
1
Input
2, [1,0,1,0,1,0], 10
Expected[4,2]
2
Input
10, [4,2], 2
Expected[1,0,1,0,1,0]
3
Input
2, [1,1,1,1,1,1,1,1], 16
Expected[15,15]
4
Input
16, [15,15], 2
Expected[1,1,1,1,1,1,1,1]
5
Input
10, [0], 2
Expected[0]
6
Input
97, [3,46,60], 73
Expected[6,10,45]
Focus radio
Paused · SomaFM · Fluid