Ruby · ruby excercise

No need to worry about interruption when Ruby program execution.

Print 1 to 10000
Why this program need ?:

1.Run a program to print 1 to 100000

2. programs interrupted when printing 497

3. Now run once again, It starts with again 1 to … .. Right ?

4. So This is the program to avoid that issue. Enjoy the program


Code:

i=0
file=File.open(“count.html”,”a”)
x= file.stat.size
if  x == 0 then
while i < 1000000
puts i
file.puts i
i+=1
end
else
s=File.readlines(“count.html”)
#s.each do |sing|
#x=sing
#end
x= s.last
i=x.to_i
i+=1
while i < 1000000
puts i
file.puts i
i+=1
end
end

Thanks,

P.Raveendran

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s