示例#1
0
func main() {
	result, err := filelib.ReadLines("../../resources/euler13.txt")
	count := 0

	if err != nil {
		fmt.Println("Failed to load big number")
	} else {
		sum := big.NewInt(0)
		numberFromFile := big.NewInt(0)

		for _, number := range result {
			if _, ok := numberFromFile.SetString(number, 10); ok {
				count = count + 1
				sum = sum.Add(sum, numberFromFile)
			} else {
				fmt.Printf("couldn't interpret line %#v\n", numberFromFile)
			}
		}
		fmt.Printf("Number is %v count is %v", sum.String(), count)
	}
}
示例#2
0
func main() {
	//load the matrix
	maxProduct := -1
	result, err := filelib.ReadLines("../../resources/euler11.txt")
	if err != nil {
		fmt.Println("Failed to load matrix.")
	} else {
		//convert slice of strings into something more convenient and xy addressable
		size := len(result)
		var matrix = convertMatrix(result)
		//traverse the matrix
		for i := 0; i < size; i++ {
			for j := 0; j < size; j++ {
				aProduct := largestProductFromPoint(i, j, matrix)
				if aProduct > maxProduct {
					maxProduct = aProduct
				}
			}
		}
		fmt.Printf("Max product is %v \n", maxProduct)
	}
}