37
7
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 code-golf, so the shortest code in bytes wins!
6I accept the challenge! In fact, I'm going to do this in Java! – Ashwin Gupta – 2016-02-04T00:41:33.570
Can I write a function or does it have to be a full program? – Ashwin Gupta – 2016-02-04T00:42:25.460
3I'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. – Ray Toal – 2016-02-04T03:40:50.2471Great! Thank you Ray! – Ashwin Gupta – 2016-02-04T04:01:19.397
It's not anywhere near small enough, but I think this a perfect place to share my
– Octavia Togami – 2016-02-04T04:57:00.403n
-tuple generator I wrote in Java: https://github.com/kenzierocks/Tuplocity. It generates fully generic tuples!Unfortunately, this cannot be considered valid Java code, due to Java's (somewhat annoying) restriction that each class be declared in its own file. Unless they're nested inner-classes, I suppose, but that severely limits the usefulness of this sort of construction... – Darrel Hoffman – 2016-02-04T15:41:50.670
The code in the question compiles fine for me. Java allows multiple top-level classes per file but only one public top-level class. BTW, the generated Java code is not intended to be useful at all; it was taken from a tweet on a parody account. But the code does compile---try it. :) – Ray Toal – 2016-02-04T15:58:38.053
Be sure to edit the question to indicate that functions are allowed! – Blacklight Shining – 2016-02-05T13:54:18.583
I can do this, but can you tell me what is customary here please? (1) A function producing a string that has newlines, (2) a function that writes to stdout as a side effect, or (3) both 1 and 2? – Ray Toal – 2016-02-05T17:16:59.267
Output the same text or the same code? Is it ok to change spacing or adding comments inside of it? – Qwertiy – 2016-05-17T12:31:25.990
That Java isn't perfectly golfed. You can remove the space after TupleX. – Fund Monica's Lawsuit – 2016-05-20T14:20:48.207
The Java code is not supposed to be golfed, The challenge was to write a golfed program to generate the given code. – Ray Toal – 2016-05-20T18:55:42.247