What's the ugliest line of R code that still parses?

19

6

The goal is to produce a single line of R code that:

  1. Does as little as possible
  2. In as many characters as possible (max of 100 characters)
  3. And is as ugly as possible (where "ugly" can be taken to mean inefficient computational strategies, extraneous characters such as a terminating semicolon, and so forth).

Do your worst, gentlefolk!

Objective criteria for winning

The winning answer will be judged according to the following point scale (the answer with the most points wins):

  • Generate a sequence from 0 to 10 (100 points)
  • In as many characters (N) as possible
    • 0 points if N=100
    • N-100 points if N<100 (i.e. lose a point for every character under 100)
    • 2(100-N) points if N>100 (i.e. lose two points for every character over 100)
  • Using as many negative examples from the R Inferno as possible
    • 6 points per cited example
    • Each example only counts once. This is so because a "heretic imprisoned in [a] flaming tomb" can only be so imprisoned one time. Thus two global assignments in your line of code only net you 6 points.

Ari B. Friedman

Posted 2011-11-29T19:18:18.087

Reputation: 1 013

4FAQ you @dmckee :) the criteria are pretty objective – Tomas – 2013-07-20T13:42:34.400

I have attempted to make the criteria even more explicit. If criteria 3 is still not objective enough, I could eliminate it, although I rather like it. – Ari B. Friedman – 2013-07-21T02:08:16.473

I don't understand the new scoring system at all. Objective 2 is to be as long as possible (subject to max of 100 characters), and you give fewer points for being closer to 100 (and specify points for programs longer than 100??!); objective 3 is to be as ugly as possible, and you give more points for uglier programs. So are points supposed to be good or bad?! – Peter Taylor – 2013-07-21T07:40:17.950

@PeterTaylor Edited to point out that both Objective #2 formulae produce negative points. Points are good: "The answer with the most points wins". – Ari B. Friedman – 2013-07-22T01:24:09.280

Not an objective winning criteria. See the FAQ. – dmckee --- ex-moderator kitten – 2011-11-30T11:25:46.673

Answers

25

72 96 characters.

`c`<-function(...){list(...)[[-1]];}->>`c`;`[`=0;`]`=10;c(c,c)(c,c)(c,invisible)(`[`[]:`]`[])[];

Ugliness:

  • Reusing a standard function name
  • Using symbols as variable names
  • Global assignment
  • Right assignment
  • Self-redefinition of function
  • Unnecessary trailing semicolon(s)
  • Unnecessary sub-scripting numbers
  • Unnecessary quoting of variable name
  • Leaves the workspace in a state which will almost certainly break any subsequent code run

Generates the sequence 0-10 (thanks to Andrie for the idea to do that).

output:

 [1]  0  1  2  3  4  5  6  7  8  9 10

Brian Diggs

Posted 2011-11-29T19:18:18.087

Reputation: 396

Brilliant. Off the top of my head, uglinesses numbers 3,4,5,8,9 are in the Inferno. So that's 96+6*5=126 points by the grading criteria. – Ari B. Friedman – 2013-10-15T15:03:38.003

Brilliant solution. Added one more ugliness + 100 char. Replace all the " with single quotes. Having embedding issues. "<-"("c",function(...){list(...)[[-1]];}->>"c");"["=0;"]"=10;c(c,c)(c,c)(c,invisible)("["[]:"]"[])[] – Vlo – 2014-08-13T17:12:04.843

4That is truly demented. This is the first time I've used that word as a compliment. On the other hand, it is an excellent piece of work for someone to de-obfuscate and learn from a careful critique. Good work. – Iterator – 2011-12-08T18:24:32.150

7

Generate a sequence from 0 to 10.

100 characters

{.=0;for(`~1` in c(1,2,3,4,5,6,7,8,9,10)){.=c(., `~1`,recursive=F)};print(unname(.[drop=T]));rm(.)}
 [1]  0  1  2  3  4  5  6  7  8  9 10

Andrie

Posted 2011-11-29T19:18:18.087

Reputation: 687

5

100 characters: Generate a sequence from 1 to 10.

Note that the numbers 2-10 are NOT in the code... - Bonus points? :-)

Also note that it uses lapply for maximum performance :)

unlist(lapply(LETTERS[-(11:26)],function(x) as.integer(charToRaw(x))-as.integer(charToRaw('A'))+1L))
#[1]  1  2  3  4  5  6  7  8  9 10 

Tommy

Posted 2011-11-29T19:18:18.087

Reputation: 821

2

100 characters

assign("a",1:10);b<<-paste(c(a),collapse=";");unlist(lapply(strsplit(b,";")[[1]],function(c)c[[1]]))

Not sure if lapply on strsplit is a negative example but it sure should be.

Returns as a character:

 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

Tom Kelly

Posted 2011-11-29T19:18:18.087

Reputation: 121

1

I(cumsum(Reduce("sum", replicate(paste0(as.integer(T),as.integer(T)), T), accumulate=1-F) - T >0))

should have slightly less than 100 characters and somehow produce 0:10

baptiste

Posted 2011-11-29T19:18:18.087

Reputation: 11

1I count 98 via nchar, counting spaces. Although on my system replicate can't take a character vector as a length argument. – Ari B. Friedman – 2013-10-15T23:40:25.743