Dan Anglin
76583b3dda
All checks were successful
/ test (pull_request) Successful in 25s
It's time to add common functions to the internal 'common' package. - Add the function that read the contents from a file to a list. - Add the function that parses a list of integers from a string. ...and more to come later...
27 lines
443 B
Go
27 lines
443 B
Go
package main
|
|
|
|
func partOneCalculateSumCalibrationValues(document []string) int {
|
|
sum := 0
|
|
|
|
for _, line := range document {
|
|
sum = sum + calibrationValue(line)
|
|
}
|
|
|
|
return sum
|
|
}
|
|
|
|
func calibrationValue(line string) int {
|
|
var digits []int
|
|
|
|
for _, r := range []rune(line) {
|
|
if (r >= '0') && (r <= '9') {
|
|
digits = append(digits, int(r-'0'))
|
|
}
|
|
}
|
|
|
|
if len(digits) == 0 {
|
|
return 0
|
|
}
|
|
|
|
return (10 * digits[0]) + digits[len(digits)-1]
|
|
}
|