Challenge 12 - Armstrong Numbers
👋 Welcome Gophers! In this challenge, you are tasked with implementing a function that checks to see whether a number is an armstrong number.
Armstrong Numbers
Armstrong Numbers - An Armstrong number is a 3-digit number such that each of the sum of the cubes of its digits equal the number itself:
View Solution
package main
import "fmt"
import "math"
type MyInt int
func (nptr *MyInt) IsArmstrong() bool {
n := *nptr
if n > 999 && n < 100 {
return false
}
n1 := float64(n / 100)
n2 := float64((n%100) / 10)
n3 := float64(n % 10)
calculated := math.Pow(n1, 3) + math.Pow(n2, 3) + math.Pow(n3, 3)
return float64(n) == calculated
}
func main() {
fmt.Println("Armstrong Numbers")
var num1 MyInt = 371
fmt.Println(num1.IsArmstrong())
}
Further Reading:
If you enjoyed this challenge, you may also enjoy some of the other challenges on this site: