Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advent2019;
- import util.AdventOfCode;
- import java.util.List;
- public class Day8 extends AdventOfCode {
- int[] pixels;
- int[][] matrix = new int[6][25];
- public Day8(List<String> input) {
- super(input);
- }
- @Override
- public Object part1() {
- int max = 0;
- int min = 999;
- for (int i = 0; i < pixels.length; i = i + 150) {
- int onecount = 0;
- int twocount = 0;
- int zerocount = 0;
- for (int j = 0; j < 150; j++) {
- if (pixels[i + j] == 0) zerocount++;
- if (pixels[i + j] == 1) onecount++;
- if (pixels[i + j] == 2) twocount++;
- }
- if (zerocount < min) {
- min = zerocount;
- max = onecount * twocount;
- }
- }
- return max;
- }
- void show() {
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 25; j++) {
- System.out.print(matrix[i][j] == 1 ? '█' : ' ');
- }
- System.out.println();
- }
- }
- void fill() {
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 25; j++) {
- matrix[i][j] = 2;
- }
- System.out.println();
- }
- }
- @Override
- public Object part2() {
- fill();
- for (int i = 0; i < pixels.length; i+= 150) {
- for (int j = 0; j < 150; j++) {
- int col = j / 25;
- int row = j % 25;
- if (matrix[col][row] == 2) {
- matrix[col][row] = pixels[i + j];
- }
- }
- }
- show();
- return 0;
- }
- @Override
- public void parse() {
- pixels = input.get(0).chars()
- .boxed()
- .mapToInt(x -> x - '0')
- .toArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement