Closed larwal6312 closed 7 years ago
separate, v. means "distinguish from others".
Your two outputs have an extra separator at the end, but there is no following element to be separated.
I think that current solution wording as good and your solutions should not be valid.
It says "Print the numbers 1 to 100 separated by spaces."
The correct description would be "Print the numbers 1 to 100 separated by spaces, terminated by a newline character" - If you read K&R2 or any other programming text, specificity is paramount and most exercises are written in that manner.
Note also, no additional end-of-line whitespace is permitted. That's fine, I can live with that.
But, if it's going to fail based on an undocumented requirement, I would disagree that the wording is good.
Additionally, if we really want to get totally pedantic, I would argue that asking for numbers separated by spaces and accepting any solution including a newline character is incorrect. Why? If it can fail for trailing white space then it should also fail for the trailing newline character you didn't ask for. If you reject answers based on additional data, then reject all additional data or none of it. Go big or go home.
Examples: So:
seq 100 | tr "\n" " " # trailing 0x20, no trailing 0x0a
...is rejected but:
{ seq 100 | tr "\n" " " ; echo; } | sed -e "s/ $//g"
...is fine
And:
echo {1..100} " " # trailing 0x20 0x20
...is rejected but:
echo {1..100} " " | sed -e "s/ $//g
...is fine
And:
seq -s " " 100 | head -c 291 # no trailing 0x0a
...also rejected and of course:
seq -s " " 100
... is the "correct" answer.
I think this challenge is clear enough on where the spaces should go, but I could agree that on single-line solutions the final newline should not be taken into account.
It can be easily tested at https://cmdchallenge.com/#/hello_world
echo -n hello world
and echo hello world
should both be accepted.
Closing as a dupe, thanks for assist @0ki 👍
Note: if you are having trouble with a challenge you can see solutions here -> https://github.com/jarv/cmdchallenge/blob/master/challenges.yaml Search for the challenge and look for the
example:
to see one way of doing it.If you would like to help improve the wording of a challenge description, please consider sending a pull request against https://github.com/jarv/cmdchallenge/blob/master/challenges.yaml
Summary
Print the numbers 1 to 100 separated by spaces is not accepting all possible answers.
Steps to reproduce
https://cmdchallenge.com/?utm_source=nixcraft#/print_number_sequence
These should be valid answers.
bash(0)> printf "%d " {1..100} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6 3 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
bash(0)> echo {1..100} " " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6 3 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100