loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

In Go.

func strongest(start, stop int) int {
    power := func(num int) int {
        numSlice := strings.Split(fmt.Sprintf("%b", num), "1")
        return len(numSlice[len(numSlice)-1])
    }

    hp := 0
    var result int

    for i := start; i <= stop; i++ {
        if hp < power(i) {
            hp = power(i)
            result = i
        }
    }

    return result
}
Code of Conduct Report abuse