Hello everyone.
Im trying to make a smart way to using fractals and i have been searching a bit around without any advice on my topic.
Well it's basicly about applying One Rule.
It looks like this:
start F
rule F -> F L F R F L F
i got the main ideer of it that when it reads F it should write F L F R F L F and then add it to the "result".
My only problem is that im not the best programmer and therefore i don't know how i should proceed to write it into python.
it should read the list, then replace F with F L F R F L F ever time it finds it when it searching the list. In the end it should give a output where the whole result is printed.
list, tuples etc?
Best regards Malling
Please read through your post as if you where someone that didn't know what you are talking about as I don't understand how to offer help.
(Oct-20-2016, 12:27 PM)Yoriz Wrote: [ -> ]Please read through your post as if you where someone that didn't know what you are talking about as I don't understand how to offer help.
sorry, i wanted to post a picture but it seems that i cant because of spam protecting.
Anyway i have found the solution, but i may post another thread soon. I do my best to explain it!
Hello again forum!
I have a task that i have to solve, but there is a thing i don't understand.
I write the whole description down below so i don't confuse anyone!
Task
________________________________________________________
Write a function
step(rules, state) that takes a list
state, applies all rules in rules, and finally flattens the resulting list.
then write a function
compute(depth, rules, start) that uses the
step function
depth times to transform the list
start into a list representing a fractal of depth
depth.
The step(rules, state) is confusing me. Can someone tell me how i define the rules in python?
I did Previously a function called
apply(left, right, state) where i got this down.
def apply(left, right, state):
result = []
for x in state:
if x==left:
result.append(right)
else:
result.append(x)
print(result)
apply("F",["F","L","F","R","F","L","F"],["F","R","F","R","F"])
but now where i only have the rule, i don't know how to proceed
Plz help me here!
Best regards Malling
Do you know what the rules are? Are they callable objects? Strings representing things you do? Could it be as simple as:
def step(rules, state):
for rule in rules:
state = rule(state)
return state
I actually have seen that before but wasn't sure.
But it confuses me how python knows what rule in rules are.
Could I also call it for x in rules? So it really doesn't matter?
Yes, it's just a temporary variable created by the for loop. You can call it whatever you want...
>>> items = ['i', 'can', 'see', 'clearly', 'now']
>>> for thing in items:
... print(thing)
...
i
can
see
clearly
now
>>> for x in items:
... print(x)
...
i
can
see
clearly
now
The files is something like this.
Rule: F -> F L F R F L F
Is that one rule? What does it mean? Replace all "F" with "FLFRFLF"?