Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.File;
- import java.util.Scanner;
- public class MainB
- {
- public static void main(String[] args) throws Exception {
- File file = new File("C:\\Users\\Jack\\Desktop\\ADVENT OF CODE\\DAY2\\input.txt");
- Scanner sc = new Scanner(file);
- String[] arr = sc.nextLine().split(",");
- int[] intArray = new int[arr.length];
- for(int x = 0; x <= 99; x++) {
- for(int y = 0; y <= 99; y++)
- {
- for (int i = 0; i < arr.length; i++) {
- intArray[i] = Integer.parseInt(arr[i]);
- }
- int count = 0;
- intArray[1] = x;
- intArray[2] = y;
- while (count + 3 < intArray.length ) {
- if (intArray[count] == 1) {
- if (intArray[count + 1] <= intArray.length && intArray[count + 2] <= intArray.length && intArray[count + 3] <= intArray.length)
- {
- intArray[intArray[count + 3]] = intArray[intArray[count + 1]] + intArray[intArray[count + 2]];
- }
- } else if(intArray[count] == 2)
- {
- if (intArray[count + 1] <= intArray.length && intArray[count + 2] <= intArray.length && intArray[count + 3] <= intArray.length)
- {
- intArray[intArray[count + 3]] = intArray[intArray[count + 1]] * intArray[intArray[count + 2]];
- }
- }else if(intArray[count] == 99)
- {
- break;
- }
- count = count + 4;
- }
- if (intArray[0] == 19690720) {
- System.out.println("The noun is " + x + " and the verb is " + y);
- System.out.println("The answer is " + (x*100+y));
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement