Tuesday, September 16, 2008

Queneau's "A Hundred Thousand Billion Poems" (Part II)

#!/usr/bin/ruby -w

# My friend, Sal, helped me factor out a lot of the redundancy from the previous version of
# this code, which can be found a few posts down. The difference between the two is
# almost shameful, or indeed is shameful. Enjoy the concision.

q = Array.new

for i in 0..9
File.open("Queneau#{i+1}.txt", "r") do |file|
q[i] = file.readlines()
end
end


print "Type X, then ENTER for Queneau's A Hundred Thousand Billion Poems: "

new_command = gets().chomp()

while (new_command == "X")
puts()
for counter_line in 0..13
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
rnum = a[rand(a.size)]
puts(q[rnum][counter_line])
end
sleep(30)
end