Example #1
0
File: c036.go Project: moul/euler
func C036() (interface{}, error) {
	sum := 0
	for nb := 1; nb < 1000000; nb++ {
		if nb%2 == 0 {
			continue
		}
		nbStr := strconv.Itoa(nb)
		if nbStr != utils.ReverseString(nbStr) {
			continue
		}
		binary := strconv.FormatInt(int64(nb), 2)
		if binary != utils.ReverseString(binary) {
			continue
		}
		sum += nb
	}
	return sum, nil
}
Example #2
0
File: c026.go Project: moul/euler
func C026() (interface{}, error) {
	longestSize := 1
	var longestNumber int64

	for i := int64(2); i < 1000; i++ {
		rat := big.NewRat(1, i)
		floatString := rat.FloatString(2000)
		cycleSize := utils.LongestRecurringCycleInString(utils.ReverseString(floatString[10:]), 1)

		// fmt.Println(i, floatString, cycleSize)
		if cycleSize > longestSize {
			// fmt.Println(i, cycleSize, floatString)
			longestSize = cycleSize
			longestNumber = i
		}
	}

	return longestNumber, nil
}
Example #3
0
File: c004.go Project: moul/euler
func C004() (interface{}, error) {
	biggest := 0

	for a := 999; a >= 100; a-- {
		for b := 999; b >= 100; b-- {
			product := a * b
			if product < biggest {
				continue
			}
			productStr := strconv.Itoa(product)
			if productStr == utils.ReverseString(productStr) {
				if biggest < product {
					biggest = product
				}
			}
		}
	}

	return biggest, nil
}