Generate 100 Java Tuple classes

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 , so the shortest code in bytes wins!

Ray Toal

Posted 2016-02-03T07:41:55.143

Reputation: 589

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.247

1Great! 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 n-tuple generator I wrote in Java: https://github.com/kenzierocks/Tuplocity. It generates fully generic tuples!

– Octavia Togami – 2016-02-04T04:57:00.403

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

Answers

8

Jolf, 42 bytes

Do I get bonus points for beating Jelly with the best score ever? Contains unprintables, so you may want to try it online here. I replaced the unprintables with their respective alt index for readability.

‼Μz~1d"Ξ/êί Tuple% {Ξ0î⌂ Ξ2Qμ_ %;}"HRzH",_

Explanation

‼Μz~1d"Ξ/êί Tuple% {Ξ0î⌂ Ξ2Qμ _%;}"HRzH",_
 Μz~1d                                     map the range 1..100 with the following function
      "                                    begin a string
       Ξ/êί                                short for "class"
            Tuple% {               H       string interpolate H (current number)
                    Ξ0î⌂ Ξ2Qμ              short for "public Object"
                              _%;}" RzH    string interpolate with a range from 1..H joined
                                       ",_  by the string ",_" (auto-closed quotes)

Conor O'Brien

Posted 2016-02-03T07:41:55.143

Reputation: 36 228

1I suppose. Is it proper on this site to change the accepted answer if a new score comes in later? – Ray Toal – 2016-03-22T06:12:08.000

6@RayToal Yes, it is proper and even suggested to do so. – Conor O'Brien – 2016-03-22T18:50:32.387

What's the character encoding for this? I know golfing languages frequently use their own encoding, but I can't see which encoding jolf could be using. I realize this is old. – recursive – 2017-09-25T23:58:09.307

@recursive The greek ISO-8859-7, this one: https://en.wikipedia.org/wiki/ISO/IEC_8859-7

– Conor O'Brien – 2017-09-26T00:00:44.513

23

vim 56 54 keystrokes

iclass Tuple1 {public Object _0;}<esc>qyYp<C-a>$y2bPr,<C-a>q98@y

Since V is backwards compatible, you can Try it online!

This is the perfect task for vim! I might golf it a little bit more later. Also note that <c-a> means Control-A, and it counts as one keystroke.

Explanation:

iclass Tuple1 {public Object _0;}<esc>         'Enter the starting text


qy                          'Start recording in register y
  Yp                        'Yank the current line, the print on the line below
     <C-a>                  'Increment the next digit to occur by one
          $                 'Move to the end of this line
           y2b              '(yank) 2 words (b)ack. This will grab '_0;'
              P             'Print the previously yanked word before the cursor.
               r,           '(r)eplace the char under the cursor with a comma.
                 <c-a>q     'Increment the current digit, then stop recording
                       99@y 'Playback macro 'y' 99 times.

James

Posted 2016-02-03T07:41:55.143

Reputation: 54 537

1If you count Control-A as one keystroke, you could substitute yy by Y. – seequ – 2016-02-03T21:44:57.050

1@Seeq Haha, I just realized the same thing and edited it in right before I saw your comment. Great minds think alike! – James – 2016-02-03T21:45:55.447

This seems to be going to class Tuple101, not class Tuple100 as the question asks. – numbermaniac – 2017-09-26T00:02:28.083

1@numbermaniac Simple off-by-one error. Thanks for pointing that out! Fixed now :) – James – 2017-09-26T14:16:58.543

10

Jelly, 44 bytes

R’j“,_”
“¤>%,oỊȤʠ“ØụĊ5D³ṃṠɼQ»j;Ç;“;}¶”
ȷ2RÇ€

My first Jelly answer. Try it online!

Lynn

Posted 2016-02-03T07:41:55.143

Reputation: 55 648

Am I doing it wrong or does this just output a giant list instead of a string? – Denker – 2016-02-03T19:30:34.300

@DenkerAffe It seems to be working now! There was a temporary bug in Jelly. (Also, the link was to an old version of my solution, so I've updated it.) – Lynn – 2016-02-03T20:04:54.840

Nice... as of now it's 9 bytes shorter than the CJam solution! – Ray Toal – 2016-02-05T03:56:43.097

8

Pyth, 53 50 48 bytes

VS100%." }SüÆðQ´Ó3Ô«%&a´4UçõÛ"[Nj",_"UN

Try it online!

Straightforward iteration over range(1,100) and building the corrosponding string from a packed string through formatting it.

Explanation

VS100%." }SüÆðQ´Ó3Ô«%&a´4UçõÛ"[Nj",_"UN

VS100                                     # Iterate over range(1,100)
     %." }SüÆðQ´Ó3Ô«%&a´4UçõÛ"            # Unpack the string and format it
                              [           # List for formatting arguments
                               N          # Number of the Tuple
                                j    UN   # Join Object numbers...
                                 ",_"     # ...on the seperator ",_"

The unpacked string is class Tuple%i {public Object _%s;}

Denker

Posted 2016-02-03T07:41:55.143

Reputation: 6 639

Two golfs: Use s[ instead of all of those +. [ makes an arbitrary length list, and s concatenates it. Also, since you want [1, 2, ... 100], not [0, 1, .. 99], use VS100, and you won't need either h. – isaacg – 2016-02-03T08:21:44.357

@isaacg Thanks, did not know about the S-trick! :) Was already sitting on getting rid of all the ++++, I knew there is a better way. – Denker – 2016-02-03T08:33:06.007

You;re welcome. By the way, you seem to have added a trailing " unnecessarily. – isaacg – 2016-02-03T09:02:10.093

@isaacg Thanks for the hint. :) I removed it in my initial solution, but somehow it got back in when I edited in your suggestions :O – Denker – 2016-02-03T09:06:03.067

1@isaacg Is there any reason j<str><int> doesn't U? – lirtosiast – 2016-02-03T21:05:57.747

1No, not really. Will do. – isaacg – 2016-02-03T21:29:53.220

7

CoffeeScript, 86 84 bytes

console.log "class Tuple#{i} {public Object _#{[0...i].join ',_'};}"for i in[1..100]

View the solution online

Ray Toal

Posted 2016-02-03T07:41:55.143

Reputation: 589

Welcome to PPCG! Just to let you know edits that improve answers are generally frowned (and should be rejected if they end up in the review queue). So it's more likely that people will comment with suggestions, so you can review them yourself. :) (As for actual tips I think you need neither the space in front of for nor the one after in.)

– Martin Ender – 2016-02-03T07:56:51.487

Does console.log" work? (Don't know coffee script, that's a general trick. – Addison Crump – 2016-02-03T08:05:00.530

No, as in, removing the space. :P I know it exists, I just don't know if that's valid syntax. – Addison Crump – 2016-02-03T08:16:40.057

@VoteToClose I tried that earlier (using the live transpiler on coffeescript.org and it didn't work). – Martin Ender – 2016-02-03T08:19:16.773

@VoteToClose Oh sorry didn't see that. No. somehow the space is required by the grammar, but it is not exactly clear to me why (yet). Spacing matters a lot in CoffeeScript, for instance, x? y:z is completely different from x ? y:z. You can say console.log?"hello" but not console.log"hello". Significant whitespace. Sometimes nice, sometimes weird. – Ray Toal – 2016-02-03T08:28:45.397

You can usually use functions for in- and output. So an anonymous lambda which implicitly returns the string might save you some bytes. – Denker – 2016-02-03T08:50:43.510

Oh-I didn't see that on either the site tour or the help center. So rather than requiring writing lines to stdout, is it customary to ask for a "function producing a string with newlines in it?" And if a function, can it not also be an expression generating the string without being the body of an anonymous function? Thanks for the patience and the tips; I'm looking to learn the customs here. If the custom is "stdout OR function OR expression" that's fine, but then should I edit the question accordingly? – Ray Toal – 2016-02-03T16:34:41.477

7

Java, 160, 125 Bytes

Thanks to @DenkerAffe, @Denham Coote and @Mathias Ettinger for the improvements.

Java writing java( because someone had to!)

void z(){String s="_0";for(int i=1;i<101;){System.out.println("class Tuple"+(i++)+" {public Object "+s+";}");s+=",_"+i;}}

And the un-golfed version

void z(){
    String s = "_0";
    for(int i = 1 ;i < 101;){
        System.out.println("class Tuple" + (i++) + " {public Object "+ s + ";}");
        s += ",_" + i;
        }
    }

SoloKix

Posted 2016-02-03T07:41:55.143

Reputation: 89

2Welcome to Programming Puzzles & Code Golf! Unless stated otherwise in the challenge, you can alwasy use functions instead of full programs. So you should use a Java8-lambda (which returns the result) here to save you all the public static void main...stuff. – Denker – 2016-02-03T10:07:38.903

4Welcome to PPCG. This answer includes an extra comma at the end of the Object declarations... class Tuple1 {public Object _0,;} class Tuple2 {public Object _0,_1,;} – Denham Coote – 2016-02-03T10:39:37.803

3You can save a further 3 bytes by incrementing your loop counter in the sysout (++i) instead of (i+1) and removing i++ from the for loop setup – Denham Coote – 2016-02-03T10:58:38.180

You should start your String s = "_0" so you can s += ",_" + i and save a byte. It will also solve the problem with the trailing coma. You’ll need to start the for loop going from 1 to less than 101 and will be able to remove an extra 4 bytes by converting the (i+1) in your output message to only i. Obviously, you’ll need to print before incrementing s. – 301_Moved_Permanently – 2016-02-04T13:59:06.033

Thanks, have done all these things, and am definitely going to have a gander at java8-lambda. – SoloKix – 2016-02-06T02:10:42.163

I know it's been more than 1.5 years, but it's currently giving incorrect results.. Your method goes from _0, to _2, instead of _1. You can fix this, and golf it by 5 bytes at the same time, like this: void z(){String s="_0";for(int i=1;i<101;s+=",_"+i++)System.out.println("class Tuple"+i+" {public Object "+s+";}");}. And you could golf it more with Java 8 using ()-> instead of void z() or better yet, v-> instead (because an empty unused parameter is allowed). Here is how to do this (resulting in 111 bytes).

– Kevin Cruijssen – 2017-09-26T10:05:06.983

6

Batch, 128 bytes

@set m=_0
@for /l %%t in (1,1,100)do @call:b %%t
@exit/b
:b
@echo class Tuple%1 {public Object %m%;}&set m=%m%,_%1

Edit: Saved 10 bytes thanks to @Bob. Saved 1 byte thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.

Neil

Posted 2016-02-03T07:41:55.143

Reputation: 95 035

3I always get really happy to see batch on code golf, also, instead of using @ everywhere, you could redirect output to append to a file called x and use that as output – Dennis van Gils – 2016-02-03T12:15:36.423

@DennisvanGils Sadly commands get echoed to standard output. – Neil – 2016-02-03T18:49:49.697

Eliminated enabledelayedexpansion for 117 bytes: https://gist.github.com/Elusive138/4cea555114a979954dcb -- if you don't mind the console window closing you can save two more by removing the /b arg from exit.

– Bob – 2016-02-04T00:08:16.890

@Neil lol okay so I just tried running it and now I realize what you did. Very clever. – Ashwin Gupta – 2016-02-04T04:13:12.663

At beginning, use @echo off – Elliot A. – 2016-02-06T18:00:51.520

@ElliotA. Why? That would waste 11 bytes. – Neil – 2016-02-06T18:25:02.757

Remove the other @'s, and :b doesn't print to the display. – Elliot A. – 2016-02-06T21:04:11.263

@ElliotA. That still leaves me 6 bytes down... – Neil – 2016-02-07T00:09:52.430

6

Oracle SQL 9.2, 138 137 Bytes

SELECT REPLACE('class Tuple'||LEVEL||' {public Object'||SYS_CONNECT_BY_PATH(LEVEL-1,',_')||';}','t,','t ')FROM DUAL CONNECT BY LEVEL<101;

@Peter Thanks for pointing the 0/1 mistake.

The query use the CONNECT BY CLAUSE of hierarchical query to generate 100 rows.

The LEVEL pseudocolumn contains the row number of each row.

SYS_CONNECT_BY_PATH concatenate the first parameter, the row number, of each row, and use the second parameter as the separator.

Jeto

Posted 2016-02-03T07:41:55.143

Reputation: 1 601

please add some explanation – Eumel – 2016-02-03T13:32:29.660

Clever :) This starts with Object _1 instead of Object _0, so that will take another two bytes (-1). However, the _ can be added to the char of SYS_CONNECT_BY_PATH instead of concatenating, reducing it by two those bytes again: REPLACE('class Tuple'||LEVEL||' {public Object'||SYS_CONNECT_BY_PATH(LEVEL-1,',_')||';}','t,_','t _') – Peter Lang – 2016-02-05T07:57:18.413

5

Retina, 80 79 bytes

Byte count assumes ISO 8859-1 encoding.

100$*1
1
class Tuple11$` {public Object 1$`}¶
1(?<= (1+))
_$1,
1(1)*
$#1
,}
;}

Try it online!

Martin Ender

Posted 2016-02-03T07:41:55.143

Reputation: 184 808

5

Powershell - 65 bytes

(Amended in response to comment)

All credit to TimmyD

1..100|%{"class Tuple$_ {public Object _$(0..($_-1)-Join",_");}"}

bulletprooffool

Posted 2016-02-03T07:41:55.143

Reputation: 51

Why the vote down? (Please note this is my first ever post, not a great welcome?) – bulletprooffool – 2016-02-03T13:27:40.597

5

Perl 6, 65 bytes

say "class Tuple$_ \{public Object _{join ',_',^$_};}" for 1..100

Brad Gilbert b2gills

Posted 2016-02-03T07:41:55.143

Reputation: 12 713

4

R - 199 132 123 118 bytes

Version 4

p=paste0;for(i in 1:10)cat(p("class Tuple",i," {public Object ",toString(sapply(0:(i-1),function(x)p("_",x))),";}\n"))

Version 3

p=paste0;for(i in 1:8)cat(p("class Tuple",i," {public Object ",p(sapply(0:(i-1),function(x)p("_",x)),collapse=","),";}\n"))

Version 2

p=paste0;for(i in 1:100)cat(p("class Tuple",i," {public Object ",p(sapply(0:(i-1),function(x)p("_",x)),collapse=","),";}"),sep="\n")

Version 1

for (i in 1:100){
  foo <- paste0("class Tuple", i, " {public Object ")
  for (j in 0:(i - 1)){
    foo <- if (j < (i - 1)) paste0(foo, "_", j, ",") else paste0(foo, "_", j, ";}")
  }
  print(foo)
}

Argenis García

Posted 2016-02-03T07:41:55.143

Reputation: 223

3Welcome to Programming Puzzles & Code Golf! Since this is a code golf competition, you'll want to make your code as short as possible. You could start by shortening variable names to a single character each, removing whitespace, and using = for assignment rather than <-. – Alex A. – 2016-02-03T17:17:47.527

144 bytes: for(i in 1:100){f=(p=paste0)("class Tuple",i," {public Object ");for(j in 0:(i-1))f=if(j<i-1)p(f,"_",j,",")else p(f,"_",j,";}");cat(f,sep="\n")} – Alex A. – 2016-02-03T17:23:41.830

No problem. :) Also, you don't need to keep track of your versions in the post body since the revision history is accessible via the link that says "edited X minutes ago." – Alex A. – 2016-02-03T19:40:25.513

(though it may be worthwhile to give some indication, either in your edit summaries or in the post what you changed with each revision so that others could learn from your revision process) – quintopia – 2016-02-03T19:54:02.673

4

Ruby, 71 bytes

100.times{|i|puts"class Tuple#{i+1} {public Object _#{[*0..i]*',_'};}"}

daniero

Posted 2016-02-03T07:41:55.143

Reputation: 17 193

2TIL [*0..i]*',_' wow – Ray Toal – 2016-02-04T03:44:18.083

4

Java, 103 bytes

s->{s="_0";for(int i=0;i++<100;s+=",_"+i)System.out.printf("class Tuple%s {public Object %s;}\n",i,s);}

My first time here. Hi there! I went for a Java8 lambda expression (aka an anonymous function).

Ungolfed version

s -> {
    s = "_0";
    for (int i = 0; i++ < 100; s += ",_" + i)
        System.out.printf("class Tuple%s {public Object %s;}\n", i, s);
}

To actually use this, as usual in Java8, you have to assign it to a variable of (or cast it to) an appropriate functional interface and then call its method; but technically, the function is only the lambda expression itself, so I am counting only that.

It also requires an input parameter, which saves me a couple bytes, since I can abuse it as a local variable without having to specify its type. I'm not sure if that's considered cheating, but to me it appears to be within the rules: I only saw people state that posting a function is allowed, not how that function needs to be invoked. :) And it doesn't actually read the parameter, so the function is still self-contained; you can pass any String to it, or even null, and it will still produce the correct output.

And here is how to use it:

import java.util.function.Consumer;

public class Main {
    public static void main(String[] args) {
        Consumer<?> r =
            s->{s="_0";for(int i=0;i++<100;s+=",_"+i)System.out.printf("class Tuple%s {public Object %s;}\n",i,s);}
        ;
        r.accept(null); 
    }
}

FireballStarfish

Posted 2016-02-03T07:41:55.143

Reputation: 91

3

Python 2, 96

def f(n=99):s=n and f(n-1)+',_'+`n`or"class Tuple%d {public Object _0";print s%-~n+';}';return s

Python 3, 98

def f(n=99):s=n and f(n-1)+',_%d'%n or"class Tuple%d {public Object _0";print(s%-~n+';}');return s

Usage:

f()

Ungolfed:

def javatuple(n=99):
    if n == 0:
        s = "class Tuple%d {public Object _0"
    else:
        s = javatuple(n-1) + ',_' + str(n)
    print(s%(n+1) + ';}')
    return s

formers:

103

r=range
for i in r(100):
 print"class Tuple%d {public Object _%s;}"%(i+1,',_'.join(`j`for j in r(i+1)))

108

def f(n=99):
 if n:f(n-1)
 print"class Tuple%d {public Object _%s;}"%(n+1,',_'.join(`i`for i in range(n+1)))

pacholik

Posted 2016-02-03T07:41:55.143

Reputation: 490

In your python2 answer the last line seems to be incomplete :

print f(3)

gives :

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 Tuple%d {public Object _0,_1,_2,_3 – dieter – 2016-02-03T15:15:26.913

@dieter The last line is a result. It's printed only when you run it interactively. – pacholik – 2016-02-03T18:03:52.300

2

CJam, 53 bytes

100{)"class Tuple"\" {public Object _"1$,",_"*";}
"}/

Try it here.

Lynn

Posted 2016-02-03T07:41:55.143

Reputation: 55 648

2

Groovy, 74 chars

"join()" is unbeatable... New solution, thanks to @yariash

100.times{println"class Tuple$it {public Object _${(0..it-1).join',_'};}"}

Old solution, 78 chars:

(1..100).each{println"class Tuple$it {public Object _${(0..it-1).join',_'};}"}

t0r0X

Posted 2016-02-03T07:41:55.143

Reputation: 153

2You can use 100.times{} instead of (1..100).each{}. – Krzysztof Atłasik – 2016-05-17T09:36:07.863

@yariash Thanks for the hint! – t0r0X – 2016-05-17T10:27:47.863

1

PowerShell, 63 bytes

1..100|%{"class Tuple$_ {public Object _$(0..--$_-Join",_");}"}

Try it online!

Two byte improvement of bulletprooffool's answer, who seems to be an abandoned account now.

Veskah

Posted 2016-02-03T07:41:55.143

Reputation: 3 580

1

Lua, 128 106 Bytes

I'm still trying to find a way to directly work on a printed value, and not on a string.

Edit : Partially found it! I still need a string for the "_0,_1..." part, but it already is better :).

s=""for i=0,99 do s=(s..",_"..i):gsub("^,",s)print(("class Tuple"..(i+1).." {public Object ")..s..";}")end

Old 128 Bytes solution

s="class Tuple1 {public Object _0;}"print(s)for i=1,99 do s=s:sub(1,s:find";"-1):gsub("e%d+","e"..i+1)..",_"..i..";}"print(s)end

Ungolfed

s=""
for i=0,99
do
  s=(s..",_"..i)              -- concatenate s with ",_i"
      :gsub("^,",s)           -- remove the leading "," for ",_0"
  -- then print the concatenated string
  print(("class Tuple"..(i+1).." {public Object ")..s..";}")
end

Katenkyo

Posted 2016-02-03T07:41:55.143

Reputation: 2 857

1

Python 2, 96 Bytes

r=range
for i in r(1,101):print"class Tuple%d {public Object _%s;}"%(i,',_'.join(map(str,r(i))))

Thanks @DenkerAffe for the suggestion of using lambda.

Thanks @MathiasEttinger for the join idea.

Dair

Posted 2016-02-03T07:41:55.143

Reputation: 141

2You can golf this down to 111 bytes if you use a lambda in your reduce-call instead of defining a function for this: reduce(lambda x,y:'%s,_%s'%(x,y), r(i)) – Denker – 2016-02-03T09:01:11.457

1Or use ',_'.join(map(str,r(i))) for an extra 14 bytes removal (or 15, since you left an extra space in your reduce). – 301_Moved_Permanently – 2016-02-04T14:07:16.527

1

Julia, 77 bytes

for i=1:100;println("class Tuple$i {public Object _$(join(0:i-1,",_"));}")end

Ray Toal

Posted 2016-02-03T07:41:55.143

Reputation: 589

1

Python 3, 111 109 105 bytes

[print('class Tuple%s {public Object %s;}'%(i,','.join('_%i'%j for j in range(i))))for i in range(1,101)]

It's not the shortest thing in the world, I'm just participating.

edit1: down 2 bytes by removing 0, in first range

edit2: I was unnecessarily casting int to str instead of just using %i... Down to 105.

Issak

Posted 2016-02-03T07:41:55.143

Reputation: 11

Welcome, nice start! If interested, try range(i) in place of range(0,i) or since you used range twice, try r=range early then reference each call with just r (as in the other Python solutions). – Ray Toal – 2016-02-03T08:58:48.837

Ugh, I forgot range starts at 0 by default. Down 2 bytes, however, adding r=range; in the beginning results in exactly the same character count, I've tried that! :D – Issak – 2016-02-03T09:05:11.493

Same comment than I did to Dair: ',_'.join(map(str,range(i))) is 7 bytes shorter here.

– 301_Moved_Permanently – 2016-02-04T14:13:25.970

1

Mathematica, 130 Bytes

{"class Tuple",ToString[#]," {public Object ",StringReplace[ToString[#-1&/@Range@#],{" "|"{" ->"_","}"->";}\n"}]}&/@Range[100]<>""

A Simmons

Posted 2016-02-03T07:41:55.143

Reputation: 4 005

Hint: \n can be replaced with a literal newline character. – LegionMammal978 – 2016-02-03T22:10:57.853

1

Scala, 85 Bytes

for(u<-1 to 100)println(s"class Tuple$u {public Object _${0 to u-1 mkString ",_"};}")

Jo Bain

Posted 2016-02-03T07:41:55.143

Reputation: 11

1

PHP, 112 bytes

<?php for($i=0;$i<100;$i++){$m.=$i==0?'_'.$i:',_'.$i;echo 'class Tuple'.($i+1).' {public Object '.$m.';}<br/>';}

gumione

Posted 2016-02-03T07:41:55.143

Reputation: 11

You can save a few bytes by switching echo to double quotes where possible: <?php for($i=0;$i<100;$i++){$m.=$i==0?"_$i":",_$i";echo 'class Tuple'.($i+1)." {public Object $m;}\n";} – Samsquanch – 2016-02-03T16:49:30.783

1

@Samsquanch Also, instead of echo 'class Tuple'.($i+1)." {public Object $m;}\n";, you can use echo'class Tuple',$i+1," {public Object $m;}\n";, which is 3 bytes shorter. Also, according to the meta, you can remove the <?php and assume that your code will be executed with php -r "code". Also, you can do for(;++$i<101;)echo"class Tuple$i {public Object ",$m=($m?"$m,":'')."_$i",";}\n"; for 80 bytes (you need to replace the \n with a real newline). Try it here: http://ideone.com/oOzKtP

– Ismael Miguel – 2016-02-04T10:34:32.320

1

Javascript, 112 110 bytes

2 bytes off thanks @CᴏɴᴏʀO'Bʀɪᴇɴ.

_=>[...Array(100)].map((x,i)=>`class Tuple${++i} {public Object ${[...Array(i)].map((y,j)=>'_'+j)};}`).join`
`

Ungolfed:

_=>                                         // anonymous function
    [...Array(100)].map((x,i)=>             // 100 times [0..99]
        `class Tuple${++i} {public Object   // Tuple index + 1
            ${[...Array(i)].map(            // (index + 1) times
                (y,j)=>'_'+j                // _+j with j in [0..index]
            )}                              // Array without join prints comma in between
        ;}`                                 // as literal string
    ).join`\n`                              // display array line by line

removed

Posted 2016-02-03T07:41:55.143

Reputation: 2 785

1I think you can replace ${i+1} with ${i++} and replace ${[...Array(i++)] with ${[...Array(i)]. – Conor O'Brien – 2016-02-03T19:55:27.297

@CᴏɴᴏʀO'Bʀɪᴇɴ. Thanks, I've updated with ++i – removed – 2016-02-04T00:14:55.373

1

Java, 116

(for the printing function only - according to some comments, this is in line with the rules)

import static java.lang.System.*;
public class T
{
    public static void main(String[] args)
    {
        T t = new T();
        t.p();
    }

    void p(){String s="_0";for(int i=0;i<100;){out.println("class Tuple"+ ++i+" {public Object "+ s + ";}");s+=",_"+i;}}
}

Marco13

Posted 2016-02-03T07:41:55.143

Reputation: 1 131

1

Seriously, 55 bytes

2╤R`;r"$'_+"£M',j@k"c╙ò T╒α%d {pu▐V Object %s;}"⌡%`M'
j

Hexdump (reversible with xxd -r):

00000000: 32e2 95a4 5260 3b72 2224 275f 2b22 c2a3  2...R`;r"$'_+"..
00000010: 4d27 2c6a 406b 2263 e295 99c3 b220 54e2  M',j@k"c..... T.
00000020: 9592 ceb1 2564 207b 7075 e296 9056 204f  ....%d {pu...V O
00000030: 626a 6563 7420 2573 3b7d 22e2 8ca1 2560  bject %s;}"...%`
00000040: 4d27 0a6a                                M'.j

Try it online!

Yes, that newline is supposed to be there.

Explanation (newline replaced with \n):

2╤R`;r"$'_+"£M',j@k"c╙ò T╒α%d {pu▐V Object %s;}"⌡%`M'\nj
2╤R                                                       push range [1,100]
   `                                              `M      map:
    ;r                                                      push a, range(a)
      "$'_+"£M                                              map:
       $'_+                                                   stringify, prepend "_"
              ',j                                           join with commas
                 @k                                         swap and push stack as list
                   "c╙ò T╒α%d {pu▐V Object %s;}"⌡           decompress, result is
                                                              "class Tuple%d {public Object %s;}"
                                                 %          string format
                                                    '\nj  join with newlines

Mego

Posted 2016-02-03T07:41:55.143

Reputation: 32 998

1

Japt, 52 bytes

Lo £`cÓ? TÕà{X} \{puÞV Object {Xò ®'_+Z}&}` r&59d} ·

The ? should be the literal byte 0x95. Test it online!

Japt has:

  • concise syntax to help shorten your code.
  • string compression to help shorten it even further.
  • lots of bugs to make you want to throw your computer out the window.

I can't even use a semicolon in the string because the function it's wrapped in wants to return everything after the semicolon. This should only be 46 bytes:

Lo £`cÓ? TÕà{X} \{puÞV Object {Xò ®'_+Z};}`} ·

But alas, it is not. I'll see if I can fix these bugs over the next couple of hours.

How it works

Lo £       }  // Generate the range [0..100), and map each item X in this range to:
`cÓ? TÕà{X}   //  "class Tuple" + X +
\{puÞV Object //  "{public Object" +
{Xò ®'_+Z}    //   Create the range [0..X] and map each item Z to "_" + Z.
              //   Upon stringification, this automatically inserts the commas.
&}`           //  + "&}"
r&59d         //  Replace the "&" with String.fromCharCode(59), or ";".
·             // Join the result with newlines.

ETHproductions

Posted 2016-02-03T07:41:55.143

Reputation: 47 880

Bah! Ninjaed by ~18 months! You need to increment the first X, by the way. – Shaggy – 2017-09-26T14:47:20.650

1

Groovy, 97 bytes

(1..100).each{println "class Tuple${it} {public Object ${(0..it-1).collect{"_$it"}.join(',')};}"}

Try it online!

Apostolos

Posted 2016-02-03T07:41:55.143

Reputation: 111

1You can user 100.times{} instead of (1..100).each{}, which saves 4 bytes. – Krzysztof Atłasik – 2016-05-17T09:13:41.927

You can also omit braces in join (join','), remove space after println, and replace .collect{} with *.with{} – Krzysztof Atłasik – 2016-05-17T09:31:28.020

1

C++, 164 159 157 bytes (155 as function only)

#include <iostream>
#define o std::cout<<
int main(){int j,i=0;for(;i<100;++i){o"class Tuple"<<i+1<<" {public Object _0";for(j=0;++j<=i;)o",_"<<j;o";}\n";}}

This is a full program. You can save 2 bytes in function only form if you replace int main() with void f().

Run code in Ideone

Ungolfed, including macro expansion

#include <iostream>
int main()
{
    int j,i=0;
    for(;i<100;++i)
    {
        std::cout << "class Tuple"<< i+1 <<" {public Object _0";
        for(j=0;++j<=i;)
            std::cout << ",_" << j;
        std::cout << ";}\n";
    }
}

sendaran

Posted 2016-02-03T07:41:55.143

Reputation: 111

Welcome to Programming Puzzles & Code Golf! Nice first answer! Unless stated otherwise in the challenge, you can always use functions instead of full programs, so you can save a few bytes by doing that. You still have to include iostream tho, since its needed for the output. – Denker – 2016-02-04T15:22:00.823

You might also want to do j=1 in your for loop, thus not having the if(j). – Ethiraric – 2016-02-05T10:42:55.330

@Ethiraric But of course! How sloppy of me. I guess I got too focused on the idea "remember to skip additions on first line" and ended up writing that too literally. – sendaran – 2016-02-05T10:59:39.997

@sendaran Or even may be for(int j=0;++j<=i;) would save one more byte. – Ethiraric – 2016-02-05T11:25:09.730

@Ethiraric Did that and shaved off an extra byte by extracting variable declarations, which enabled another empty expression. – sendaran – 2016-02-05T14:27:11.910

1

, 44 chars / 55 bytes

⩥ṥⓜᵖ`э£ēÕ>rĕĠ#⦃$⦄ {public Object ⦃⩤$ⓜ⍘_+$⦄;}

Try it here (Firefox only).

Still amazing even without compression.

Explanation

⩥ṥⓜᵖ`э£ēÕ>rĕĠ#⦃$⦄ {public Object ⦃⩤$ⓜ⍘_+$⦄;} // implicit: ṥ=input
⩥ṥⓜ                                          // generate [0,100) to map over
    ᵖ                                         // push to stack:
     `э£ēÕ>rĕĠ#⦃$⦄                             // class Tuple[insert mapitem here]
                  {public Object ⦃⩤$ⓜ⍘_+$⦄;} // {public Object [insert [0,mapitem] here preceded by semicolons per item];}
                                             // implicit stack output

Mama Fun Roll

Posted 2016-02-03T07:41:55.143

Reputation: 7 234

1

Pip, 53 51 bytes

LhP["class Tuple"++i" {public Object "'_.,iJ',";}"]

Try it online!

Explanation:

                        h is preinitialized to 100 and i to 0 (implicit)
L h                     Loop 100 times:
 P [                    Print the following list (with trailing newline):
    "class Tuple"
    ++i                 Increment i here so that its values run from 1 to 100
    " {public Object "
    ('_ . ,i) J ',      Range(i), concatenate "_" before each element, join on ","
    ";}"
   ]                    By default, lists are concatenated when printed

DLosc

Posted 2016-02-03T07:41:55.143

Reputation: 21 213

Idea: Maybe name your language so that it doesn't get confused with the pip utility

– LegionMammal978 – 2016-04-24T09:54:25.780

@LegionMammal978 Yeah, I realized that problem after the fact... but I think now it is what it is. (When I came up with the acronym "Pip Isn't Python," it seemed so perfect...) – DLosc – 2016-04-25T22:42:59.927

1

JavaScript (ES6), 85 bytes

s='_0';for(i=1;i<101;s+=',_'+i++)console.log(`class Tuple${i} {public Object ${s};}`)

dtkaias

Posted 2016-02-03T07:41:55.143

Reputation: 141

1Very nice! Could you add an explanation? Also, I believe you could save a single byte by moving s+=',_'+i++ into the last bit of the for. – Fund Monica's Lawsuit – 2016-05-20T01:25:48.540

Thanks! The for loop prints out each line whilst adding to the _0,_1,_2... string (stored in s) at the end of each iteration. Uses ES6 template strings to save a few bytes :P – dtkaias – 2016-05-20T05:21:25.170

(I meant [edit] an explanation into your question. Answers with them tend to be better-received) – Fund Monica's Lawsuit – 2016-05-20T14:18:47.167

0

Tcl, 107 bytes

time {set s "class Tuple[incr i] \{public Object \{"
set j 0
time {set s $s\_$j\;
incr j} $i
puts $s\}} 100

Try it online!

Tcl, 117 bytes

proc P n {set i 0;time {append s _$i\;;incr i} $n;set s}
time {puts "class Tuple[incr i] {public Object [P $i]}"} 100

Try it online!

sergiol

Posted 2016-02-03T07:41:55.143

Reputation: 3 055

0

Perl 5, 68 bytes

$"=',_';@d=0..$_-1,say"class Tuple$_ {public Object _@d;}"for 1..100

Try it online!

Xcali

Posted 2016-02-03T07:41:55.143

Reputation: 7 671

0

V, 47 bytes

iclass Tuple1 {public Object _0;}99ñÙ$hi,_Û

Try it online!

James

Posted 2016-02-03T07:41:55.143

Reputation: 54 537

0

C++, 139 137 bytes

-2 bytes thanks to Zacharý

#include<iostream>
auto&p=printf;void j(){int i=1,k;for(;i<101;++i){p("class T%d{",i);for(k=0;k<i;++k)p("public Object v%d;",k);p("}");}}

HatsuPointerKun

Posted 2016-02-03T07:41:55.143

Reputation: 1 891

Woah, nice golf! If you're straying from the source to generate equivalent valid java code (using public Object v0;public Object v1; instead of public Object _0,_1;, removing the space before {) then can't you change p("}\n") to p("}")? That raises another question, are you allowed to stray from the source? – Zacharý – 2017-09-30T22:43:55.473

@Zacharý actually, the code outputed is class T2{public Object v0;public Object v1}, so... I may try to use some printf magic to erase a full loop – HatsuPointerKun – 2017-09-30T23:28:00.253

Secondly, why are using <iostream> instead of <cstdio> if you're just using printf? Unless I'm missing something, that may work. – Zacharý – 2017-10-05T16:49:47.840

0

C# (Visual C# Interactive Compiler), 110 109 bytes

int i;for(;i++<100;)Write($"class Tuple{i} {{public Object _{string.Join(",_",Enumerable.Range(0,i))};}}\n");

Saved a byte thanks to @dana

Try it online!

Embodiment of Ignorance

Posted 2016-02-03T07:41:55.143

Reputation: 7 014

109 - declare i at the top level ;) – dana – 2019-04-03T05:14:08.070

0

ink, 87 bytes

-(i)class Tuple{i} \{public Object <>
~temp k=-1
-(j)~k++
_{k}{k<i:,->j};\}
{i<100:->i}

Try it online!

Sara J

Posted 2016-02-03T07:41:55.143

Reputation: 2 576

0

Forth (gforth), 97 bytes

: f 101 1 do cr ." class Tuple"i 1 .r ." {public Object _0"i 1 ?do ." ,_"i 1 .r loop ." ;}"loop ;

Try it online!

Code Explanation

: f                           \ start a new word definition
  101 1 do                    \ start a loop from 1 to 100
    cr                        \ output a new line
    ." class Tuple"i 1 .r     \ output "class TupleN" where N is the loop index
    ." {public Object _0"     \ output "{public Object _0"
    i 1 ?do                   \ start a loop from 1 to the outer loop index
      ." ,_"i 1 .r            \ output ",_N" where N is the inner loop index
    loop                      \ end the inner loop
    ," ;}"                    \ output ";}"
  loop                        \ end the outer loop
 ;                            \ end the word definition

reffu

Posted 2016-02-03T07:41:55.143

Reputation: 1 361

0

05AB1E, 43 bytes

тFNÝ„,_ý'_ì'Œº™'‚ÆN>'„à"ÿ Tupleÿ {ÿ ÿ ÿ;}"=

Try it online!

Magic Octopus Urn

Posted 2016-02-03T07:41:55.143

Reputation: 19 422

0

Python 2, 93 bytes

i=1;exec'print"class Tuple%s {public Object _"%i+",_".join(map(str,range(i)))+";}";i+=1;'*100

Try it online!

I rarely get to use exec in code golf, so I wasn't going to pass on this one!

ArBo

Posted 2016-02-03T07:41:55.143

Reputation: 1 416

0

Perl5, 77 Bytes

$"=", ";for(0..100){push@o,"_$_";print"class Tuple$_\{public Object @o;\}\n"}

Also

for(0..100){$o.=$o?", _$_":"_$_";print"class Tuple$_\{public Object $o;\}\n"}

Peter Barker

Posted 2016-02-03T07:41:55.143

Reputation: 9

Welcome to Programming Puzzles and Code Golf! Please put your language together with the byte count in the title and format the code correctly (see my edit). Hope your have a great time here! :) – Denker – 2016-02-03T08:37:26.127

You don't have to put a backslash for the first accolade in the print : print"class Tuple$_{public Object $o;\}\n"} – Paul Picard – 2016-02-03T16:22:23.190

You have an off-by-one error, the first line should be Tuple1 … _0;. The simple fix would be to put the push after the print and to make the print conditional on $_. …;for(0..100){$_&&print …;push@o,"_$_"} – Brad Gilbert b2gills – 2016-02-03T17:23:49.733

0

MATL, 59 bytes

100:"'class Tuple%i {public Object %s}'@'_%i,'@:qYD59O(3$YD

EDITS

  • (May 16, 2016): to adapt to recent changes in the language, O needs to be replaced by J in the above code.
  • (September 29, 2017): the order of the inputs to YD has changed, which requires some modifications in the code.

The following link includes these changes.

Try it online!

Luis Mendo

Posted 2016-02-03T07:41:55.143

Reputation: 87 464

0

Java 1.8, 163 Bytes

interface T{static void main(String[]a){String o="";for(int i=0;i<100;){o+=(i>0?",":"")+"_"+i;System.out.println("class Tuple"+(++i)+" {public Object "+o+";}");}}}

Ungolfed

interface T{
static void main(String[]a){
    String o="";
    for(int i=0;i<100;){
        o+=(i>0?",":"")+"_"+i;
        System.out.println("class Tuple"+(++i)+" {public Object "+o+";}");
    }
}
}

Denham Coote

Posted 2016-02-03T07:41:55.143

Reputation: 1 397

1Unless stated otherwise in the challenge, you can always use functions instead of full prorgams. So youcan save all that static void main... stuff by using a Java8-lambda which implictly returns the result. – Denker – 2016-02-03T10:58:26.637

Old habits die hard ;) – Denham Coote – 2016-02-03T10:59:08.897

0

AWK, 84 Bytes

BEGIN{m=" {public Object _0";for(i=1;i<101;){print"class Tuple"i m";}";m=m",_"i++}}

I do like playing with AWK.

If the script were placed in a file, tuple.awk, and called with a 1 line input, the BEGIN tag could be removed... e.g. echo 1|awk -f tuple.awk

Not sure if any other golfing could be done to it.

Robert Benson

Posted 2016-02-03T07:41:55.143

Reputation: 1 339

0

Clojure, 103 chars

(map(fn[n](prn(str"class Tuple"n" {public Object "(join","(map #(+"_"%)(range n)))";}")))(range 1 101))

MattPutnam

Posted 2016-02-03T07:41:55.143

Reputation: 521

0

jq, 80 characters

(78 characters code + 2 characters command line option.)

range(1;13)|"class Tuple\(.) {public Object \([range(.)|"_\(.)"]|join(","));}"

Sample run:

bash-4.3$ bin/jq -nr 'range(1;101)|"class Tuple\(.) {public Object \([range(.)|"_\(.)"]|join(","));}"' | head
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;}

On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

manatwork

Posted 2016-02-03T07:41:55.143

Reputation: 17 865

0

Common Lisp, 106 bytes

(let(y)(dotimes(x 100)(push x y)(format t"class Tuple~d {public Object ~{_~d~^,~};}~&"(1+ x)(reverse y))))

Try it online!

cromachina

Posted 2016-02-03T07:41:55.143

Reputation: 1

0

Java, 166 Bytes

void m(){int c=0;while(c!=100){System.out.print("class Tuple"+(c+1)+" {public Object ");for(int i=0;i<c+1;i++)System.out.print(",_"+i);System.out.print(";}\n");c++;}}

Not bad for java, I mean calling main() alone is like 10+ bytes.. (plus long print statements)

(Non-Competetive) Java w/ Quick-Print! 137 bytes

import t.Q;
void m(){int c=0;while(c!=100){Q.p("class Tuple"+(c+1)+" {public Object ");for(int i=0;i<c+1;i++)Q.p(",_"+i);Q.p(";}\n");c++;}}

This one uses a quick library I have been thinking about making for a while(and just made) for shortening the long java print statements. It saves 29 bytes and that was just with 3 system.out.print() calls in the original. I've marked this one as non-competetive since the lib was made after the challenge was posted. Also, I don't know if we are allowed to use cheap little tricks like this and I felt bad about it. (Although in a way its fair since java has the longest print statements of any language I know).

Ashwin Gupta

Posted 2016-02-03T07:41:55.143

Reputation: 471

0

Java 8, 184 194 bytes

(just to add void r() as mentioned in the comments)

void r(){IntStream.rangeClosed(1,100).mapToObj(i->IntStream.range(0,i).mapToObj(j->"_"+j).collect(Collectors.joining(",","class Tuple"+i+" {public Object ",";}"))).forEach(System.out::println);}

Ungolfed

void r(){ IntStream.rangeClosed(1, 100)
    .mapToObj(i -> IntStream.range(0, i).mapToObj(j -> "_" + j)
        .collect(Collectors.joining(",", "class Tuple" + i + " {public Object ", ";}")))
    .forEach(System.out::println); }

h.j.k.

Posted 2016-02-03T07:41:55.143

Reputation: 589

This code isn't even in a function or anything... You need to add like void r(){ around it } – Ashwin Gupta – 2016-02-04T04:02:35.057

Np. Why is your "," seperate from your "_" if the are right next to each other when you print? You may be able to cut some bytes by using this string: ",_" – Ashwin Gupta – 2016-02-04T04:43:12.933

@AshwinGupta "," is used as a delimiter for a Stream<String> of _0 _1 _2.... If I'm going to used ",_" as the delimiter, the mapToObj() conversion is longer (String::valueOf), and I'll need an additional _ at the end of " {public Object " to handle that. – h.j.k. – 2016-02-04T05:35:22.227

1oh okay I didn't know that. I'm a begginer programmer really. I just noticed. – Ashwin Gupta – 2016-02-04T05:36:26.103

0

Brachylog, 99 bytes

0:99eI+1=J,[J]:"class Tuple~w {public Object "w,(I{:0reI,(?I,F";";?'I,F","):"w~_"cr:[I]rw\};"}
"w\)

Fatalize

Posted 2016-02-03T07:41:55.143

Reputation: 32 976

0

Scala, 119 bytes

I'm new to Scala and to codegolf, so nothing fancy.

for(i<-1 to 100){print("class Tuple"+i+" {public Object "); for(j<-0 to i-2) print("_"+j+","); print("_"+(i-1)+";}\n")}

Try online

More readable version:

for (i <- 1 to 100) {
  print("class Tuple" + i + " {public Object ")
  for (j <- 0 to i - 2) print("_" + j + ",")
  print("_" + (i - 1) + ";}\n")
}

andreas nilsson

Posted 2016-02-03T07:41:55.143

Reputation: 1

0

Haskell, 131 bytes

Call j.

import Data.List
j=mapM_(\n->putStrLn("class Tuple"++show n++" {public Object _"++intercalate",_"(map show[0..n-1])++";}"))[1..100]

Leif Willerts

Posted 2016-02-03T07:41:55.143

Reputation: 1 060

0

BlitzMax, 81 bytes

While i<100s$:+",_"+i i:+1Print"class Tuple"+i+" {public Object "+s[1..]+";}"Wend

That's the whole program. Non-Strict and without a Framework, so I can use variables without declaration and Print without having to import StandardIO. The String slicing operator comes in handy here, since it allows me to easily remove the superfluous comma at the beginning of each Object list.

Ungolfed version

While i < 100
    s$ :+ ",_" + i
    i :+ 1
    Print "class Tuple" + i + " {public Object " + s[1..] + ";}"
Wend

FireballStarfish

Posted 2016-02-03T07:41:55.143

Reputation: 91

0

Haskell, 102 bytes

putStr$[0..99]>>= \a->"class Tuple"++show(a+1)++" {public Object _0"++([1..a]>>=(",_"++).show)++";}\n"

As a program (107 bytes):

main=putStr$[0..99]>>= \a->"class Tuple"++show(a+1)++" {public Object _0"++([1..a]>>=(",_"++).show)++";}\n"

Explanation

putStr$ -- print it all
  [0..99]>>= \a->                 -- For each a from 0 to 99, make the
                                  -- following string, then concat
                                  -- it all together

    "class Tuple" ++ show (a + 1) -- class name (starts at Tuple1)

    ++" {public Object _0"        -- All Tuple classes start with a _0

    ++([1..a]>>=(",_"++).show)    -- If we're on TupleA,
                                  -- concat together ",_1", ",_2", etc.
                                  -- up to "_A"

    ++";}\n"

Reimu

Posted 2016-02-03T07:41:55.143

Reputation: 11

0

Python 3, 96 bytes

r=range
for i in r(1,101):print('class Tuple%d {public Object _0'%i,*r(1,i),sep=',_',end=';}\n')

Joining its expanded positional arguments from *range(1,i) using a custom separator ,_ and ending each line with ;}, Python 3's print() function happily does the job almost entirely on its own.

Greg

Posted 2016-02-03T07:41:55.143

Reputation: 491

0

Javascript ES6, 128 122 chars

for(s="class Tuple1 {public Object _0;}",q=0;q++<100;s=s.replace(/\d+(?!\d|,)( )?/g,(m,s)=>[q+1+s][+s]||m+",_"+q))alert(s)

Qwertiy

Posted 2016-02-03T07:41:55.143

Reputation: 2 697

0

Kotlin, 92 Bytes

fun j(){var s="_0";for(i in 1..100){println("class Tuple$i {public Object $s;}");s+=",_"+i}}

Try it online!

Ungolfed

fun j(){
    var s = "_0"
    for(i in 1..100){
        println("class Tuple$i {public Object $s;}")
        s+=",_"+i
    }   
}

The_Lone_Devil

Posted 2016-02-03T07:41:55.143

Reputation: 191

-1

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;
    }
}

}

user49916

Posted 2016-02-03T07:41:55.143

Reputation: 1

2You need to import System or use System.out. – mbomb007 – 2016-02-04T21:48:32.767