mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 19:34:18 +01:00
14 lines
349 B
Python
14 lines
349 B
Python
from typing import List
|
|
|
|
|
|
def amount_split(amount: int) -> List[int]:
|
|
"""Given an amount returns a list of amounts returned e.g. 13 is [1, 4, 8]."""
|
|
if amount <= 0:
|
|
return []
|
|
bits_amt = bin(amount)[::-1][:-2]
|
|
rv = []
|
|
for pos, bit in enumerate(bits_amt):
|
|
if bit == "1":
|
|
rv.append(2**pos)
|
|
return rv
|