#Java 8, (削除) 123 (削除ここまで)(削除) 149 (削除ここまで)(削除) 113 (削除ここまで) 108 bytes
Java 8, (削除) 123 (削除ここまで)(削除) 149 (削除ここまで)(削除) 113 (削除ここまで) 108 bytes
#Java 8, (削除) 123 (削除ここまで)(削除) 149 (削除ここまで)(削除) 113 (削除ここまで) 108 bytes
Java 8, (削除) 123 (削除ここまで)(削除) 149 (削除ここまで)(削除) 113 (削除ここまで) 108 bytes
- 136.2k
- 14
- 154
- 394
#Java 8, (削除) 123 (削除ここまで) (削除) 149 (削除ここまで) 113(削除) 113 (削除ここまで) 108 bytes
()->{for(int n=2,s=0n=0,e=7s=1,i;s!=e;n+=2,e+=7=n*7;){for(i=n,s=n;ii=s=++n*2;i-->0;s+=Math.randomrandom()*6);if(s!=e=n*7)SystemSystem.out.println(nn*2);}}
Or 112107 bytes if we use an Object null as unused parameter instead.
+26 bytes for a bug-fix, correctly pointed out by @Jules in the comments.
-3641 bytes thanks to @OliverGrégoire's great thinking!
()->{ // Method without parameter nor return-type
for(int n=2n=0, // Amount of dice, starting at 2
s=0s=1, // Sum
e=7, // Equals check integer, starting at 7 (<- 3.5*2)Sum
i; // Index
s!=e; =n*7;){ // Loop (1) as long as the sum isn'tdoesn't theequal same`n`*7,
as the equal-int
n+=2,e+=7){ // And add two dice after every iteration
// because we for(i=nroll the dice per two, and 3.5*2=7
for(i=s=++n*2; // Reset both the index and sum to `n``n`*2,
s=n; // And sum as well,// so we can use random 0-5, instead of 1-6
// soand we won't have to use `+1` at `Math.random()*6+1`*6`
i-->0; // Inner loop (2) over the amount of dice
s+=Math.randomrandom()*6 // And rollincrease themthe (randomly)sum with their random results
); // End of inner loop (2)
if(s!=e=n*7) // If the sum isn't the same as thedoesn't equal-int `n`*7
SystemSystem.out.println(nn*2); // Print the amount of dice for this iteration
} // End of loop (1)
} // End of method
#Java 8, (削除) 123 (削除ここまで) (削除) 149 (削除ここまで) 113 bytes
()->{for(int n=2,s=0,e=7,i;s!=e;n+=2,e+=7){for(i=n,s=n;i-->0;s+=Math.random()*6);if(s!=e)System.out.println(n);}}
Or 112 bytes if we use an Object null as unused parameter instead.
+26 bytes for a bug-fix, correctly pointed out by @Jules in the comments.
-36 bytes thanks to @OliverGrégoire's great thinking!
()->{ // Method without parameter nor return-type
for(int n=2, // Amount of dice, starting at 2
s=0, // Sum
e=7, // Equals check integer, starting at 7 (<- 3.5*2)
i; // Index
s!=e; // Loop (1) as long as sum isn't the same as the equal-int
n+=2,e+=7){ // And add two dice after every iteration
for(i=n, // Reset the index to `n`
s=n; // And sum as well, so we can use random 0-5 instead of 1-6
// so we won't have to use `Math.random()*6+1`
i-->0; // Inner loop (2) the amount of dice
s+=Math.random()*6 // And roll them (randomly)
); // End of inner loop (2)
if(s!=e) // If the sum isn't the same as the equal-int
System.out.println(n); // Print the amount of dice
} // End of loop (1)
} // End of method
#Java 8, (削除) 123 (削除ここまで) (削除) 149 (削除ここまで) (削除) 113 (削除ここまで) 108 bytes
()->{for(int n=0,s=1,i;s!=n*7;){for(i=s=++n*2;i-->0;s+=Math.random()*6);if(s!=n*7)System.out.println(n*2);}}
Or 107 bytes if we use an Object null as unused parameter instead.
+26 bytes for a bug-fix, correctly pointed out by @Jules in the comments.
-41 bytes thanks to @OliverGrégoire's great thinking!
()->{ // Method without parameter nor return-type
for(int n=0, // Amount of dice
s=1, // Sum
i; // Index
s!=n*7;){ // Loop (1) as long as the sum doesn't equal `n`*7,
// because we roll the dice per two, and 3.5*2=7
for(i=s=++n*2; // Reset both the index and sum to `n`*2,
// so we can use random 0-5, instead of 1-6
// and we won't have to use `+1` at `Math.random()*6`
i-->0; // Inner loop (2) over the amount of dice
s+=Math.random()*6 // And increase the sum with their random results
); // End of inner loop (2)
if(s!=n*7) // If the sum doesn't equal `n`*7
System.out.println(n*2); // Print the amount of dice for this iteration
} // End of loop (1)
} // End of method
#Java 8, 123(削除) 123 (削除ここまで)(削除) 149 (削除ここまで) 113 bytes
()->{for(int n=2,r=12s=0,i;fore=7,i;s!=e;n+=2,e+=7){for(r*=Mathi=n,s=n;i-->0;s+=Math.randomrandom()+2;r!=3.5*n;n+=2*6)for;if(Systems!=e)System.out.println(n),r=0,i=0;i++<n+2;r+=1+Math.random()*6);}}
Or 122112 bytes if we use an Object null as unused parameter instead.
+26 bytes for a bug-fix, correctly pointed out by @Jules in the comments.
-36 bytes thanks to @OliverGrégoire's great thinking!
()->{ // Method without parameter nor return-type
for(int n=2,r=12,i; // SomeAmount tempof integersdice, starting at 2
for s=0, // Sum
e=7, // Equals check integer, starting at 7 (r*=Math<- 3.random(5*2)+2; // Start byi; rolling two dice // Index
rs!=3.5*n;=e; // Loop (1) as long as sum isn't the sumsame `r`as doesn'tthe equal 3.5*`n`-int
n+=2,e+=7){ // And increase `n`add bytwo 2dice after every iteration
for(System.out.println(n)i=n, // PrintReset the index to `n`
r=0s=n; // And sum as well,i=0; so we can use random 0-5 instead of 1-6
// Reset `r`so andwe `i`won't have to 0use `Math.random()*6+1`
i++<n+2;i-->0; // Inner loop (2) the amount of dice + 2
r+=1+Maths+=Math.randomrandom()*6 // Roll each, andAnd addroll them to the sum `r`(randomly)
); // End of inner loop (2)
if(s!=e) // If the sum isn't the same as the equal-int
// End of loop System.out.println(1n); (implicit // single-line body) Print the amount of dice
} // End of loop (1)
} // End of method
Example run explanation:
- Start
nat 2 (int n=2) - Roll two dice at once, by picking a random number from 2-12 (
r=12andr*=Math.random()+2) - Check if this random number is equal to 3.5*
n(r!=3.5*n)- If it is 3.5*
n, leave the loop and we're done. - If it is not 3.5*
n: continue with step 4 below
- If it is 3.5*
- Print
n(System.out.println(n)) - Then roll
n+2dice again (by picking a random number from 1-6) and save them inr(for(...,r=0,i=0;i++<n+2;r+=1+Math.random()*6);) - And raise
nby 2 (n+=2) - And then get back to step 3 again by checking if
n(now 4) times 3.5 equalsr
#Java 8, 123 bytes
()->{int n=2,r=12,i;for(r*=Math.random()+2;r!=3.5*n;n+=2)for(System.out.println(n),r=0,i=0;i++<n+2;r+=1+Math.random()*6);}
Or 122 bytes if we use an Object null as unused parameter instead.
()->{ // Method without parameter nor return-type
int n=2,r=12,i; // Some temp integers
for(r*=Math.random()+2; // Start by rolling two dice
r!=3.5*n; // Loop (1) as long as the sum `r` doesn't equal 3.5*`n`
n+=2) // And increase `n` by 2 after every iteration
for(System.out.println(n), // Print `n`
r=0,i=0; // Reset `r` and `i` to 0
i++<n+2; // Inner loop (2) the amount of dice + 2
r+=1+Math.random()*6 // Roll each, and add them to the sum `r`
); // End of inner loop (2)
// End of loop (1) (implicit / single-line body)
} // End of method
Example run explanation:
- Start
nat 2 (int n=2) - Roll two dice at once, by picking a random number from 2-12 (
r=12andr*=Math.random()+2) - Check if this random number is equal to 3.5*
n(r!=3.5*n)- If it is 3.5*
n, leave the loop and we're done. - If it is not 3.5*
n: continue with step 4 below
- If it is 3.5*
- Print
n(System.out.println(n)) - Then roll
n+2dice again (by picking a random number from 1-6) and save them inr(for(...,r=0,i=0;i++<n+2;r+=1+Math.random()*6);) - And raise
nby 2 (n+=2) - And then get back to step 3 again by checking if
n(now 4) times 3.5 equalsr
#Java 8, (削除) 123 (削除ここまで)(削除) 149 (削除ここまで) 113 bytes
()->{for(int n=2,s=0,e=7,i;s!=e;n+=2,e+=7){for(i=n,s=n;i-->0;s+=Math.random()*6);if(s!=e)System.out.println(n);}}
Or 112 bytes if we use an Object null as unused parameter instead.
+26 bytes for a bug-fix, correctly pointed out by @Jules in the comments.
-36 bytes thanks to @OliverGrégoire's great thinking!
()->{ // Method without parameter nor return-type
for(int n=2, // Amount of dice, starting at 2
s=0, // Sum
e=7, // Equals check integer, starting at 7 (<- 3.5*2) i; // Index
s!=e; // Loop (1) as long as sum isn't the same as the equal-int
n+=2,e+=7){ // And add two dice after every iteration
for(i=n, // Reset the index to `n`
s=n; // And sum as well, so we can use random 0-5 instead of 1-6
// so we won't have to use `Math.random()*6+1`
i-->0; // Inner loop (2) the amount of dice
s+=Math.random()*6 // And roll them (randomly)
); // End of inner loop (2)
if(s!=e) // If the sum isn't the same as the equal-int
System.out.println(n); // Print the amount of dice
} // End of loop (1)
} // End of method
- 14.5k
- 3
- 33
- 56
- 136.2k
- 14
- 154
- 394