17
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ Not an objective winning criteria. See the FAQ. \$\endgroup\$ – dmckee Nov 30 '11 at 11:25
  • 4
    \$\begingroup\$ FAQ you @dmckee :) the criteria are pretty objective \$\endgroup\$ – Tomas Jul 20 '13 at 13:42
  • \$\begingroup\$ 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. \$\endgroup\$ – Ari B. Friedman Jul 21 '13 at 2:08
  • \$\begingroup\$ 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?! \$\endgroup\$ – Peter Taylor Jul 21 '13 at 7:40
  • \$\begingroup\$ @PeterTaylor Edited to point out that both Objective #2 formulae produce negative points. Points are good: "The answer with the most points wins". \$\endgroup\$ – Ari B. Friedman Jul 22 '13 at 1:24
24
\$\begingroup\$

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
\$\endgroup\$
  • 4
    \$\begingroup\$ That 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. \$\endgroup\$ – Iterator Dec 8 '11 at 18:24
  • \$\begingroup\$ 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. \$\endgroup\$ – Ari B. Friedman Oct 15 '13 at 15:03
  • \$\begingroup\$ 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)("["[]:"]"[])[] \$\endgroup\$ – Vlo Aug 13 '14 at 17:12
7
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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 
\$\endgroup\$
2
\$\begingroup\$

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"
\$\endgroup\$
1
\$\begingroup\$
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

\$\endgroup\$
  • 1
    \$\begingroup\$ I count 98 via nchar, counting spaces. Although on my system replicate can't take a character vector as a length argument. \$\endgroup\$ – Ari B. Friedman Oct 15 '13 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.