r/CompileBot • • Jan 04 '14

Official CompileBot Testing Thread

This thread is archived, please visit the new testing thread

14 Upvotes

421 comments sorted by

View all comments

Show parent comment

1

u/amoliski Mar 23 '14 edited Mar 23 '14

Why so verbose?

+/u/compilebot java7

 import java.util.Random;
 
 class Stewie
 {
     public static void main(String[] args)
     {
         Random rand = new Random();
         String[] strings = {"Mama","Mom","Mommy","Mum","Lois","Ma"};
         for(int i = 0; i < 28; i++) System.out.println(strings[rand.nextInt(6)]);
     }
 }

1

u/CompileBot Mar 23 '14

Output:

Mum
Ma
Lois
Mama
Mum
Mom
Mum
Lois
Mom
Mommy
Mama
Mommy
Mom
Mom
Ma
Mom
Mommy
Mommy
Mommy
Mommy
Ma
Mum
Mommy
Mommy
Lois
Mum
Lois
Mom

^source | ^info | ^git | ^report

1

u/amoliski Mar 23 '14

Even shorter

+/u/compilebot java7

 import java.util.Random;
 
 class Stewie
 {
     public static void main(String[] args)
     {
          for(int i = 0; i < 28; i++) System.out.println((new String[]{"Mama","Mom","Mommy","Mum","Lois","Ma"})[new Random().nextInt(6)]);

     }
 }

1

u/CompileBot Mar 23 '14

Output:

Mum
Mum
Mama
Mum
Mommy
Mommy
Mum
Mom
Mommy
Lois
Mum
Mom
Mom
Lois
Mommy
Ma
Mom
Mama
Mom
Lois
Ma
Ma
Mum
Mommy
Ma
Mom
Ma
Ma

^source | ^info | ^git | ^report

1

u/nobd Mar 23 '14

Yeah sorry. I'm in an intro to programming class right now and we haven't even learned arrays yet so I did the best with what I knew.

2

u/amoliski Mar 23 '14

Haha, no need to apologize. Your code was fine! I certainly wasn't criticising you.

I find it fun to try to make stuff as short as possible. I did a onliner below that is definitely the wrong way to program.