Last active
August 29, 2015 13:56
-
-
Save zyphlar/8972577 to your computer and use it in GitHub Desktop.
binary multiple
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
# from http://stackoverflow.com/questions/19305067/regex-binary-multiple-of-4 | |
class String | |
def binary_multiple_4? | |
(/^[10]*00$/ =~ self) == 0 | |
end | |
end | |
puts "4" | |
puts 4.to_s(2).binary_multiple_4? | |
puts "5" | |
puts 5.to_s(2).binary_multiple_4? | |
puts "long string4" | |
puts "long string4".binary_multiple_4? | |
puts "10" | |
puts 10.to_s(2).binary_multiple_4? | |
#4 | |
#true | |
#5 | |
#false | |
#long string4 | |
#false | |
#10 | |
#false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will, you are genius