Created
February 16, 2024 11:39
-
-
Save edr3x/00a85cf379a9669b823cd6df8a05cff3 to your computer and use it in GitHub Desktop.
Function to check if a number is a power of another number in GO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isPower(number int, isPowerOf int) bool { | |
if number < 1 { | |
return false | |
} | |
if number%isPowerOf == 0 { | |
return isPower(number/isPowerOf, isPowerOf) | |
} | |
return number == 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment