Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/wolffles Secret

Created December 16, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/edeb1ca3d7cce7b6cb6c to your computer and use it in GitHub Desktop.
Save anonymous/edeb1ca3d7cce7b6cb6c to your computer and use it in GitHub Desktop.
powers_of_two
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