Python Forum
Increasing depth in python
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Increasing depth in python
#1
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
Reply
#2
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.
Reply
#3
(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!
Reply
#4
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
Reply
#5
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
Reply
#6
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?
Reply
#7
(Oct-20-2016, 04:10 PM)malling Wrote: sorry, i wanted to post a picture but it seems that i cant because of spam protecting.
The link restrictions were given a little more leniency, if it was a link to pic.
http://python-forum.io/Thread-new-link-restriction
Recommended Tutorials:
Reply
#8
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
Reply
#9
The files is something like this.
Rule: F -> F L F R F L F
Reply
#10
Is that one rule? What does it mean? Replace all "F" with "FLFRFLF"?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "RecursionError: maximum recursion depth exceeded in comparison" hhydration 1 1,812 Sep-26-2020, 03:07 PM
Last Post: deanhystad
  Digits increasing meknowsnothing 6 4,073 Feb-17-2019, 11:22 AM
Last Post: scidam
  Increasing difficulty of a maths game Maxxy_Gray 1 3,174 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020