Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (31 sloc) 0.668 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
package main

import (
"fmt"
"math/big"
"strconv"
)

// Function imported from problem 20 (where it's tested)
func Factorial(number int64) *big.Int {
factorial := big.NewInt(1)

for i := number; i >= 1; i-- {
factorial.Mul(factorial, big.NewInt(i))
}

return factorial
}

func main() {
factorials := make([]*big.Int, 0)
for i := int64(0); i < 10; i++ {
factorials = append(factorials, Factorial(i))
}

sum := int64(0)
for i := int64(10); i < 50000; i++ {
factorialSum := int64(0)
for _, digit := range strconv.FormatInt(i, 10) {
factorialSum += factorials[digit-'0'].Int64()
}

if factorialSum == i {
sum += i
}
}

fmt.Println(sum)
}
Something went wrong with that request. Please try again.