LoginSignup
0
0

More than 5 years have passed since last update.

自己書き換え再帰でFizzBuzzやってみた

Posted at
self-rec-fizz-buzz.rb
n = 1

if n%15  == 0
  puts "FizzBuzz"
elsif n%3 == 0
  puts "Fizz"
elsif n%5 == 0
  puts "Buzz"
else
  puts n
end

if n == 100
  n = 1
  cmd = "exit"
else
  n += 1
  cmd = "system('exec ruby #{__FILE__}')"
end

lines = File.readlines(__FILE__)
lines[0] = "n = #{n}\n"
File.write(__FILE__, lines.join)
eval cmd

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0