22
\$\begingroup\$

Some types of challenges require submission that produce constant output and, as such, forbid the solutions from taking input of any kind.

That presents a problem for languages like sed, which execute code for each line of input, so they downright refuse to do anything if STDIN is empty.

On one hand, if we apply the same rules to all languages, sed simply won't be allowed to compete. On the other hand, excluding a language altogether seems undesirable.

So:

  • Should a language that requires input to do anything be allowed to take input, even if all other languages are not?

  • What should that input be?

  • What should happen in cases like this one, where an exemption from the rule would simplify the task at hand?

\$\endgroup\$
8
  • \$\begingroup\$ Might it be possible to require that the program runs correctly for any single-line input? \$\endgroup\$
    – xnor
    Jun 24, 2015 at 19:59
  • 2
    \$\begingroup\$ This makes me wonder what "no input" means. Does it mean the program has to work the same regardless of what is given on STDIN or does it mean you have to assume STDIN is empty? \$\endgroup\$ Jun 25, 2015 at 21:00
  • \$\begingroup\$ @MartinBüttner: That's a good point.With the first interpretation, I'd have to revise a few GolfScript answers... \$\endgroup\$
    – Dennis
    Jun 25, 2015 at 21:03
  • \$\begingroup\$ that input should be any possible input in order to verify it's not based on input I think. \$\endgroup\$ Sep 4, 2016 at 20:44
  • \$\begingroup\$ @Eʀɪᴋ Current consensus is that programs may assume that input is empty \$\endgroup\$
    – Dennis
    Sep 4, 2016 at 20:55
  • \$\begingroup\$ @Dennis Of course, you can't do that in sed, that's the point of the question! So, different inputs will verify if a submission is actually input-independent. \$\endgroup\$ Sep 4, 2016 at 20:57
  • \$\begingroup\$ @Eʀɪᴋ That contradicts both the consensus reached in this discussion and the one I linked to. If you want to propose something different, make your case in an answer. \$\endgroup\$
    – Dennis
    Sep 4, 2016 at 21:01
  • \$\begingroup\$ @Dennis Unfortunately, it's nighttime where I am, so I'm not in mood of changing consensuses. \$\endgroup\$ Sep 4, 2016 at 21:14

1 Answer 1

21
\$\begingroup\$

Yes, as long as the exact input for this language is proposed before the question

Because this is basically the same as inventing a dialect of the original language.

For sed, I propose an empty line. And the interpreter in bash is:

#!/bin/bash
echo|sed "$@"

Or a more complex one:

#!/bin/bash
if ! [ -t 0 ] || [ "$(head -c1|tee /dev/fd/3|wc -c)" = 0 ]; then echo; else cat; fi 3>&1|sed "$@"

I consider these non-standard sed language interpreters, instead of a new language.

(If you agree with me, the sed variant doesn't need to be the consensus to be valid. If you don't, you can propose this sed variant again in another answer. So don't vote for the above code.)

\$\endgroup\$
8
  • \$\begingroup\$ I am unclear on the definition of "purpose" you're using here. \$\endgroup\$
    – Sparr
    Jun 24, 2015 at 17:21
  • \$\begingroup\$ @Sparr Sorry for my bad English... \$\endgroup\$
    – jimmy23013
    Jun 24, 2015 at 17:25
  • \$\begingroup\$ Upvoted for the idea. Another alternative could be an interpreter such as [ -t 0 ] && echo || cat | sed "$@", which wouldn't require any input at all, not even an empty one. \$\endgroup\$
    – Dennis
    Jun 24, 2015 at 17:33
  • \$\begingroup\$ @Dennis Edited into my second version. \$\endgroup\$
    – jimmy23013
    Jun 24, 2015 at 17:38
  • \$\begingroup\$ I agree with the "empty input" suggestion. \$\endgroup\$ Jun 29, 2015 at 15:44
  • \$\begingroup\$ Another way to start it is sed -f script_file <<< "", which I use on both "no input" rule challenges (given this exempt) and on those stating that the code must be a complete program, showing how to run it straight forward, without the need of echo. \$\endgroup\$
    – seshoumara
    Sep 1, 2016 at 15:49
  • \$\begingroup\$ @seshoumara That's not an empty input - it's an input of a newline. sed -f script_file < /dev/null or echo -n | sed -f script_file are better alternatives because both are truly empty inputs - no newlines. \$\endgroup\$
    – user45941
    Sep 1, 2016 at 21:08
  • \$\begingroup\$ @Mego I didn't say sed receives an empty input, I said I use it for those types of challenges based on this exempt discussed here. My snippet is actually equivalent to echo|sed as accepted in this answer. If the input was truly empty a sed code wont execute, the topic discusses what an input should be that can be used in no input challenges. \$\endgroup\$
    – seshoumara
    Sep 1, 2016 at 21:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .