Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package adventofcode;
- import java.io.IOException;
- import java.nio.file.FileSystems;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- public class Day1 {
- public static int solutionOne() {
- List<String> frequencies = Collections.emptyList();
- Path path = FileSystems.getDefault().getPath("input.txt");
- int frequency = 0;
- try {
- frequencies = Files.readAllLines(path);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- for (String freq : frequencies) {
- frequency += Integer.parseInt(freq);
- }
- return frequency;
- }
- public static Integer solutionTwo() {
- List<String> frequencies = Collections.emptyList();
- List<Integer> freqs = new ArrayList<>();
- Path path = FileSystems.getDefault().getPath("input.txt");
- int frequency = 0;
- try {
- frequencies = Files.readAllLines(path);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- for (String freq : frequencies) {
- freqs.add(frequency);
- frequency += Integer.parseInt(freq);
- }
- while (true) {
- for (String freq : frequencies) {
- frequency += Integer.parseInt(freq);
- if (freqs.contains(frequency)) {
- return frequency;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement