Problem:
You have a blue lottery ticket, with ints a, b, and c on it. This makes three pairs, which we'll call ab, bc, and ac. Consider the sum of the numbers in each pair. If any pair sums to exactly 10, the result is 10. Otherwise if the ab sum is exactly 10 more than either bc or ac sums, the result is 5. Otherwise the result is 0.
blueTicket(9, 1, 0) → 10
blueTicket(9, 2, 0) → 0
blueTicket(6, 1, 4) → 10
Solution:
public int blueTicket(int a, int b, int c) { int ab = a + b; int bc = b + c; int ac = a + c; if (ab == 10 || bc == 10 || ac == 10) return 10; if (ab - bc == 10 || ab - ac == 10) return 5; else return 0; }
public int blueTicket(int a, int b, int c) {
ReplyDeleteint ab = a + b;
int bc = b + c;
int ac = a + c;
int abbc = ab - bc;
int abac = ab - ac;
return ab == 10 || bc == 10 || ac == 10 ? 10 : abbc == 10 || abac == 10? 5 : 0;
}
public int blueTicket(int a, int b, int c) {
ReplyDeletereturn (a + b == 10 || b + c == 10 || c + a == 10)? 10 : (a == c + 10 || b == c + 10)? 5 : 0;
}
public int blueTicket(int a, int b, int c) {
ReplyDeleteif (a + b == 10 || b + c == 10 || c + a == 10){
return 10;
}
if(a == c + 10 || b == c + 10){
return 5;
}
return 0;
}
public int blueTicket(int a, int b, int c) {
ReplyDeletereturn a+b==10 || b+c==10 || c+a==10 ? 10 : (a==b+10 || a==b-10) ? 5 : (b==c+10 || b==c-10) ? 5 : a==c+10 || a==c-10 ? 5:0 ;
}