-5
\$\begingroup\$

ed is the standard text editor on Unix systems. Your goal is to write an ed clone.

Task

Write a program that reads an input stream and for every received end of line character, print ? followed by a end of line character.

  • The communication has to interactive. Means the program needs to output as soon as possible and has to accept more input after that.
  • There are no input lines that are longer than 105 characters + end of line character
  • You can choose which character or sequence you use as end of line character, as long as it does not contain any alphanumerical characters nor the ? character.
  • The program should not output anything else.

Shortest code wins.

Example Python Script

#/usr/bin/env python3

import sys

for line in sys.stdin:
  print("?")
\$\endgroup\$
2
  • 9
    \$\begingroup\$ How is this an ed clone? It doesn't seem to edit files. \$\endgroup\$
    – Wheat Wizard
    Jan 7 at 22:12
  • \$\begingroup\$ @WheatWizard It is a joke. Because ed returns ? for almost every input. \$\endgroup\$ Jan 10 at 11:41
0
\$\begingroup\$

Charcoal, 5 bytes

?WSD⎚

Try it online! Link is to verbose version of code. Explanation:

?

Write a ? to the canvas, but don't print anything yet.

WS

Repeatedly input lines until there is nothing left to input...

... dump the canvas with a trailing newline.

Clear the canvas so that nothing gets output at the end.

\$\endgroup\$
1
  • \$\begingroup\$ I upvoted that for respect. I like your answer. \$\endgroup\$
    – Fmbalbuena
    Jan 8 at 1:01
0
\$\begingroup\$

Perl 5.28.1 (webperl) + -pl, 6 bytes

$_="?"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Ruby + -pl, 5 bytes

$_=??

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Nibbles, 2 bytes

@"?"

That's 4 nibbles at half a byte each in the binary form.

@ is the first line of input but auto maps all lines if there's more input after the first line.

Despite the simplicity of this problem I must thank it for making me make sure Nibbles is properly lazy enough to do interactive IO right. There was an issue in that it adds a newline at termination unless your last character was a newline (to not double print newlines), but that wasn't being done lazy enough and so it wasn't interactive enough to satisfy this question. But I've fixed it in latest commit (you'll need latest unstable version of nibbles).

\$\endgroup\$
-1
\$\begingroup\$

Python 3, 40 27 bytes

for i in open(0):print("?")

Try it online!

-13 thanks to @ovs

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can use open(0) instead of sys.stdin and get rid of the input \$\endgroup\$
    – ovs
    Jan 7 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.