withoutDoubles  challenge

gudii9
gudii9 used Ask the Experts™
on
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;
}

Open in new window


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?
 Please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
iirc, you already did this challenge quite a while ago.

?
Most Valuable Expert 2014
Top Expert 2015
Commented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {
  return noDoubles&&die1==die2?
         die1+die2%6+1
         :
         die1+die2;        
}

Author

Commented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {

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

Open in new window



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

Open in new window



which is best approach ?

die1%6 approach or die1%6 approach?
does it vary results if i change approach to  die1%6
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
public int withoutDoubles(int die1, int die2, boolean noDoubles) {

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

Open in new window


apparently above also passed all tests??
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
die1%6 approach or die1%6 approach?
looks the same to me

Author

Commented:
wrapping around to 1 if its value was 6.

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

Author

Commented:
withoutDoubles(6, 5, true) →

withoutDoubles(6, 5, false) →

withoutDoubles(5, 6, true) →

withoutDoubles(5, 6, false) →

what results we get in above 4 cases ?

please advise
ozo
Most Valuable Expert 2014
Top Expert 2015

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

Author

Commented:
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?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial