in reply to Re^4: hackerrank.com question
in thread hackerrank.com question

Per what choroba said (perhaps privately) regarding the source document, I did a hexdump of the source document, and found that vi was appending, but not presenting, a newline in that data set.

If I explicitly added a newline, there were two terminal newline characters in hexdump.

Mystery solved, sort of, but that looks like a bug in vim. I always trusted it before.

Replies are listed 'Best First'.
Re^6: hackerrank.com question
by writch (Sexton) on Sep 27, 2018 at 16:25 UTC
    Not a bug, but a 'feature'. Apparently, vim automatically appends every line with CR/LF characters per whatever file mode is set. The suggested path to fixing this is to use the ':set binary' command in conjunction with ':%!xxd' and ':%!xxd -r' to remove this extra character.
      Other than that, the way to resolve this is to use echo -n '<stuff>' > filename.

      That gives results like pasting with no explicit newline at the end used to in vi, and it's much less work.