37
\$\begingroup\$

Write a script that writes to standard output, or your language's equivalent, 100 lines of (valid) Java code that begins with:

class Tuple1 {public Object _0;}
class Tuple2 {public Object _0,_1;}
class Tuple3 {public Object _0,_1,_2;}
class Tuple4 {public Object _0,_1,_2,_3;}
class Tuple5 {public Object _0,_1,_2,_3,_4;}
class Tuple6 {public Object _0,_1,_2,_3,_4,_5;}
class Tuple7 {public Object _0,_1,_2,_3,_4,_5,_6;}
class Tuple8 {public Object _0,_1,_2,_3,_4,_5,_6,_7;}
class Tuple9 {public Object _0,_1,_2,_3,_4,_5,_6,_7,_8;}
class Tuple10 {public Object _0,_1,_2,_3,_4,_5,_6,_7,_8,_9;}
class Tuple11 {public Object _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10;}
class Tuple12 {public Object _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11;}

The last line should begin with class Tuple100.

This is , so the shortest code in bytes wins!

\$\endgroup\$
  • 6
    \$\begingroup\$ I accept the challenge! In fact, I'm going to do this in Java! \$\endgroup\$ – Ashwin Gupta Feb 4 '16 at 0:41
  • \$\begingroup\$ Can I write a function or does it have to be a full program? \$\endgroup\$ – Ashwin Gupta Feb 4 '16 at 0:42
  • 3
    \$\begingroup\$ I'm new to the site so asked for a script, but I've been hearing it's customary to allow functions, and that makes a lot of sense for Java, to avoid public static void main(String[] args) so definitely give a function if you like. \$\endgroup\$ – Ray Toal Feb 4 '16 at 3:40
  • 1
    \$\begingroup\$ Great! Thank you Ray! \$\endgroup\$ – Ashwin Gupta Feb 4 '16 at 4:01
  • \$\begingroup\$ It's not anywhere near small enough, but I think this a perfect place to share my n-tuple generator I wrote in Java: github.com/kenzierocks/Tuplocity. It generates fully generic tuples! \$\endgroup\$ – Octavia Togami Feb 4 '16 at 4:57

61 Answers 61

-1
\$\begingroup\$

Java 112 bytes

void p(){String x="_0";for(int i=0;i<100;){out.format("class Tuple %d {public Object %s;}\n",++i,x);x+=",_"+i;}}

Un-golfed

import static java.lang.System.*;

public class I {
public static void main(String[] args){
    I m=new I();
    m.p();
}
    void p(){
    String x="_0";
    for(int i=0;i<100;){
        out.format("class Tuple %d {public Object %s;}\n", ++i, x);
        x+=",_"+i;
    }
}

}

\$\endgroup\$
  • 2
    \$\begingroup\$ You need to import System or use System.out. \$\endgroup\$ – mbomb007 Feb 4 '16 at 21:48

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.