Shortest Code in WolframLang May be Most Inefficient

By Xah Lee. Date: .

Shortest Code in WolframLang May be Most Inefficient

When you go for shortest code, and in WolframLang, you run into a situation that you abandon the clear efficient solution, because abnormal one saves you 2 characters.

For example, say you wanna find the length of a line in input. Normally, you do

StringSplit[input, "/n",2][[1]]//StringLength

The 2 there means, stop once you got 2 lines. Very efficient when you have say a million lines.

But now, if we go for shortest, we do

StringSplit@input[[1]]//StringLength

you drop the "/n" and drop the 2 too. Because, by default, it split by whitespace, including newline char. You save 6 chars. But now, it return a list of million items, from which, you grab the first line. Lol

The thing interesting here is that, if you just code wolfram the normal way, you still get the shortest code, of all langs. However, your shortest code, is not the shortest, among the WolframLang coders.

WolframLang Code Competition