# Number Splitting

## Instructions

Oh no, my numbers have stuck together! Luckily, we can split them apart with code.

Your code should be a function that takes an integer input from stdin or as an argument. You must split the number into single digits, keeping the order and possible duplicates of these digits. The output should be an array and it may be returned from the function or from stdout. Other forms of output may be discussed. The array elements may be a string or number.

## Examples

345 -> [3, 4, 5]
12218 -> [1, 2, 2, 1, 8]


## Scoring

This is code golf, so shortest code wins.

• As you don't have an a negative number in the examples, will the input always be zero or greater? Aug 23 '20 at 0:56
• Please, put your questions in the sandbox before posting them. Your submission is bascially something like this, but with lesser steps. Please check for similiar questions before posting, as well. Aug 23 '20 at 4:47
• Firstly, it is generally discouraged to accept answers here as that discourages further answers. Secondly, even if you decided to accept an answer, you should at least wait for several weeks, which is significantly longer than 1 hour. Thirdly, the JS answer is not the shortest, why accepting it?
– null
Aug 23 '20 at 8:38

# Japt, 1 byte

Trivial challenges get trivial solutions.

ì


Try it

• Trivial challenges meant for noobs like me to try to get into this thing. Aug 22 '20 at 23:31

# Wolfram Language (Mathematica), 13 bytes

IntegerDigits


Try it online!

• A surprising builtin. I'm impressed. Aug 22 '20 at 23:06
• @PinruiHuang I'm impressed too!! how did you think of such an unexpected challenge? Aug 22 '20 at 23:09
• I thought there weren't enough basic challenges on this site and I'm trying to help newbies like me get into golfing. I snatched it from here: adriann.github.io/programming_problems.html Aug 22 '20 at 23:10
• @PinruiHuang are you impressed by my answer then? Aug 22 '20 at 23:13
• Haaaave you met Mathematica?! codegolf.stackexchange.com/a/71680/58974 Aug 23 '20 at 1:11

# JavaScript, 12 bytes

-3 bytes if we can take input as a string.

n=>[...n+""]


Try it online!

• Absolutely destroyed me. Congratulations. Aug 22 '20 at 23:46
• Firstly, it is generally discouraged to accept answers here as that discourages further answers. Secondly, even if you decided to accept an answer, you should at least wait for several weeks, which is significantly longer than 1 hour. It seems ridiculous to accept a 12 byte answer when there's a 4 byte answer posted only a few hours later.
– null
Aug 23 '20 at 8:37

# Retina 0.8.2, 4 bytes

\B
,


Try it online! Explanation: Simply inserts a , between each pair of digits. Alternatively, if a newline-delimited list is acceptable, then for 3 bytes:

!.


Try it online! Explanation: Simply lists each digit separately. Alternatively, to produce the example output, then for 13 bytes:

\B
,
^
[
$]  Try it online! Link includes test cases. Alternatively, this can be done in Retina 1 for 12 bytes: [[|", "]]L.  Try it online! Link includes test cases. # Arn, 1 byte Mmm. I have absolutely no idea how I found this... \  Try it! # Explained  _ The current input (implicit) \ Map/Fold by this: _ The current item of the input, overloaded by \ Thus, Map/Fold yields a list of the items of the input string.  # Arn, 2 bytes <i  Try it! # Explained Unpacked: :!" _ Input indicator (implicit) :! Split by " The empty string " Trailing quote mark (implicit)  • Try it! <- fixed the link for you. I can't believe that works too XD Aug 26 '20 at 16:14 # APL+WIN, 4 bytes Prompts for integer: ⍎¨⍕⎕  Try it online! Courtesy of Dyalog Classic # Assembly (MIPS, SPIM), 106 bytes Outputs the digits space-separated. .data .text main:li$v0,12
syscall
move $a0,$v0
beq $a0,10,e li$v0,11
syscall
li $a0,32 syscall b main e:  Try it online! # Assembly (MIPS, SPIM), 160 bytes This outputs in a format looking like a list of digits. .data .text main:li$a0,91
li $v0,11 syscall l:li$v0,12
syscall
move $a0,$v0
beq $a0,10,e li$v0,11
syscall
li $a0,44 syscall b l e:li$a0,93
li \$v0,11
syscall


Try it online!

# Javascript(ES6), 38 bytes

Just to kick this off.

a=(w)=>{return w.toString().split("")}


## Output:

345 -> ["3", "4", "5"] 12218 -> ["1", "2", "2", "1", "8"]

• Wow I got outgolfed so hard so fast that I am literally confused. Aug 22 '20 at 23:39
• You don't need to count the a= and you can remove the parentheses around the w, the return & the curly braces. Aug 23 '20 at 0:26
• Oh, and split works without and argument and you can cast w to a string with w+"", but you'll need to wrap it in parentheses. Aug 23 '20 at 0:28

# Python 2, 18 bytes

lambda x:list(x)


# Python 3, 21 bytes

lambda x:list(str(x))

• Great. Can you provide examples of output and put a place where we can run it online? Aug 22 '20 at 23:28
• If you're allowed to take input as a string, you can have list for 4 bytes. Aug 23 '20 at 8:21

# Python 3: 28 20 bytes

Try it Online - lambda function

Try it Online - normal function def

Tried it with lambda function (20 bytes) instead of normal function definition

x=lambda n:[*str(n)]


My earlier response with normal def function - 28 bytes

def x(n):*x,=str(n);return x


Calling the function as follows:

print(x(345))
print(x(12218))


Output:

['3', '4', '5']
['1', '2', '2', '1', '8']

• For the lambda function, you are allowed to keep the "x=" part in the header saving 2 bytes: tio.run/##K6gsycjPM/5foWCrEPM/… Aug 23 '20 at 8:47
• Thank You for the tip. I also realized that  is not working in python 3. It is giving me errors. The tips said i could use  as an option. That would reduce 3 more Aug 23 '20 at 15:49

# C (gcc), 36 bytes

Returns a string representation of the integer.

f(i){int*s;asprintf(&s,"%d",i);i=s;}


Try it online!

• We were asked to return a digit array, not a string. Aug 23 '20 at 14:56
• Suggest *s;f(i){ instead of f(i){int*s; Aug 24 '20 at 7:23

# Jelly, 1 byte

Another trivial solution.

D


Try it online!

# Pyth, 3 bytes

jQT


Try it online!

Explanation: Takes the integer input (Q) and converts it into base 10 (T) and returns the individual digits in a list.

# Pyth, 3 bytes

cz1


Try it online!

Unlike the above one, this one takes input as a string and returns an array of the characters of the string. Still 3 bytes. :<)