Skip to content

Instantly share code, notes, and snippets.

@ox
Created March 25, 2011 03:04
Show Gist options
  • Save ox/886298 to your computer and use it in GitHub Desktop.
Save ox/886298 to your computer and use it in GitHub Desktop.
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