Part 1: This Nushell code divides the input into lines, and find the max "joltage" in each line, summing up the totals. The max joltage is found by splitting the line into characters, and each character into and integer, and enumerating this list. The first value is the largest item in the list, but leaving out the last list item. This is done by reversing the list, dropping the first item, then reversing the list back again. The second value is the largest item among the remaining items, that is, from the index of the first value to the end of the list. The list which is to be searched is gotten by dropping all values from 0 to the index of the first value. The function that find the largest value is not a simple max function, because the list is enumerated. So, the special max function uses a reduce or fold operation, which compares adjacent items manually, and sets the largest index and its value in the accumulator.
Part 2: This problem is more complex than the first part, because now the "joltage" is made up out of 12 digits, not just 2. So, instead of finding each digit manually (although this is how I prototyped the algorithm) I use a reduce or fold operation on the sequence of digits counting down from 12 to 1. Each fold iteration then finds the largest digit in the line, in the range from the index in the accumulator (which is the index of the previous largest digit) to the length of the line minus the value of the sequence which counts down from 12. It then stores the index of this largest digit in the accumulator, and concatenates the digit onto the value field in the accumulator.
#AdventOfCode Day 3 in #nushell