File tree 1 file changed +5
-2
lines changed
1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -57,12 +57,12 @@ func partTwo(lines []string) {
57
57
log .Println (sum )
58
58
}
59
59
60
- // please create a function that solves the problem
60
+ // readCalibrationValue2 reads the calibration value from a line.
61
61
func readCalibrationValue2 (line string ) int {
62
62
var firstDigit int
63
63
var lastDigit int
64
64
digits := map [string ]int {
65
- "one" : 49 ,
65
+ "one" : 49 , // ASCII code for 1 etc.
66
66
"two" : 50 ,
67
67
"three" : 51 ,
68
68
"four" : 52 ,
@@ -82,10 +82,12 @@ func readCalibrationValue2(line string) int {
82
82
return n
83
83
}
84
84
85
+ // isActualDigit checks if a character is a digit between 1 and 9.
85
86
func isActualDigit (char int ) bool {
86
87
return char >= '1' && char <= '9'
87
88
}
88
89
90
+ // searchForCalibrationValueFromLeftToRight searches for the first occurrence of a spelled out digit or actual digit from left to right
89
91
func searchForCalibrationValueFromLeftToRight (line string , digits map [string ]int ) int {
90
92
for i := 0 ; i < len (line ); i ++ {
91
93
for j , k := range digits {
@@ -104,6 +106,7 @@ func searchForCalibrationValueFromLeftToRight(line string, digits map[string]int
104
106
return 0
105
107
}
106
108
109
+ // searchForCalibrationValueFromRightToLeft searches for the first occurrence of a spelled out digit or actual digit from right to left
107
110
func searchForCalibrationValueFromRightToLeft (line string , digits map [string ]int ) int {
108
111
for i := len (line ) - 1 ; i >= 0 ; i -- {
109
112
for j , k := range digits {
You can’t perform that action at this time.
0 commit comments