Created
February 4, 2019 12:04
-
-
Save NuarkNoir/64bc4adef093cbe944e6ad24ed5e54b8 to your computer and use it in GitHub Desktop.
Var. 1; Tasks 6, 7
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
def dec_to_base(N, base): | |
if not hasattr(dec_to_base, 'table'): | |
dec_to_base.table = '0123456789ABCDEF' | |
x, y = divmod(N, base) | |
return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y] | |
num = 16**20+2**30-32 | |
base = 4 | |
need_num = 3 | |
convtd = dec_to_base(num, base) | |
print("Num:", num) | |
print("Converted:", convtd) | |
print("SUM:", sum(map(int, convtd))) | |
print("Count of", need_num, ":", sum(map(lambda x: 1 if int(x) == need_num else 0, convtd))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment