Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
count = 0
IO.foreach("input.txt") { |line| print line; count += 1 }
puts "Printed #{count} lines."

View file

@ -0,0 +1,12 @@
count = 0
reader = Fiber.new do
IO.foreach("input.txt") { |line| Fiber.yield line }
puts "Printed #{count} lines."
nil
end
# printer
while line = reader.resume
print line
count += 1
end

View file

@ -0,0 +1,15 @@
require 'continuation' unless defined? Continuation
count = 0
reader = proc do |cont|
IO.foreach("input.txt") { |line| cont = callcc { |cc| cont[cc, line] }}
puts "Printed #{count} lines."
cont[nil]
end
# printer
while array = callcc { |cc| reader[cc] }
reader, line = array
print line
count += 1
end

View file

@ -0,0 +1,26 @@
require 'thread'
counts = Queue.new
lines = Queue.new
reader = Thread.new do
begin
File.foreach("input.txt") { |line| lines << line }
lines << :EOF
puts "Printed #{counts.pop} lines."
ensure
lines << nil
end
end
# writer
count = 0
while line = lines.pop
case line
when String
print line
count += 1
when :EOF
counts << count
end
end
reader.join