-5
0
Question
Write a program to accept one string on the console only and print back its letters arranged in alphabetical order. The string must only have the following characters:
0123456789abcdefghijklmnopqrstuvwxyz
Rules
The ascending alphabetical order is defined in the given string.
All repeated characters must be printed.
If the string contains characters other than the ones mentioned above, it must display "Invalid input".
This is code-golf, so shortest answer in bytes wins.
Standard loopholes are forbidden.
A null string "" will output "Invalid input".
Your program must be executable and not a function or snippet.
Boilerplate is not required.
Examples
"dragon"--> adgnor
"skoda3ferrari"--> 3aadefikorrrs
"ferret"--> eefrrt
"werewolf92"--> 29eeflorww
"@hog"--> Invalid input
"gTa5"--> Invalid input
" l "--> Invalid input
""--> Invalid input
Edit: The double quotes are given for clarification.
May the force be with you. Good luck!
3Any particular reason for the input being restricted to the console? Why not allow a function taking an argument? – Adám – 2020-01-08T10:15:22.707
What if my function is executable without boilerplate? – Adám – 2020-01-08T10:16:05.553
What is boilerplate? – Riley Jones – 2020-01-08T10:16:30.243
Now your post is self-contradictory: as an argument vs not a function – Adám – 2020-01-08T10:17:00.370
Boilerplate is additional code necessary to actually run one's main code. – Adám – 2020-01-08T10:17:22.567
Input will be restricted to the console. Boilerplate is not required. – Riley Jones – 2020-01-08T10:18:09.097
@a'_' No, unless it has characters outside the set. – Adám – 2020-01-08T10:40:36.147
Suggested additional test cases:
"ABC"
and""
– Adám – 2020-01-08T10:42:07.113Invalid input for "" and also and whitespace – Riley Jones – 2020-01-08T10:44:42.547
2@RileyJones Why is
""
invalid? It has no characters outside the set. – Adám – 2020-01-08T10:46:51.613Just so. No specific reason. – Riley Jones – 2020-01-08T10:47:50.033
@RileyJones Since that is an additional rule which cannot be inferred from the other rules, you should be explicit about it. Do not rely on a test case to specify the challenge. – Adám – 2020-01-08T10:49:55.590
Does "console input" included passing the string as argument? – he77789 – 2020-01-08T11:43:49.547
no, only console input – Riley Jones – 2020-01-08T12:10:38.743
Is the
Invalid input
mandatory to be with titlecasedInvalid
and lowercaseinput
, or isInvalid Input
orinvalid input
orINVALID INPUT
valid as well? Several answers are usingInvalid Input
right now. – Kevin Cruijssen – 2020-01-08T13:31:04.85711Hi! I've downvoted this post as it goes against several site conventions (allowable I/O methods, allowed to be programs or functions, and input parsing) without really providing justification for those decisions (e.g., input parsing as a core component of the challenge). – AdmBorkBork – 2020-01-08T13:32:34.297
2Hi Riley, thank you for your challenge. Please do stick around, and answer a few challenges to get to know the site better. It would be a good idea to post your next challenge to the sandbox (see link at top right of screen) for review before it goes live. @AdmBorkBork I applaud you for explaining the reason for your downvote, and I don't disagree with your reasons. On the other hand I think all of us need to be a bit more welcoming and lenient with new contributors lest they are put off using the site in future. – Level River St – 2020-01-09T20:16:38.420