# Counting Newlines [duplicate]

Possible Duplicate:
Line break formats and character numbers

Do we count newlines in ? I know newlines are almost redundant in , but imagine it's a language requirement.

How many characters does a newline take? CRLF (2) like in Windows? Or simply LF (1)?

## 2 Answers

If it's a language requirement, then see if your language allows bare LFs. If so, it's one byte. If your language requires CRLF (I think batch files do? Haven't checked), then you have to include both.

Remember, the principle is that you have to make the smallest valid program that does the task. The same principle governs how much whitespace needs to be counted: as little whitespace as is required to make the program valid and behave according to spec.

(Some people make bogus rules like "whitespace characters don't count towards the code size"; for such contests, any submission in Whitespace is guaranteed to be shortest.)

In some languages they work just like whitespace, so you could replace all the spaces with newlines. As far as I know they are usually counted

• It is worth noting that Georges' script attempts to understand which newlines are necessary (counted) and which are simply to keep the blocks from needed endless scrolling (uncounted). May 3, 2011 at 2:13
• @dmckee is this a dupe per Joey's comment on the question, or not? May 5, 2011 at 8:07