-2
\$\begingroup\$

Challenge

Given a positive integer, find the fastest way to iterate over its digits. Bytecode size doesn't matter as much as speed of execution.

Examples

For 6875, the program would output 6 8 7 5.

For 199182, it would output 1 9 9 1 8 2.

For 0, it would output 0.

\$\endgroup\$
5
  • \$\begingroup\$ Welcome to Code Golf! Your first question is OK, however it is way too trivial, and almost all answers will be identical. I don't see any faster solution than the obvious here. I recommend you read How to Ask a Good Question before asking questions and try posting competitive answers too. \$\endgroup\$ Commented Apr 2, 2021 at 16:57
  • 1
    \$\begingroup\$ Hey @Makonede! Happy to close the question. I just wanted to get a taste of CG and I posted the first challenge that crossed my mind. \$\endgroup\$ Commented Apr 2, 2021 at 17:00
  • 4
    \$\begingroup\$ Please note that you'd have to choose either fastest code (fastest runtime speed) or fastest algorithm (smallest asymptotic time complexity). You cannot use both. You probably want the latter but, as pointed out by Makonede, neither makes much sense for this task. \$\endgroup\$ Commented Apr 2, 2021 at 17:02
  • 1
    \$\begingroup\$ How much algorithms are for this? \$\endgroup\$ Commented Apr 2, 2021 at 17:03
  • \$\begingroup\$ Dupe \$\endgroup\$ Commented Apr 2, 2021 at 17:05

1 Answer 1

2
\$\begingroup\$

Python 3, 15 bytes (Courtesy of @Makonede)

print(*input())

Try it online!

Python 3, 24 bytes (~0.03s)

print(' '.join(input()))

Try it online!

Should be compact and fast

PowerShell, 23 bytes

("$args"|% t*y)-join' '

Try it online!

This dosen't deserve seperate answer

answered Apr 2, 2021 at 16:55
\$\endgroup\$
9
  • 1
    \$\begingroup\$ @Makonede thanks! I'll edit later \$\endgroup\$ Commented Apr 2, 2021 at 16:59
  • 1
    \$\begingroup\$ @Makonede how can I calculate execution time \$\endgroup\$ Commented Apr 2, 2021 at 17:02
  • 1
    \$\begingroup\$ Also i am posting all answers in one answers because they are trivial \$\endgroup\$ Commented Apr 2, 2021 at 17:02
  • 2
    \$\begingroup\$ @Makonede its not accurate, maybe Sys. time? \$\endgroup\$ Commented Apr 2, 2021 at 17:03
  • 1
    \$\begingroup\$ I guess, but it's fine, this challenge is probably gonna be closed soon anyway - EDIT: closed \$\endgroup\$ Commented Apr 2, 2021 at 17:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.