22
3
As a celebration of good old Notepad, we are going to treat carriage returns and line feeds as what they originally meant, rather than what they are (ab-)used for today.
Given a string consisting of printable ASCII plus line feeds (␊; LF; esc \n
; hex 0A; dec 10) and carriage returns (␍; CR; esc \r
; hex 0D; dec 13), cause Try It Online to show how the printable characters would be positioned if printed on a printer which takes those two control characters literally:
- upon a line feed, continue printing one line further down
- upon a carriage return continue printing from the left edge
- multiple consecutive carriage returns behave like a single carriage return
Due to modern devices having problems with overstriking, a run of one or more of carriage returns will, except for at the beginning of the input, never occur without at least one preceding and/or following line feed. However, two runs of carriage returns may be separated by a single line feed.
Any amount of additional trailing white space is acceptable, both on the right-hand side of any lines and below the entire text, as long as at least the amount of white space given in the input is preserved.
Examples (using \n
and \r
for line feed and carriage return)
Lorem ipsum dolor sit amet,
Lorem ipsum dolor sit amet,
consectetur adipiscing\nelit, sed
consectetur adipiscing
elit, sed
do eiusmod\r\ntempor incididunt\n\n ut labore
do eiusmod
tempor incididunt
ut labore
et dolore\n\rmagna \r\r\naliqua. Ut
(notice the trailing spaces)
et dolore
magna
aliqua. Ut
\nenim ad minim veniam,\n\r quis nostrud
enim ad minim veniam, quis nostrud
\rexercitation\r\n\rullamco laboris\n\r\nnisi ut aliquip ex\n\n\rea commodo consequat.\n\n
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
28Suggested answer: Notepad, 179712 bytes – Nit – 2018-05-09T08:57:37.860
3@Nit :| notepad isn't TC – ASCII-only – 2018-05-09T08:58:04.400
2Shame that TIO doesn't use a proper terminal, otherwise a nice shell winner would be
stty -onlcr;cat
. – Toby Speight – 2018-05-09T11:28:07.243@TobySpeight Then there would be no challenge. – Adám – 2018-05-09T11:30:33.467
1I'm having trouble entering the carriage-return characters into the "input" field of TIO. They just seem to get swallowed up (or converted into newlines) when pasting - is that my browser at fault, or is it TIO? – Toby Speight – 2018-05-09T13:09:07.077
1@TobySpeight You'll probably need to input them as JSON or something similar. You don't need to count any wrapper that handles that bit. – Adám – 2018-05-09T13:12:13.820
In my opinion, just require the output to only contain only printable ASCII and newlines should be OK. – user202729 – 2018-05-09T13:48:56.540
STDERR (i.e. TIO's Debug) is also fine. And if they somehow can be wrapped (e.g. using Bash on TIO) to capture the output, that's fine too (and the wrapper doesn't need to be counted). Otherwise they cannot participate. Sorry. – Adám – 2018-05-09T13:49:36.593
2@Adám Don't prohibit all outputs than TIO. Instead restrict programs to using certain terminal types, or to file output. Or require that output have the necessary spaces preceding text on new lines. – mbomb007 – 2018-05-09T21:46:38.273