Create a gist now

Instantly share code, notes, and snippets.

A simple dragon curve algorithm
# Dragon Curve algorithm
# source: http://en.wikipedia.org/wiki/Dragon_curve
# Use: ruby dragon_curve.rb [number of iterations]
str = "R"
ARGV[0].to_i.times do
nstr = str.reverse
for i in 0..nstr.length
if nstr[i] == 82
nstr[i] = "L"
elsif nstr[i] == 76
nstr[i] = "R"
end
end
str = str + "R" + nstr
end
puts str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment