Logic-2
public boolean makeBricks(int small, int big, int goal) {
if (big >= goal / 5 && small >= goal % 5) {
return true;
} else if (goal - big * 5 <= small && goal - big * 5 > 0) {
return true;
}
return false;
}
public int loneSum(int a, int b, int c) {
int sum = 0;
if (a != b && a != c) {
sum += a;
}
if (b != c && b != a) {
sum += b;
}
if (c != a && c != b) {
sum += c;
}
return sum;
}
public int luckySum(int a, int b, int c) {
int sum = 0;
if (a != 13) {
sum += a;
}
if (a != 13 && b != 13) {
sum += b;
}
if (a != 13 && b != 13 && c != 13) {
sum += c;
}
return sum;
}
public int noTeenSum(int a, int b, int c) {
int sum = 0;
if (a < 13 || a > 19) {
sum += a;
}
if (b < 13 || b > 19) {
sum += b;
}
if (c < 13 || c > 19) {
sum += c;
}
return sum + fixTeen(a) + fixTeen(b) + fixTeen(c);
}
public int fixTeen(int n) {
if (n == 15 || n == 16) {
return n;
} else return 0;
}
public int roundSum(int a, int b, int c) {
int sum = 0;
sum += round10(a);
sum += round10(b);
sum += round10(c);
return sum;
}
public int round10(int num) {
if (num % 10 >= 5) {
num += 10 - num % 10;
}
if (num % 10 < 5) {
num -= num % 10;
}
return num;
}
public boolean closeFar(int a, int b, int c) {
if (Math.abs(a - b) <= 1 && Math.abs(c - b) >= 2 && Math.abs(a - c) >= 2) {
return true;
}
if (Math.abs(a - c) <= 1 && Math.abs(b - a) >= 2 && Math.abs(b - c) >= 2) {
return true;
}
return false;
}
public int blackjack(int a, int b) {
if(Math.max(a,b) <= 21){
return Math.max(a,b);
}else if(Math.min(a,b) > 21){
return 0;
}
return Math.min(a,b);
}
public boolean evenlySpaced(int a, int b, int c) {
if (a == b && b == c) {
return true;
}
return max(a, b, c) - mid(a, b, c) == mid(a, b, c) - min(a, b, c);
}
public int max(int a, int b, int c) {
int max = 0;
if (a > b) {
max = a;
}
if (b > a) {
max = b;
}
if (c > a) {
max = c;
}
return max;
}
public int min(int a, int b, int c) {
int min = 0;
if (Math.min(a, b) > c) {
min = c;
}
if (Math.min(a, b) < c) {
min = Math.min(a, b);
}
return min;
}
public int mid(int a, int b, int c) {
int mid = 0;
mid = (a + b + c) - (max(a, b, c) + min(a, b, c));
return mid;
}
public int makeChocolate(int small, int big, int goal) {
if (big >= goal / 5 && small >= goal % 5) {
return goal % 5;
}
if (big <= goal / 5 && small >= goal - big * 5) {
return goal - big * 5;
}
return -1;
}
Last updated