Skip to content

Instantly share code, notes, and snippets.

@peterfoxflick
Last active October 11, 2018 02:54
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 peterfoxflick/d1fa4c4c2810f4ea5a41ff37c0e1ea13 to your computer and use it in GitHub Desktop.
Save peterfoxflick/d1fa4c4c2810f4ea5a41ff37c0e1ea13 to your computer and use it in GitHub Desktop.
This is for a school project on testing if you can count with the sqrt(2) and (2 + sqrt(2)).
require 'twitter'
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.access_token = "YOUR_ACCESS_TOKEN"
config.access_token_secret = "YOUR_ACCESS_SECRET"
end
def getA(n)
return ((n * 14142) + ((n * 1356) + ((n * 2373) + ((n * 950) + ((n * 4880) + ((n * 1688) + ((n * 7242) / 10000)) / 10000) / 10000) / 10000) / 10000) / 10000) / 10000
end
def getB(n)
return ((n * 34142) + ((n * 1356) + ((n * 2373) + ((n * 950) + ((n * 4880) + ((n * 1688) + ((n * 7242) / 10000)) / 10000) / 10000) / 10000) / 10000) / 10000) / 10000
end
# Inital Variables #####################################
a = 7071067812
b = 2928932189
n = 10000000000
# Get User Settings ####################################
puts "Would you like to read in output.txt?"
answer = gets.chomp
if answer == "yes" || answer == "y"
File.open("output.txt", "r") do |f|
f.each_line do |line|
if line["N:"] != nil
n = line.scan(/\d/).join('').to_i
end
if line["A:"] != nil
a = line.scan(/\d/).join('').to_i
end
if line["B:"] != nil
b = line.scan(/\d/).join('').to_i
end
end
end
end
puts "How high would you like to count to? 0 keeps default of 1,000,000,000,000,000"
answer = gets.chomp.to_i
max = 1000000000000000
if answer != 0
max = answer
end
puts "What would you like the delay to be?"
delay = gets.chomp.to_i
puts "Would you like to send tweets?"
answer = gets.chomp
tweet = false
if answer == "y" || answer == "yes"
tweet = true
end
# Start Counting ####################################
puts "\n\u{1f60e}\n"
if tweet
twitter.update("Begining new count, starting at: " + n.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + " https://goo.gl/ZdMJiE" )
end
isA = false
uberStart = Time.now
start = Time.now
# Begin the Loop ####################################
while n < max
if getA(a) == n
a += 1
isA = true
elsif getB(b) == n
b += 1
isA = false
else
puts "error at: " + n.to_s
puts "A: " + getA(a).to_s
puts "B: " + getB(b).to_s
break
end
finish = Time.now
diff = finish - start
if tweet && diff > 3600
twitter.update("Current trillion counter is at: " + n.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + " https://goo.gl/ZdMJiE" )
end
if diff > delay
puts n.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
start = finish
tempA = a
tempB = b
if isA
tempA -= 1
else
tempB -= 1
end
File.open("output.txt", 'w') { |file| file.write("N: " + n.to_s + "\nA: " + tempA.to_s + "\nB: " + tempB.to_s) }
end
n += 1
end
# Finalize the Results ####################################
if isA
a -= 1
else
b -= 1
end
puts "A: " + a.to_s + " B: " + b.to_s
finish = Time.now
timeTaken = finish - uberStart
puts "it took: " + timeTaken.to_s + " to get to n: " + n.to_s
if tweet
twitter.update("Finished counting to " + (n - 1).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + " in " + timeTaken + " seconds. https://goo.gl/ZdMJiE" )
end
N: 10110441280
A: 292893218814
B: 1000000000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment