Created
January 15, 2016 00:07
-
-
Save wrq/33f52ac5d087cede6af5 to your computer and use it in GitHub Desktop.
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
require 'prime' | |
PRIMES = (1..Float::INFINITY).lazy.select(&:prime?) | |
#while primes.length > 0 do puts primes.pop; sleep 1 end | |
def make_prime_sayer(starting_time) | |
dt = starting_time | |
c = 0 | |
return lambda do || | |
begin | |
c += 1 if (Time.new.to_i - dt) >= 5 | |
p PRIMES.next if (Time.new.to_i - dt) >= 5 | |
dt = Time.new.to_i if (Time.new.to_i - dt) >= 5 | |
end | |
end | |
end | |
ps = make_prime_sayer(Time.new.to_i) | |
while true do ps.call end | |
# whatever, jhass | |
# the point of this was to print a prime number but to take five seconds | |
# the idea was that you would compute it very slowly | |
# you cant use sleep | |
# my thought was to attach a block to time so that it ran each second | |
# and then just print a prime on every second divisible by five | |
# i feel like a pussy for not having ever completed this | |
# and i wonder... | |
# what if I just had a busy loop with a counter that counted | |
# how long it had been since it last yielded to some &block or something like that? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment