Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package Advent2019;
  2.  
  3. import util.AdventOfCode;
  4.  
  5. import java.util.List;
  6.  
  7. public class Day8 extends AdventOfCode {
  8.    
  9.     int[] pixels;
  10.     int[][] matrix = new int[6][25];
  11.  
  12.     public Day8(List<String> input) {
  13.         super(input);
  14.     }
  15.  
  16.     @Override
  17.     public Object part1() {
  18.         int max = 0;
  19.         int min = 999;
  20.         for (int i = 0; i < pixels.length; i = i + 150) {
  21.             int onecount = 0;
  22.             int twocount = 0;
  23.             int zerocount = 0;
  24.             for (int j = 0; j < 150; j++) {
  25.                 if (pixels[i + j] == 0) zerocount++;
  26.                 if (pixels[i + j] == 1) onecount++;
  27.                 if (pixels[i + j] == 2) twocount++;
  28.  
  29.             }
  30.             if (zerocount < min)  {
  31.                 min = zerocount;
  32.                 max = onecount * twocount;
  33.             }
  34.         }
  35.         return max;
  36.     }
  37.  
  38.     void show() {
  39.         for (int i = 0; i < 6; i++) {
  40.             for (int j = 0; j < 25; j++) {
  41.                 System.out.print(matrix[i][j] == 1 ? '█' : ' ');
  42.             }
  43.             System.out.println();
  44.         }
  45.     }
  46.     void fill() {
  47.         for (int i = 0; i < 6; i++) {
  48.             for (int j = 0; j < 25; j++) {
  49.                 matrix[i][j] = 2;
  50.             }
  51.             System.out.println();
  52.         }
  53.     }
  54.     @Override
  55.     public Object part2() {
  56.         fill();
  57.         for (int i = 0; i < pixels.length; i+= 150) {
  58.             for (int j = 0; j < 150; j++) {
  59.                 int col = j / 25;
  60.                 int row = j % 25;
  61.                 if (matrix[col][row] == 2) {
  62.                     matrix[col][row] = pixels[i + j];
  63.                 }
  64.             }
  65.         }
  66.         show();
  67.         return 0;
  68.     }
  69.  
  70.     @Override
  71.     public void parse() {
  72.         pixels = input.get(0).chars()
  73.                 .boxed()
  74.                 .mapToInt(x -> x - '0')
  75.                 .toArray();
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement