Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package adventofcode;
  2.  
  3.  
  4. import java.io.IOException;
  5. import java.nio.file.FileSystems;
  6. import java.nio.file.Files;
  7. import java.nio.file.Path;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.List;
  11.  
  12. public class Day1 {
  13.  
  14.     public static int solutionOne() {
  15.  
  16.         List<String> frequencies = Collections.emptyList();
  17.         Path path = FileSystems.getDefault().getPath("input.txt");
  18.         int frequency = 0;
  19.  
  20.         try {
  21.             frequencies = Files.readAllLines(path);
  22.         } catch (IOException e) {
  23.             // TODO Auto-generated catch block
  24.             e.printStackTrace();
  25.         }
  26.  
  27.         for (String freq : frequencies) {
  28.             frequency += Integer.parseInt(freq);
  29.         }
  30.  
  31.         return frequency;
  32.     }
  33.  
  34.     public static Integer solutionTwo() {
  35.  
  36.         List<String> frequencies = Collections.emptyList();
  37.         List<Integer> freqs = new ArrayList<>();
  38.         Path path = FileSystems.getDefault().getPath("input.txt");
  39.         int frequency = 0;
  40.  
  41.         try {
  42.             frequencies = Files.readAllLines(path);
  43.         } catch (IOException e) {
  44.             // TODO Auto-generated catch block
  45.             e.printStackTrace();
  46.         }
  47.  
  48.         for (String freq : frequencies) {
  49.             freqs.add(frequency);
  50.             frequency += Integer.parseInt(freq);
  51.         }
  52.  
  53.         while (true) {
  54.  
  55.             for (String freq : frequencies) {
  56.                 frequency += Integer.parseInt(freq);
  57.                 if (freqs.contains(frequency)) {
  58.                     return frequency;
  59.                 }
  60.             }
  61.         }
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement