# withoutDoubles challenge

Hi,

I am working on below challenge
http://codingbat.com/prob/p115233

I tried my code as below
``````public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles==false){
return die1+die2;
}

else if(die1==die2){
return die1+die2+1;

}
else
return 1;
}
``````

I am getting below result
Expected      Run
withoutDoubles(2, 3, true) → 5      1      X
withoutDoubles(3, 3, true) → 7      7      OK
withoutDoubles(3, 3, false) → 6      6      OK
withoutDoubles(2, 3, false) → 5      5      OK
withoutDoubles(5, 4, true) → 9      1      X
withoutDoubles(5, 4, false) → 9      9      OK
withoutDoubles(5, 5, true) → 11      11      OK
withoutDoubles(5, 5, false) → 10      10      OK
withoutDoubles(6, 6, true) → 7      13      X
withoutDoubles(6, 6, false) → 12      12      OK
withoutDoubles(1, 6, true) → 7      1      X
withoutDoubles(6, 1, false) → 7      7      OK
other tests
OK

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
JavaProgrammingJava EEProgramming Languages-Other

Last Comment
gudii9
krakatoa

iirc, you already did this challenge quite a while ago.

?
ozo

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
gudii9

``````public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
return die1+die2%6+1;
}

else
return die1+die2;
}
``````

above passed all cases as you mentioned.

My question is can i write as below as well?

``````public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
return die1%6+die2+1;
}

else
return die1+die2;
}
``````

which is best approach ?

die1%6 approach or die1%6 approach?
does it vary results if i change approach to  die1%6
gudii9

``````public int withoutDoubles(int die1, int die2, boolean noDoubles) {

if(noDoubles && die1==die2){
return die1%6+die2+1;
}

else
return die1+die2;
}
``````

apparently above also passed all tests??
ozo

die1%6 approach or die1%6 approach?
looks the same to me
gudii9

wrapping around to 1 if its value was 6.

but challenge did not mention die1 or die2? i wonder which one to take ideally?
gudii9

withoutDoubles(6, 5, true) →

withoutDoubles(6, 5, false) →

withoutDoubles(5, 6, true) →

withoutDoubles(5, 6, false) →

what results we get in above 4 cases ?

ozo

In above 4 cases, the two dice do not show the same value, so just return the sum.
gudii9

oops i missed the point that both dies needs to be equal to do
die1%6+die2+1
then it really does not matter die1%6 or die2%6.

How to read and comprehend challenge correctly first time itself like you people?
it is some times taking many times of going over to understand the depth and width of the challenge?
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY