NilsKirchhoff

AoC 2017 - Day 1

Dec 1st, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class Day1 {
  2.  
  3.     public static void main(String[] args) {
  4.         // First problem of the day
  5.        
  6.  
  7.         String capcha = " //YOUR CAPCHA CODE GOES HERE //";
  8.         int summe = 0;
  9.         int length = capcha.length();
  10.         for(int i=1; i<length; i++) {
  11.             if ((capcha.charAt(i)-'0') == (capcha.charAt(i-1)-'0')) {
  12.                 summe = summe + (capcha.charAt(i)-'0');
  13.             }
  14.             if ((i+1) == length) {
  15.                 if ((capcha.charAt(i)-'0') == (capcha.charAt(0)-'0'))
  16.                 summe = summe + (capcha.charAt(0)-'0');
  17.             }
  18.         }
  19.         System.out.println("Capcha 1:" + summe);
  20.        
  21.         // Second problem of the day
  22.         for(int i=0; i<length; i++) {
  23.             int j= 0;
  24.             if ( i + ( length/2 ) >= length )
  25.                 j = i - length/2;
  26.             else
  27.                 j = i + length/2;
  28.             if ((capcha.charAt(i)-'0') == (capcha.charAt(j)-'0'))
  29.             summe = summe + (capcha.charAt(i)-'0');
  30.         }
  31.         System.out.println("Capcha 2:" + summe);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment