Skip to content

Commit 635e4db

Browse files
doc(day01): add comments
1 parent e163659 commit 635e4db

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: 2023-go/day01/day01.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ func partTwo(lines []string) {
5757
log.Println(sum)
5858
}
5959

60-
// please create a function that solves the problem
60+
// readCalibrationValue2 reads the calibration value from a line.
6161
func readCalibrationValue2(line string) int {
6262
var firstDigit int
6363
var lastDigit int
6464
digits := map[string]int{
65-
"one": 49,
65+
"one": 49, // ASCII code for 1 etc.
6666
"two": 50,
6767
"three": 51,
6868
"four": 52,
@@ -82,10 +82,12 @@ func readCalibrationValue2(line string) int {
8282
return n
8383
}
8484

85+
// isActualDigit checks if a character is a digit between 1 and 9.
8586
func isActualDigit(char int) bool {
8687
return char >= '1' && char <= '9'
8788
}
8889

90+
// searchForCalibrationValueFromLeftToRight searches for the first occurrence of a spelled out digit or actual digit from left to right
8991
func searchForCalibrationValueFromLeftToRight(line string, digits map[string]int) int {
9092
for i := 0; i < len(line); i++ {
9193
for j, k := range digits {
@@ -104,6 +106,7 @@ func searchForCalibrationValueFromLeftToRight(line string, digits map[string]int
104106
return 0
105107
}
106108

109+
// searchForCalibrationValueFromRightToLeft searches for the first occurrence of a spelled out digit or actual digit from right to left
107110
func searchForCalibrationValueFromRightToLeft(line string, digits map[string]int) int {
108111
for i := len(line) - 1; i >= 0; i-- {
109112
for j, k := range digits {

0 commit comments

Comments
 (0)