\$\begingroup\$
\$\endgroup\$
5
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.
-
\$\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\$Makonede– Makonede2021年04月02日 16:57:33 +00:00Commented 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\$Paul Razvan Berg– Paul Razvan Berg2021年04月02日 17:00:22 +00:00Commented 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\$Arnauld– Arnauld2021年04月02日 17:02:39 +00:00Commented Apr 2, 2021 at 17:02
-
1\$\begingroup\$ How much algorithms are for this? \$\endgroup\$avarice– avarice2021年04月02日 17:03:03 +00:00Commented Apr 2, 2021 at 17:03
-
\$\begingroup\$ Dupe \$\endgroup\$Makonede– Makonede2021年04月02日 17:05:01 +00:00Commented Apr 2, 2021 at 17:05
1 Answer 1
\$\begingroup\$
\$\endgroup\$
9
Python 3, 15 bytes (Courtesy of @Makonede)
print(*input())
Python 3, 24 bytes (~0.03s)
print(' '.join(input()))
Should be compact and fast
PowerShell, 23 bytes
("$args"|% t*y)-join' '
This dosen't deserve seperate answer
answered Apr 2, 2021 at 16:55
avarice
12.5k1 gold badge21 silver badges51 bronze badges
-
1\$\begingroup\$ @Makonede thanks! I'll edit later \$\endgroup\$avarice– avarice2021年04月02日 16:59:42 +00:00Commented Apr 2, 2021 at 16:59
-
1\$\begingroup\$ @Makonede how can I calculate execution time \$\endgroup\$avarice– avarice2021年04月02日 17:02:08 +00:00Commented Apr 2, 2021 at 17:02
-
1\$\begingroup\$ Also i am posting all answers in one answers because they are trivial \$\endgroup\$avarice– avarice2021年04月02日 17:02:23 +00:00Commented Apr 2, 2021 at 17:02
-
2\$\begingroup\$ @Makonede its not accurate, maybe Sys. time? \$\endgroup\$avarice– avarice2021年04月02日 17:03:43 +00:00Commented 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\$Makonede– Makonede2021年04月02日 17:04:15 +00:00Commented Apr 2, 2021 at 17:04
Explore related questions
See similar questions with these tags.