adds work files and binaries for day 3 solutions TAKE TWO
This commit is contained in:
parent
bcdd418b93
commit
e71eb74bab
6 changed files with 94 additions and 1 deletions
BIN
2022/day03/BadgeCheck.class
Normal file
BIN
2022/day03/BadgeCheck.class
Normal file
Binary file not shown.
34
2022/day03/BadgeCheck.java
Normal file
34
2022/day03/BadgeCheck.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
import java.util.Scanner;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BadgeCheck {
|
||||
public static void main (String[] args) {
|
||||
String bag1, bag2, bag3 = new String();
|
||||
int prioritySum = 0;
|
||||
|
||||
try (Scanner inputLine = new Scanner(Paths.get("input.txt"))) {
|
||||
while (inputLine.hasNext()) {
|
||||
bag1 = inputLine.nextLine();
|
||||
bag2 = inputLine.nextLine();
|
||||
bag3 = inputLine.nextLine();
|
||||
boolean breakFlag = false;
|
||||
for (int i = 0; i < bag1.length() && breakFlag == false; i++) {
|
||||
for (int j = 0; j < bag2.length() && breakFlag == false; j++) {
|
||||
if (bag1.charAt(i) == bag2.charAt(j)) {
|
||||
for (int k = 0; k < bag3.length() && breakFlag == false; k++) {
|
||||
if (bag2.charAt(j) == bag3.charAt(k)) {
|
||||
prioritySum += PriorityScore.score(bag3.charAt(k));
|
||||
breakFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.printf("Total score for matching chars is: %d", prioritySum);
|
||||
}
|
||||
}
|
BIN
2022/day03/BagCheck.class
Normal file
BIN
2022/day03/BagCheck.class
Normal file
Binary file not shown.
BIN
2022/day03/PriorityScore.class
Normal file
BIN
2022/day03/PriorityScore.class
Normal file
Binary file not shown.
59
2022/day03/PriorityScore.java
Normal file
59
2022/day03/PriorityScore.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
public class PriorityScore {
|
||||
public static int score(char c) {
|
||||
switch (c) {
|
||||
case 'a': return 1;
|
||||
case 'b': return 2;
|
||||
case 'c': return 3;
|
||||
case 'd': return 4;
|
||||
case 'e': return 5;
|
||||
case 'f': return 6;
|
||||
case 'g': return 7;
|
||||
case 'h': return 8;
|
||||
case 'i': return 9;
|
||||
case 'j': return 10;
|
||||
case 'k': return 11;
|
||||
case 'l': return 12;
|
||||
case 'm': return 13;
|
||||
case 'n': return 14;
|
||||
case 'o': return 15;
|
||||
case 'p': return 16;
|
||||
case 'q': return 17;
|
||||
case 'r': return 18;
|
||||
case 's': return 19;
|
||||
case 't': return 20;
|
||||
case 'u': return 21;
|
||||
case 'v': return 22;
|
||||
case 'w': return 23;
|
||||
case 'x': return 24;
|
||||
case 'y': return 25;
|
||||
case 'z': return 26;
|
||||
case 'A': return 27;
|
||||
case 'B': return 28;
|
||||
case 'C': return 29;
|
||||
case 'D': return 30;
|
||||
case 'E': return 31;
|
||||
case 'F': return 32;
|
||||
case 'G': return 33;
|
||||
case 'H': return 34;
|
||||
case 'I': return 35;
|
||||
case 'J': return 36;
|
||||
case 'K': return 37;
|
||||
case 'L': return 38;
|
||||
case 'M': return 39;
|
||||
case 'N': return 40;
|
||||
case 'O': return 41;
|
||||
case 'P': return 42;
|
||||
case 'Q': return 43;
|
||||
case 'R': return 44;
|
||||
case 'S': return 45;
|
||||
case 'T': return 46;
|
||||
case 'U': return 47;
|
||||
case 'V': return 48;
|
||||
case 'W': return 49;
|
||||
case 'X': return 50;
|
||||
case 'Y': return 51;
|
||||
case 'Z': return 52;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
Build a function to return the priority int value of the input char, must be case sensitive
|
||||
Build a function to return the priority int value of the input char, must be case sensitive - do this in a separate class file since it'll probably be needed in P2
|
||||
|
||||
Main:
|
||||
Declare string bagContents
|
||||
|
|
Loading…
Reference in a new issue