AccusationsInc

AOC day one solutions 2020

Nov 30th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //Solution for problem one
  2. for(int i = 0; i < data.size() - 1; i++) {
  3. for(int c = i + 1; c < data.size(); c++) {
  4. if(data.get(i) + data.get(c) == 2020) {
  5. int answer = data.get(i) * data.get(c);
  6. System.out.println("This is the solution for"
  7. + " problem one :: " + answer);
  8. }
  9. }
  10. }
  11. //solution for problem two
  12. for(int i = 0; i < data.size() - 2; i++) {
  13. for(int c = i + 1; c < data.size() - 1; c++) {
  14. for(int j = c + 1; j < data.size(); j++) {
  15. if((data.get(i) + data.get(c)) + data.get(j) == 2020) {
  16. int answer = data.get(i) * data.get(c) * data.get(j);
  17. System.out.println("This is the solution for"
  18. + " problem two :: " + answer);
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment