DEV Community

loading...

Discussion on: Daily Challenge #11 - Cubic Numbers

Collapse
margo1993 profile image
margo1993
package utils

import (
    "fmt"
    "strconv"
)

func IsCubicNumber(number int) bool {
    stringNumber := strconv.Itoa(number)
    var result int = 0

    for _, n := range stringNumber {
        parseInt, _ := strconv.ParseInt(string(n), 0, 32)

        i := int(parseInt)
        result += calcCube(i)
        fmt.Print(i, string(n))
    }

    if result == number {
        return true
    }

    return false
}

func calcCube(number int) int {
    return number * number * number
}