-
-
Save anonymous/edeb1ca3d7cce7b6cb6c to your computer and use it in GitHub Desktop.
powers_of_two
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
def is_power_of_two?(number) | |
i = 0 | |
array = [] | |
while i < 10; array << 2 ** i; i += 1 end | |
array.include?(number) | |
end | |
puts('is_power_of_two?(1) == true: ' + (is_power_of_two?(1) == true).to_s) | |
puts('is_power_of_two?(16) == true: ' + (is_power_of_two?(16) == true).to_s) | |
puts('is_power_of_two?(64) == true: ' + (is_power_of_two?(64) == true).to_s) | |
puts('is_power_of_two?(78) == false: ' + (is_power_of_two?(78) == false).to_s) | |
puts('is_power_of_two?(0) == false: ' + (is_power_of_two?(0) == false).to_s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment