-6
\$\begingroup\$

This may seem like it's a question for StackOverflow, but I want to make this question into a challenge. Challenges are more fun.

Some introduction:

In iOS programming and game development, I wanted to make some SKLabelNodes (labels in SpriteKit) appear on the screen to represent the year, have them fall down with physics, and then disappear.

The labels would appear as part of an event to say "Happy New Year!", and show the year. The closest I could get was 59 59 59 9. That's not going to work.

Normally, I'd ask StackOverflow, but I want to have a bit of fun with this ordinary programming question.

The challenge:

What I want to do, and what I want you to do, is make each each digit of an inputted integer its own string.

You can output the functions through stdout, printf, NSLog, echo, whatever your heart desires. Your function may, if you don't want to console output each string, return an array of the strings.

Your function, or piece of code, must take an integer in.

Each digit of the integer must be output on its own line.

Other miscellaneous rules:

This is Code Golf. Standard loopholes apply. Shortest code wins. After a week, I'm accepting the shortest answer and declaring that a winner. (heh, "declaring." programming pun.)

Sample Input:

5000

Sample Output:

Through console output:

5
0
0
0

Or as a returned array of strings:

{"5", "0", "0", "0"}

Good luck!

\$\endgroup\$

closed as off-topic by isaacg, xnor, Οurous, Beta Decay, Calvin's Hobbies Jul 23 '15 at 5:34

  • This question does not appear to be about programming puzzles or code golf within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ When you say "must take an integer in", what does that mean if input is via STDIN? STDIN is always a string, effectively. \$\endgroup\$ – isaacg Jul 23 '15 at 5:04
  • \$\begingroup\$ @isaacg if the input is through STDIN in string format, then you have input in string format. That is an exception to the "you must take in an integer" rule, as the STDIN string is an integer as type string. \$\endgroup\$ – DDPWNAGE Jul 23 '15 at 5:06
  • 2
    \$\begingroup\$ I think is too simple a question to be interesting. Many languages can do this by composing a couple of built-ins. \$\endgroup\$ – xnor Jul 23 '15 at 5:07
  • 1
    \$\begingroup\$ @DDPWNAGE Folks here are generally recommend posting challenges to the Sandbox before posting them live, so it might be something to consider for your next challenge. \$\endgroup\$ – Alex A. Jul 23 '15 at 5:11
  • 7
    \$\begingroup\$ I'm voting to close this question as off-topic because it is trivial in most languages. \$\endgroup\$ – isaacg Jul 23 '15 at 5:17
2
\$\begingroup\$

GolfScript, 2 bytes

n*

Try it online.

\$\endgroup\$
  • \$\begingroup\$ Damn, you're good :) \$\endgroup\$ – Beta Decay Jul 23 '15 at 5:18
  • \$\begingroup\$ Accepting this so that way you get the reputation you deserve. Challenge is closing. \$\endgroup\$ – DDPWNAGE Jul 23 '15 at 5:22
1
\$\begingroup\$

Cobra - 28

Anonymous function of the type Action<of dynamic>

do(i)
    for c in'[i]',print c
\$\endgroup\$
1
\$\begingroup\$

Haskell, 4

show

This is an anynonymous function. Usage:

>> show 35
"35"

This is arguable because "35" displays as a string. But, in Haskell, lists of characters are completely identical to strings and displayed as such. For example,

>> ['3','5']
"35"
\$\endgroup\$
  • 4
    \$\begingroup\$ Wow, so I have a 0 bytes CJam anonymous function which does the same.. \$\endgroup\$ – Optimizer Jul 23 '15 at 5:14
  • 2
    \$\begingroup\$ @Optimizer Don't leave me in suspense. What's the function? :-) \$\endgroup\$ – xnor Jul 23 '15 at 5:17
  • \$\begingroup\$ Jokes apart, you have you have to return an array of strings. Not an array of characters. So your function is invalid :) \$\endgroup\$ – Optimizer Jul 23 '15 at 5:19
0
\$\begingroup\$

Julia, 22 bytes

n->split(string(n),"")

This creates an unnamed function that accepts an integer as input and returns an array of strings. string turns the input into a string and split splits it into an array.

\$\endgroup\$
0
\$\begingroup\$

Golfscript, 3 bytes

1/p

Splits the list then prints it

\$\endgroup\$
0
\$\begingroup\$

Pyth, 3 bytes

jbz

or

VzN

This post won't be long enough if this sentence didn't exist.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.