Created
December 16, 2021 19:43
-
-
Save tombulled/7431650ce91f516837cd9d16c280eb3f to your computer and use it in GitHub Desktop.
Python - Concatenate Numbers of Varying Bases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def join_number(a: int, b: int, base: int) -> int: | |
return a * base ** math.ceil(math.log(b, base)) + b | |
assert join_number(2, 3, 10) == 23 | |
assert join_number(4, 64, 10) == 464 | |
assert join_number(573, 82, 10) == 57382 | |
assert join_number(0b101, 0b111, 2) == 0b101111 | |
assert join_number(0b1100, 0b100111, 2) == 0b1100100111 | |
assert join_number(0b1010011, 0b1100100, 2) == 0b10100111100100 | |
assert join_number(0xA4, 0xB3, 16) == 0xA4B3 | |
assert join_number(0xFE, 0xDEAD, 16) == 0xFEDEAD | |
assert join_number(0xBEEF48C1, 0xA2E6, 16) == 0xBEEF48C1A2E6 | |
assert join_number(0o3, 0o7, 8) == 0o37 | |
assert join_number(0o3, 0o753, 8) == 0o3753 | |
assert join_number(0o1234567, 0o7216534, 8) == 0o12345677216534 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment