Avatar ·

Split a number into a list of digits

📁 список, помощь, пример, ии

From the user, using the input function, I receive a six-digit number.

After that, I need to split it into 6 separate numbers, for example, into a list.

How can this be achieved?

For example, the number 123456 should be split into 1, 2, 3, 4, 5, 6

Avatar ·

I will post the code suggested by @Harry in C++, translated by me into Python to preserve the "theme" of the language on the page. The solution belongs to him. Anyway - as always, the language decides, but the brain does Ж-)

import numpy as np
from math import sqrt
MAXSIZE = 1000000000
m = np.zeros(MAXSIZE+1, dtype=np.int16)
def f(x, level=0, curmin = MAXSIZE) -> int: 
    if level > curmin: return -1 # Pruning - no point in going deeper                                

Log in to leave an answer

Blogs