Created
March 25, 2011 03:04
-
-
Save ox/886298 to your computer and use it in GitHub Desktop.
A simple dragon curve algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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