Created
October 1, 2020 08:19
-
-
Save AJFaraday/251aba28f0fa068aebe7b955b860561a to your computer and use it in GitHub Desktop.
The search for a Deciam Binary Two Bit Number™️
This file contains hidden or 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
# Two bit numbers | |
require 'active_support' | |
def has_two_bits?(s) | |
r = false | |
b = 0 | |
c = s.chars.sort | |
c[-3] != '1' && c[-2] == '1' | |
end | |
def is_binary_two_bit?(n) | |
has_two_bits?(n.to_s(2)) | |
end | |
def is_decimal_two_bit?(n) | |
s = n.to_s | |
s =~ /^([01]+)$/ && has_two_bits?(s) | |
end | |
n = 17100000000 | |
b = false | |
t = Time.now | |
loop do | |
if is_decimal_two_bit?(n) && is_binary_two_bit?(n) | |
10.times { puts "#{'#' * 100}#{'#' * 100}" } | |
puts "#{n.to_s.ljust(4)} #{n.to_s(2).rjust(8, '0')} DecimalBinary" | |
10.times { puts "#{'#' * 100}#{'#' * 100}" } | |
b = true | |
#elsif is_binary_two_bit?(n) | |
# puts "#{n.to_s.ljust(4)} #{n.to_s(2).rjust(8, '0')} Binary" | |
#elsif is_decimal_two_bit?(n) | |
# puts "#{n.to_s.ljust(4)} #{n.to_s(2).rjust(8, '0')} Decimal" | |
end | |
if (n % 100_000_000) == 0 | |
puts "#{Time.now} #{Time.now - t}s #{n} #{ActiveSupport::NumberHelper.number_to_rounded(n, delimiter: ',', precision: 0)} #{b}" | |
t = Time.now | |
end | |
n += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment