redTicket challenge

gudii9
gudii9 used Ask the Experts™
on
Hi,
I am working on below challenge
http://codingbat.com/prob/p170833
I tried my code as below
public int redTicket(int a, int b, int c) {

if((a==2)||(b==2)||(c==2))
{
return 10;
}

else{

if((a==b)&&(b==c)){
return 5;
}

else if((b!=a)&&(c!=a)){
return 5;
}
}

return 10;

  
}

Open in new window

I am getting below result
Expected      Run            
redTicket(2, 2, 2) → 10      10      OK         
redTicket(2, 2, 1) → 0      10      X         
redTicket(0, 0, 0) → 5      5      OK         
redTicket(2, 0, 0) → 1      10      X         
redTicket(1, 1, 1) → 5      5      OK         
redTicket(1, 2, 1) → 0      10      X         
redTicket(1, 2, 0) → 1      10      X         
redTicket(0, 2, 2) → 1      10      X         
redTicket(1, 2, 2) → 1      10      X         
redTicket(0, 2, 0) → 0      10      X         
redTicket(1, 1, 2) → 0      10      X         
other tests
X         

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®
return a+b+c==6?10:(a==b)&&(b==c)?5:b!=a&&c!=a?1:0;

Open in new window

as this is a challenge it should be done by yourself.
But as a hint, what about adding some console.log() statements to see, where it is and what decision it is taking?
awking00Information Technology Specialist
Commented:
return a==2&&b==2&&c==2 ? 10 : a==b&&a==c ? 5 : a!=b&&a!=c ? 1 : 0;

Author

Commented:
public int redTicket(int a, int b, int c) {

if((a==2)&&(b==2)&&(c==2))
{
return 10;
}



else if((a==b)&&(b==c)){
return 5;
}

else if((b!=a)&&(c!=a)){
return 1;
}


return 0;

  
}

Open in new window


Expected	Run		
redTicket(2, 2, 2) → 10	10	OK	    
redTicket(2, 2, 1) → 0	0	OK	    
redTicket(0, 0, 0) → 5	5	OK	    
redTicket(2, 0, 0) → 1	1	OK	    
redTicket(1, 1, 1) → 5	5	OK	    
redTicket(1, 2, 1) → 0	0	OK	    
redTicket(1, 2, 0) → 1	1	OK	    
redTicket(0, 2, 2) → 1	1	OK	    
redTicket(1, 2, 2) → 1	1	OK	    
redTicket(0, 2, 0) → 0	0	OK	    
redTicket(1, 1, 2) → 0	0	OK	    
other tests
OK	    

Open in new window

i wrote similar to above more expanded code which passed all tests now.
main Mistake i did was used || instead of &&

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