Last active
November 23, 2022 18:23
-
-
Save monkrus/ad53c3e48dc45192bc562c3c89ea927d to your computer and use it in GitHub Desktop.
Extract string values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getProduct(digits string) (product int64, e error) { | |
product = 1 | |
for _, digit := range digits { | |
d, err := strconv.Atoi(string(digit)) | |
if err != nil { | |
return -1, fmt.Errorf("cannot convert %v to int", digit) | |
} | |
product *= int64(d) | |
} | |
return product, nil | |
} | |
for i := 0; i <= len(digits)-span; i++ { | |
product, err := getProduct(digits[i : i+span]) | |
if err != nil { | |
return -1, err | |
} | |
if product > largestProduct { | |
largestProduct = product | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment