Skip to content

Commit 342b5b3

Browse files
committed
logic-2 added
1 parent 57b02ba commit 342b5b3

9 files changed

+141
-0
lines changed

logic-2/blackjack.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public int blackjack(int a, int b) {
2+
if( a > 21 && b > 21) {
3+
return 0;
4+
} else if ( a > 21 && b <= 21){
5+
return b;
6+
} else if ( b > 21 && a <= 21){
7+
return a;
8+
} else if(a > b && a <= 21){
9+
return a;
10+
} else if( b > a && b <= 21) {
11+
return b;
12+
} else {
13+
return a;
14+
}
15+
}
16+

logic-2/closeFar.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public boolean closeFar(int a, int b, int c) {
2+
int ab = Math.abs(a-b);
3+
int bc = Math.abs(b-c);
4+
int ac = Math.abs(a-c);
5+
6+
if(ab <= 1){
7+
return bc >=2 && ac >=2;
8+
} else if(bc <= 1) {
9+
return ab >= 2 && ac >= 2;
10+
} else if(ac <= 1) {
11+
return ab >= 2 && bc >= 2;
12+
} else {
13+
return false;
14+
}
15+
}
16+

logic-2/evenlySpaced.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public boolean evenlySpaced(int a, int b, int c) {
2+
int smallest = Math.min(a, Math.min(b, c));
3+
int largest = Math.max(a, Math.max(b,c));
4+
5+
int medium = a;
6+
7+
if(largest == b){
8+
if(smallest == a){
9+
medium = c;
10+
} else {
11+
medium = a;
12+
}
13+
} else if (largest == c){
14+
if(smallest == a){
15+
medium = b;
16+
} else {
17+
medium = a;
18+
}
19+
} else {
20+
if(smallest == b){
21+
medium = c;
22+
} else {
23+
medium = b;
24+
}
25+
}
26+
27+
if(Math.abs(smallest-medium) == Math.abs(largest-medium)){
28+
return true;
29+
} else {
30+
return false;
31+
}
32+
33+
}

logic-2/loneSum.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public int loneSum(int a, int b, int c) {
2+
if(a == b && b == c && a == c) {
3+
return 0;
4+
} else if(a == c){
5+
return b;
6+
} else if(a == b){
7+
return c;
8+
} else if(b == c){
9+
return a;
10+
} else {
11+
return a + b + c;
12+
}
13+
}
14+

logic-2/luckySum.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public int luckySum(int a, int b, int c) {
2+
if(a == 13){
3+
return 0;
4+
} else if(b == 13){
5+
return a;
6+
} else if(c == 13){
7+
return a + b;
8+
} else {
9+
return a + b + c;
10+
}
11+
12+
}

logic-2/makeBricks.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public boolean makeBricks(int small, int big, int goal) {
2+
if(big * 5 + small < goal || goal % 5 > small){
3+
return false;
4+
}
5+
return true;
6+
}
7+

logic-2/makeChocolate.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public int makeChocolate(int small, int big, int goal) {
2+
3+
while(big > 0 && goal >= 5){
4+
goal -= 5;
5+
big--;
6+
}
7+
8+
if(small >= goal){
9+
return goal;
10+
} else {
11+
return -1;
12+
}
13+
14+
}
15+

logic-2/noTeenSum.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public int noTeenSum(int a, int b, int c) {
2+
return fixTeen(a) + fixTeen(b) + fixTeen(c);
3+
}
4+
5+
public int fixTeen(int n) {
6+
if(n == 15){
7+
return 15;
8+
} else if(n == 16){
9+
return 16;
10+
} else if(n > 12 && n < 20){
11+
return 0;
12+
} else {
13+
return n;
14+
}
15+
}

logic-2/roundSum.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public int roundSum(int a, int b, int c) {
2+
return round10(a) + round10(b) + round10(c);
3+
}
4+
5+
public int round10(int num){
6+
int remainder = num % 10;
7+
num -= remainder;
8+
if (remainder >= 5) {
9+
num += 10;
10+
}
11+
return num;
12+
}
13+

0 commit comments

Comments
 (0)