Your calculation isn’t quite right. It looks like some digits are actually spelled out with letters: one
, two
, three
, four
, five
, six
, seven
, eight
, and nine
also count as valid “digits”.
Equipped with this new information, you now need to find the real first and last digit on each line.
Write a bash
shell script trebuchet
that takes the pathname of a calibration document as its argument. The shell script must output the sum of all calibration values to stdout
. For example, if we take this calibration document (data.txt
1)
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
the calibration values are 29
, 83
, 13
, 24
, 42
, 14
, and 76
. Adding these together produces 281
.
In this interactive session, we assume that the text file data.txt
2 is in the current directory.
$ trebuchet data.txt
281
Advent of Code 2023
This assignment is based on Eric Wastl’s Advent of Code 20233.