Skip to content

Commit

Permalink
2023 Day 1 Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
leibi committed Dec 6, 2023
1 parent b3abdc9 commit 03f162b
Show file tree
Hide file tree
Showing 3 changed files with 1,063 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/net/leibi/adventofcode2023/day1/Day1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.leibi.adventofcode2023.day1;

import lombok.extern.slf4j.Slf4j;

import java.util.stream.IntStream;

@Slf4j
public class Day1 {
public Integer getSumOfCalibrationValues(String small) {
return small
.lines()
.map(this::getCalibrationValue)
.flatMapToInt(IntStream::of)
.sum();
}

private Integer getCalibrationValue(String line) {
//1abc2
var numbers = line.chars()
.filter(i -> i > 48 && i <= 57) // numbers
.map(i -> i - 48)
.toArray();
log.info("{} -> {}: {}", line, numbers, numbers.length);
return numbers[0] * 10 + numbers[numbers.length - 1];
}
}
Loading

0 comments on commit 03f162b

Please sign in to comment.