Skip to content

Commit

Permalink
aoc 2024 day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCK committed Dec 1, 2024
1 parent 8d74f59 commit 206f8ca
Show file tree
Hide file tree
Showing 11 changed files with 2,110 additions and 65 deletions.
104 changes: 52 additions & 52 deletions adventofcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1422,59 +1422,59 @@
[20232402tests]: src/test/java/org/ck/adventofcode/year2023/Day24Test.java
[20232501tests]: src/test/java/org/ck/adventofcode/year2023/Day25Test.java

# 2024 (0/49)
# 2024 (2/49)

| # | Name | Solution | Test |
|---------:|--------------------------------|:------------------------------------:|:---------------------------------:|
| 20240101 | [Day 1: ?][20240101] | [💾][20240101solution] | [💾][20240101tests] |
| 20240102 | [Day 1: ? - Part 2][20240102] | [💾][20240102solution] | [💾][20240102tests] |
| 20240201 | [Day 2: ?][20240201] | [💾][20240201solution] | [💾][20240201tests] |
| 20240202 | [Day 2: ? - Part 2][20240202] | [💾][20240202solution] | [💾][20240202tests] |
| 20240301 | [Day 3: ?][20240301] | [💾][20240301solution] | [💾][20240301tests] |
| 20240302 | [Day 3: ? - Part 2][20240302] | [💾][20240302solution] | [💾][20240302tests] |
| 20240401 | [Day 4: ?][20240401] | [💾][20240401solution] | [💾][20240401tests] |
| 20240402 | [Day 4: ? - Part 2][20240402] | [💾][20240402solution] | [💾][20240402tests] |
| 20240501 | [Day 5: ?][20240501] | [💾][20240501solution] | [💾][20240501tests] |
| 20240502 | [Day 5: ? - Part 2][20240502] | [💾][20240502solution] | [💾][20240502tests] |
| 20240601 | [Day 6: ?][20240601] | [💾][20240601solution] | [💾][20240601tests] |
| 20240602 | [Day 6: ? - Part 2][20240602] | [💾][20240602solution] | [💾][20240602tests] |
| 20240701 | [Day 7: ?][20240701] | [💾][20240701solution] | [💾][20240701tests] |
| 20240702 | [Day 7: ? - Part 2][20240702] | [💾][20240702solution] | [💾][20240702tests] |
| 20240801 | [Day 8: ?][20240801] | [💾][20240801solution] | [💾][20240801tests] |
| 20240802 | [Day 8: ? - Part 2][20240802] | [💾][20240802solution] | [💾][20240802tests] |
| 20240901 | [Day 9: ?][20240901] | [💾][20240901solution] | [💾][20240901tests] |
| 20240902 | [Day 9: ? - Part 2][20240902] | [💾][20240902solution] | [💾][20240902tests] |
| 20241001 | [Day 10: ?][20241001] | [💾][20241001solution] | [💾][20241001tests] |
| 20241002 | [Day 10: ? - Part 2][20241002] | [💾][20241002solution] | [💾][20241002tests] |
| 20241101 | [Day 11: ?][20241101] | [💾][20241101solution] | [💾][20241101tests] |
| 20241102 | [Day 11: ? - Part 2][20241102] | [💾][20241102solution] | [💾][20241102tests] |
| 20241201 | [Day 12: ?][20241201] | [💾][20241201solution] | [💾][20241201tests] |
| 20241202 | [Day 12: ? - Part 2][20241202] | [💾][20241202solution] | [💾][20241202tests] |
| 20241301 | [Day 13: ?][20241301] | [💾][20241301solution] | [💾][20241301tests] |
| 20241302 | [Day 13: ? - Part 2][20241302] | [💾][20241302solution] | [💾][20241302tests] |
| 20241401 | [Day 14: ?][20241401] | [💾][20241401solution] | [💾][20241401tests] |
| 20241402 | [Day 14: ? - Part 2][20241402] | [💾][20241402solution] | [💾][20241402tests] |
| 20241501 | [Day 15: ?][20241501] | [💾][20241501solution] | [💾][20241501tests] |
| 20241502 | [Day 15: ? - Part 2][20241502] | [💾][20241502solution] | [💾][20241502tests] |
| 20241601 | [Day 16: ?][20241601] | [💾][20241601solution] | [💾][20241601tests] |
| 20241602 | [Day 16: ? - Part 2][20241602] | [💾][20241602solution] | [💾][20241602tests] |
| 20241701 | [Day 17: ?][20241701] | [💾][20241701solution] | [💾][20241701tests] |
| 20241702 | [Day 17: ? - Part 2][20241702] | [💾][20241702solution] | [💾][20241702tests] |
| 20241801 | [Day 18: ?][20241801] | [💾][20241801solution] | [💾][20241801tests] |
| 20241802 | [Day 18: ? - Part 2][20241802] | [💾][20241802solution] | [💾][20241802tests] |
| 20241901 | [Day 19: ?][20241901] | [💾][20241901solution] | [💾][20241901tests] |
| 20241902 | [Day 19: ? - Part 2][20241902] | [💾][20241902solution] | [💾][20241902tests] |
| 20242001 | [Day 20: ?][20242001] | [💾][20242001solution] | [💾][20242001tests] |
| 20242002 | [Day 20: ? - Part 2][20242002] | [💾][20242002solution] | [💾][20242002tests] |
| 20242101 | [Day 21: ?][20242101] | [💾][20242101solution] | [💾][20242101tests] |
| 20242102 | [Day 21: ? - Part 2][20242102] | [💾][20242102solution] | [💾][20242102tests] |
| 20242201 | [Day 22: ?][20242201] | [💾][20242201solution] | [💾][20242201tests] |
| 20242202 | [Day 22: ? - Part 2][20242202] | [💾][20242202solution] | [💾][20242202tests] |
| 20242301 | [Day 23: ?][20242301] | [💾][20242301solution] | [💾][20242301tests] |
| 20242302 | [Day 23: ? - Part 2][20242302] | [💾][20242302solution] | [💾][20242302tests] |
| 20242401 | [Day 24: ?][20242401] | [💾][20242401solution] | [💾][20242401tests] |
| 20242402 | [Day 24: ? - Part 2][20242402] | [💾][20242402solution] | [💾][20242402tests] |
| 20242501 | [Day 25: ?][20242501] | [💾][20242501solution] | [💾][20242501tests] |
| # | Name | Solution | Test |
|---------:|------------------------------------------------|:------------------------------------:|:---------------------------------:|
| 20240101 | [Day 1: Historian Hysteria][20240101] | ✅[💾][20240101solution] | ✅[💾][20240101tests] |
| 20240102 | [Day 1: Historian Hysteria - Part 2][20240102] | ✅[💾][20240102solution] | ✅[💾][20240102tests] |
| 20240201 | [Day 2: ?][20240201] | [💾][20240201solution] | [💾][20240201tests] |
| 20240202 | [Day 2: ? - Part 2][20240202] | [💾][20240202solution] | [💾][20240202tests] |
| 20240301 | [Day 3: ?][20240301] | [💾][20240301solution] | [💾][20240301tests] |
| 20240302 | [Day 3: ? - Part 2][20240302] | [💾][20240302solution] | [💾][20240302tests] |
| 20240401 | [Day 4: ?][20240401] | [💾][20240401solution] | [💾][20240401tests] |
| 20240402 | [Day 4: ? - Part 2][20240402] | [💾][20240402solution] | [💾][20240402tests] |
| 20240501 | [Day 5: ?][20240501] | [💾][20240501solution] | [💾][20240501tests] |
| 20240502 | [Day 5: ? - Part 2][20240502] | [💾][20240502solution] | [💾][20240502tests] |
| 20240601 | [Day 6: ?][20240601] | [💾][20240601solution] | [💾][20240601tests] |
| 20240602 | [Day 6: ? - Part 2][20240602] | [💾][20240602solution] | [💾][20240602tests] |
| 20240701 | [Day 7: ?][20240701] | [💾][20240701solution] | [💾][20240701tests] |
| 20240702 | [Day 7: ? - Part 2][20240702] | [💾][20240702solution] | [💾][20240702tests] |
| 20240801 | [Day 8: ?][20240801] | [💾][20240801solution] | [💾][20240801tests] |
| 20240802 | [Day 8: ? - Part 2][20240802] | [💾][20240802solution] | [💾][20240802tests] |
| 20240901 | [Day 9: ?][20240901] | [💾][20240901solution] | [💾][20240901tests] |
| 20240902 | [Day 9: ? - Part 2][20240902] | [💾][20240902solution] | [💾][20240902tests] |
| 20241001 | [Day 10: ?][20241001] | [💾][20241001solution] | [💾][20241001tests] |
| 20241002 | [Day 10: ? - Part 2][20241002] | [💾][20241002solution] | [💾][20241002tests] |
| 20241101 | [Day 11: ?][20241101] | [💾][20241101solution] | [💾][20241101tests] |
| 20241102 | [Day 11: ? - Part 2][20241102] | [💾][20241102solution] | [💾][20241102tests] |
| 20241201 | [Day 12: ?][20241201] | [💾][20241201solution] | [💾][20241201tests] |
| 20241202 | [Day 12: ? - Part 2][20241202] | [💾][20241202solution] | [💾][20241202tests] |
| 20241301 | [Day 13: ?][20241301] | [💾][20241301solution] | [💾][20241301tests] |
| 20241302 | [Day 13: ? - Part 2][20241302] | [💾][20241302solution] | [💾][20241302tests] |
| 20241401 | [Day 14: ?][20241401] | [💾][20241401solution] | [💾][20241401tests] |
| 20241402 | [Day 14: ? - Part 2][20241402] | [💾][20241402solution] | [💾][20241402tests] |
| 20241501 | [Day 15: ?][20241501] | [💾][20241501solution] | [💾][20241501tests] |
| 20241502 | [Day 15: ? - Part 2][20241502] | [💾][20241502solution] | [💾][20241502tests] |
| 20241601 | [Day 16: ?][20241601] | [💾][20241601solution] | [💾][20241601tests] |
| 20241602 | [Day 16: ? - Part 2][20241602] | [💾][20241602solution] | [💾][20241602tests] |
| 20241701 | [Day 17: ?][20241701] | [💾][20241701solution] | [💾][20241701tests] |
| 20241702 | [Day 17: ? - Part 2][20241702] | [💾][20241702solution] | [💾][20241702tests] |
| 20241801 | [Day 18: ?][20241801] | [💾][20241801solution] | [💾][20241801tests] |
| 20241802 | [Day 18: ? - Part 2][20241802] | [💾][20241802solution] | [💾][20241802tests] |
| 20241901 | [Day 19: ?][20241901] | [💾][20241901solution] | [💾][20241901tests] |
| 20241902 | [Day 19: ? - Part 2][20241902] | [💾][20241902solution] | [💾][20241902tests] |
| 20242001 | [Day 20: ?][20242001] | [💾][20242001solution] | [💾][20242001tests] |
| 20242002 | [Day 20: ? - Part 2][20242002] | [💾][20242002solution] | [💾][20242002tests] |
| 20242101 | [Day 21: ?][20242101] | [💾][20242101solution] | [💾][20242101tests] |
| 20242102 | [Day 21: ? - Part 2][20242102] | [💾][20242102solution] | [💾][20242102tests] |
| 20242201 | [Day 22: ?][20242201] | [💾][20242201solution] | [💾][20242201tests] |
| 20242202 | [Day 22: ? - Part 2][20242202] | [💾][20242202solution] | [💾][20242202tests] |
| 20242301 | [Day 23: ?][20242301] | [💾][20242301solution] | [💾][20242301tests] |
| 20242302 | [Day 23: ? - Part 2][20242302] | [💾][20242302solution] | [💾][20242302tests] |
| 20242401 | [Day 24: ?][20242401] | [💾][20242401solution] | [💾][20242401tests] |
| 20242402 | [Day 24: ? - Part 2][20242402] | [💾][20242402solution] | [💾][20242402tests] |
| 20242501 | [Day 25: ?][20242501] | [💾][20242501solution] | [💾][20242501tests] |

[20240101]: https://adventofcode.com/2024/day/1
[20240102]: https://adventofcode.com/2024/day/1#part2
Expand Down
53 changes: 42 additions & 11 deletions adventofcode/src/main/java/org/ck/adventofcode/year2024/Day01.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
package org.ck.adventofcode.year2024;

import java.util.Scanner;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.IntToLongFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.ck.adventofcode.util.AOCSolution;
import org.ck.codechallengelib.annotation.Solution;

@Solution(
id = 20240101,
name = "Day 1: ?",
name = "Day 1: Historian Hysteria",
url = "https://adventofcode.com/2024/day/1",
category = "2024",
solved = false)
category = "2024")
@Solution(
id = 20240102,
name = "Day 1: ? - Part 2",
name = "Day 1: Historian Hysteria - Part 2",
url = "https://adventofcode.com/2024/day/1#part2",
category = "2024",
solved = false)
category = "2024")
public class Day01 extends AOCSolution {

@Override
protected void runPartOne(final Scanner in) {
run(in);
run(
in,
(one, two) -> {
Collections.sort(one);
Collections.sort(two);

return i -> Math.abs(one.get(i) - two.get(i));
});
}

@Override
protected void runPartTwo(final Scanner in) {
run(in);
run(
in,
(one, two) -> {
final Map<Integer, Long> collect =
two.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

return i -> collect.containsKey(one.get(i)) ? collect.get(one.get(i)) * one.get(i) : 0;
});
}

private void run(final Scanner in) {
print("Whoopsie");
private void run(
final Scanner in,
final BiFunction<List<Integer>, List<Integer>, IntToLongFunction> getValueGenerator) {
final List<Integer> one = new ArrayList<>();
final List<Integer> two = new ArrayList<>();

while (in.hasNextLine()) {
final String[] split = in.nextLine().split(" +");

one.add(Integer.parseInt(split[0]));
two.add(Integer.parseInt(split[1]));
}

final IntToLongFunction valueGenerator = getValueGenerator.apply(one, two);
print(IntStream.range(0, one.size()).mapToLong(valueGenerator).sum());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.ck.adventofcode.year2024;

import org.ck.adventofcode.util.BaseAOCTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@Disabled
class Day01Test extends BaseAOCTest {
@ParameterizedTest
@ValueSource(strings = {"01", "01a"})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2057374
Loading

0 comments on commit 206f8ca

Please sign in to comment.