aoc2024

Advent of Code 2024
Log | Files | Refs | README

commit edf606b9ef2669d72a7005c064489222248d4653
parent 594417f456226d37c3038c028292af6c5c162288
Author: Martin Ashby <martin@ashbysoft.com>
Date:   Wed,  1 Jan 2025 14:23:24 +0000

Day 12, pt1

Diffstat:
Aday12.txt | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday12_sample.txt | 10++++++++++
Asrc/main/java/day12_pt1.java | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 234 insertions(+), 0 deletions(-)

diff --git a/day12.txt b/day12.txt @@ -0,0 +1,140 @@ +VVVVVVVVVVVCCCCLLLLLLLLLLLLLLLLLSSSSFFFFFFFFFFFFHHHHHHHHHHHHLLLLLLLLLLLLMLPPPPPPPZZZZZGGGGGGNNNXXXXXXXFFFLLFVVCCCDDCCCYYYYYYYYYYYYYYYYYYCCCC +VVVVVVVVVVCCCCCCCCDLLLLLLLLLLLLSSSSFFFFFFFFFFFFFHHHHHHHHHHHHHLLLLLLLLLLLMLLLPPPPPZZZZZZGGGGGGNXXNNNXXFFFFFFFVVCCCCCCCCYCCYYYYYYYYYYYYYYYCCCC +VVVVVVVVCCCCCCCCDDDDLLLLLLLLLLLLSSSSFFFFFFFFFFFFHHHHHHHHHHHHHLLLLLLLLLLLLLLPPPPZZZZZZZZGGGGGNNNNNNNXFFFFFFFFFVCCCCCCCCCCCCYYYYYYYYYYYYYYYYCC +VVVVVVVVCCCCCCDDDDDDLLLLLLLLLLLLSSSFFFFFFFFFFFHHHHHHHHHHHHHHLLLLLLLLLLLLLLLPPPPZPZLZLLLLLLGNNNNNNNNNFFFFFFFFFVVCCCCCCCCCCCCYYYYYYYYYYYYYYYCC +VVVVVVVVCCPCDDDDDDDDDDLLLLLLLLLLSSSSSFFFFFFFFFHHHHHHHHHHHHHHLLLLLLLLLLLLNLLPPPPPPLLLLLLLLLGNNNNNNNNFFFFFFFFFFCCCCCCCCCCCCCCY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VVVVVVVVVVVVVVVVVVVVVYYYYKKKKKKOOOOOOUOOOOOOLDDDDDDMMMMMMMBBBBBBBBIIIIIIIIIIIIYYYYYYYYYGQGVVVVVVVVVCCCCCCPPPPPPKKKKKKKKKKKKHHHHHHH +VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKYYKKKKKKOOYOOOOOOIOOOVVVDMMMMMMMMMMMBBBBBBBIIIIIIIIIIIIYYYYYYYYYYQQVQQVVVVVVCCCCCCCPPPPKKKKKKKKKKKKKHHHHHHH +VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVKJYKKKKKTOOOOODDOOIOOVVVVVVVMMAMMMMMBBBBBBBBILIIIIIIIIIIIKYYYYYYYYQQQQQVVVCCCCCCCCCPPPPKKKKKKKKKKKKKHHHHHHHH +VVVVVVVVVVVVVVVVOVVVVVVVVVVVVVVVKKKKKKKKKAOKOODDOIIOVVVVVVVVVMAAMSSMBBBBBBBBILIIIIIIIIIIIKYYYYYYYQQQQQQQVVHHCCCCCCCBBPKKKKKKKKKKKKKKHHHHHHHH diff --git a/day12_sample.txt b/day12_sample.txt @@ -0,0 +1,10 @@ +RRRRIICCFF +RRRRIICCCF +VVRRRCCFFF +VVRCCCJFFF +VVVVCJJCFE +VVIVCCJJEE +VVIIICJJEE +MIIIIIJJEE +MIIISIJEEE +MMMISSJEEE diff --git a/src/main/java/day12_pt1.java b/src/main/java/day12_pt1.java @@ -0,0 +1,84 @@ +import java.nio.file.Files; +import java.nio.file.Path; +import java.io.IOException; +import java.util.*; +import java.util.stream.*; + +class day12_pt1 { + record Point(int x, int y) { + Point add(Vec v) { + return new Point(this.x + v.x, this.y + v.y); + } + } + record Vec(int x, int y) {} + static Vec[] DIRS = new Vec[]{ + new Vec(0, 1), + new Vec(1, 0), + new Vec(0, -1), + new Vec(-1, 0) + }; + public static void main(String[] args) throws IOException { + var grid = Files.readAllLines(Path.of(args[0])); + // iterate the grid. Recursively find regions and their perimeters. + var pts = new HashSet<Point>(); + var nRegions = 0; + var regions = new HashMap<Integer, HashSet<Point>>(); + int height = grid.size(); + int width = grid.get(0).length(); + for (int y=0; y<height; y++) { + for (int x=0; x<width; x++) { + var pt = new Point(x, y); + if (pts.contains(pt)) continue; + var region = expandRegion(grid, pt); + regions.put(nRegions++, region); + pts.addAll(region); + } + } + + var res = regions.entrySet().stream().mapToLong(e -> { + var region = e.getValue(); + var perim = perimeter(grid, region); + //System.out.printf("Region %d: size: %d perimeter: %d\n", e.getKey(), e.getValue().size(), perim); + return perim * region.size(); + }) + .sum(); + System.out.printf("Day 12, pt1: %d\n", res); + } + static long perimeter(List<String> grid, HashSet<Point> region) { + var val = gv(grid, region.stream().findFirst().get()); + return region.stream().mapToLong(p -> { + return Arrays.stream(DIRS).map(d -> p.add(d)) + .filter(pp -> gv(grid, pp) != val) + .count(); + }).sum(); + // return region.stream().mapToInt(p -> { + // var val = gv(grid, p); + // return Arrays.stream(DIRS) + // .map(d -> p.add(d)) + // .filter(pp -> gv(grid, pp) != val) + // .count(); + // }); + } + static HashSet<Point> expandRegion(List<String> grid, Point p) { + var res = new HashSet<Point>(); + expandRegionInternal(grid, p, gv(grid, p), res); + return res; + } + static void expandRegionInternal(List<String> grid, Point p, int val, HashSet<Point> region) { + if (region.contains(p)) return; + region.add(p); + Arrays.stream(DIRS).forEach(d -> { + var pp = p.add(d); + if (gv(grid, pp) == val) { + expandRegionInternal(grid, pp, val, region); + } + }); + } + static int gv(List<String> grid, Point p) { + var height = grid.size(); + if (p.y < 0 || p.y >= height) return -1; + var width = grid.get(0).length(); + if (p.x < 0 || p.x >= width) return -1; + return grid.get(p.y).charAt(p.x); + } +}