I want to compute dragon curve till n = 10 in java with L system using recursion. For example,
Replace all F characters with F-H
Replace all H characters with F+H
dragon(0) = F-H (this is the input)
dragon(1) = F-H-F+H
dragon(2) = F-H-F+H-F-H+F+H
...
dragon(10) = ?
How can I accomplish the same in java using recursion? I'm only interested in knowing the recursive approach.
In recursive approach such "replace" problem statements usually can be implemented as recursive calls.
So let's create two functions -
F()
andH()
each of them will return"F"
or"H"
when desired curve depth is reached, orF(...) + "-" + H(...)
orF(...) + "+" + H(...)
if further expansion is needed.Try it online!