static void day1(String puzzleInputUri) throws IOException, InterruptedException {
Map<String, String> digits = Map.of(
"1", "one",
"2", "two",
"3", "three",
"4", "four",
"5", "five",
"6", "six",
"7", "seven",
"8", "eight",
"9", "nine"
);
TreeMap<Integer, String> firstLast = new TreeMap<>();
var result = client.send(request.uri((URI.create(puzzleInputUri))).build(), HttpResponse.BodyHandlers.ofLines()).body()
.map(string -> {
firstLast.clear();
digits.forEach((digit, numeric) -> {
firstLast.put(string.indexOf(digit), digit);
firstLast.put(string.lastIndexOf(digit), digit);
firstLast.put(string.indexOf(numeric), digit);
firstLast.put(string.lastIndexOf(numeric), digit);
}
);
firstLast.remove(-1); // not matched substrings index
return firstLast.firstEntry().getValue() + firstLast.lastEntry().getValue();
})
.mapToInt(Integer::parseInt)
.sum();
System.out.println(result);
}