Skip to main content
deleted 1 character in body
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63

Java: 204 183 182 176 175 characters - 10 - 50 = 115

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28<i?-1:1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28<i?-1:1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100% and the probability of getting -1 is 0%. If i is 28, the opposite to that will happen.

Third, by replacing the " "32 at the end by "_"'_' to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Java: 204 183 182 176 175 characters - 10 - 50 = 115

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28<i?-1:1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28<i?-1:1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100% and the probability of getting -1 is 0%. If i is 28, the opposite to that will happen.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Java: 204 183 182 176 175 characters - 10 - 50 = 115

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28<i?-1:1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28<i?-1:1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100% and the probability of getting -1 is 0%. If i is 28, the opposite to that will happen.

Third, by replacing the 32 at the end by '_' to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

-1 char
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63

Java: 204 183 182 176176 175 characters - 10 - 50 = 118115

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28>=i*28<i?-1:-1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28>=i*28<i?-1:-1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100% and the probability of getting -1 is 0%. If i is 28, the probability of getting +1 is 0%opposite to that will happen.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Java: 204 183 182 176 characters - 10 - 50 = 118

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28>=i?1:-1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28>=i?1:-1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100%. If i is 28, the probability of getting +1 is 0%.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Java: 204 183 182 176 175 characters - 10 - 50 = 115

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28<i?-1:1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28<i?-1:1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100% and the probability of getting -1 is 0%. If i is 28, the opposite to that will happen.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

6 chars less
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63

Java: 204 183 182182 176 characters - 10 - 50 = 122118

class K{public static void main(String[]y){int k,jj=0,i=(int)(29*Math.random());for(j=0;j<30;j++,i+=Math;j++<30;i+=Math.random()*28>=i?1:-1)for(k=0;k<31;k++)System.out.print(k>29?"\n"10:k==i?"'."':" "32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the puroposespurposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferedpreferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(j=0;j<29;j++;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28>=i?1:-1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100%. If i is 28, the probability of getting +1 is 0%.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks forto @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Java: 204 183 182 characters - 10 - 50 = 122

class K{public static void main(String[]y){int k,j,i=(int)(29*Math.random());for(j=0;j<30;j++,i+=Math.random()*28>=i?1:-1)for(k=0;k<31;k++)System.out.print(k>29?"\n":k==i?".":" ");}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the puroposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally prefered if it would be normally distributed around 14, but my answer would be longer:

i=0;for(j=0;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28>=i?1:-1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100%. If i is 28, the probability of getting +1 is 0%.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks for @VadimR for pointing out a misunderstanding in a prior version.

Java: 204 183 182 176 characters - 10 - 50 = 118

class K{public static void main(String[]y){int k,j=0,i=(int)(29*Math.random());for(;j++<30;i+=Math.random()*28>=i?1:-1)for(k=0;k<31;k++)System.out.print(k>29?10:k==i?'.':32);}} 

First, the dot position must be 0 < x < 30, i.e. [1-29]. This generates a number between 0 and 28 uniformly distributed, and for the purposes of this program [0-28] has the same effect as [1-29]:

i=(int)(29*Math.random()); 

I personally preferred if it would be normally distributed around 14, but my answer would be longer:

i=0;for(;j<29;j++)i+=(int)(2*Math.random()); 

Second, this code ensures that it tends to be in the middle:

i+=Math.random()*28>=i?1:-1 

The probability to get +1 is larger as smaller is the value of i, and we have the opposite for -1. If i is 0, the probability of getting +1 is 100%. If i is 28, the probability of getting +1 is 0%.

Third, by replacing the " " at the end by "_" to see the output easier, we see that each line has 30 characters plus a new line:

__________.___________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ ________._____________________ _________.____________________ ________._____________________ _________.____________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ __________.___________________ _________.____________________ __________.___________________ ___________.__________________ ____________._________________ _____________.________________ ____________._________________ _____________.________________ ______________._______________ _____________.________________ ______________._______________ _______________.______________ ______________._______________ _____________.________________ 

Thanks to @VadimR (now, user2846289) for pointing out a misunderstanding in a prior version.

Thanks to @KevinCruijssen for shaving out 6 characters, even after more than two and a half years after this answer was initially posted.

Fixed bug
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63
Loading
shaving 1 char
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63
Loading
added 20 characters in body
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63
Loading
added 20 characters in body
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63
Loading
Source Link
Victor Stafusa
  • 8.8k
  • 5
  • 42
  • 63
Loading