Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advent2018;
- import util.AdventOfCode;
- import util.QuickUnionUF;
- import util.UnionFind;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Day25 extends AdventOfCode {
- List<Point4d> points;
- class Point4d {
- int x;
- int y;
- int z;
- int u;
- Point4d(int x, int y, int z, int u) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.u = u;
- }
- Point4d(List<Integer> in) {
- this(in.get(0), in.get(1), in.get(2), in.get(3));
- }
- int dist(Point4d other) {
- return Math.abs(this.x - other.x) + Math.abs(this.y - other.y)
- + Math.abs(this.z - other.z) + Math.abs(this.u - other.u);
- }
- }
- public Day25(List<String> input) {
- super(input);
- }
- @Override
- public Object part1() {
- QuickUnionUF uf = new QuickUnionUF(points.size());
- for (int i = 0; i < points.size() - 1; i++) {
- for (int j = i + 1; j < points.size(); j++) {
- if (points.get(i).dist(points.get(j)) <= 3) {
- if (!uf.connected(i, j)) {
- uf.union(i, j);
- }
- }
- }
- }
- return uf.count();
- }
- @Override
- public Object part2() {
- return "Merry Christmas!!!";
- }
- @Override
- public void parse() {
- points = input.stream()
- .map(x -> Arrays.stream(x.split(","))
- .mapToInt(Integer::parseInt)
- .boxed()
- .collect(Collectors.toList()))
- .map(Point4d::new)
- .collect(Collectors.toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement