Magn0733's Profile User Rating: -----

Reputation: 4 Apprentice
Group:
Active Members
Active Posts:
57 (0.09 per day)
Joined:
04-April 13
Profile Views:
724
Last Active:
User is offline Oct 29 2014 07:13 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Magn0733 has not set their status

Posts I've Made

  1. In Topic: Quick help with inserting list into list.

    Posted 29 Oct 2014

    As promissed.
    class Rule(object):
    	def __init__(self, key, ruleDict = dict(), depth = 0):
    		self.sumRuleList = []
    		self.ruleList = ruleDict[key]
    		self.sumRuleList = ruleDict[key]
    		self.ApplyRule(ruleDict, depth, key)
    		print self.sumRuleList
    		
    	def ApplyRule(self, ruleDict, dpt, k):
    		self.sumRuleList = list(k)
    		if dpt == 0:
    			return
    		while dpt > 0:
    			self.tmpList = []
    			for n in range(len(self.sumRuleList)):
    				if self.sumRuleList[n] == k:
    					for i in self.ruleList:
    						self.tmpList.append(i)
    				else:
    					self.tmpList.append(self.sumRuleList[n])
    			
    			self.sumRuleList = self.tmpList
    			dpt -= 1
    		
    
    class Command(object):
    	def __init__(self):
    		pass
    		
    class Fractal(object):
    	def __init__(self):
    		pass
    		
    TestObj = Rule('F', {'F':['F','L','F','R','F','L','F']}, 2)
    
    


    Ass promissed.
    class Rule(object):
    	def __init__(self, key, ruleDict = dict(), depth = 0):
    		self.sumRuleList = []
    		self.ruleList = ruleDict[key]
    		self.sumRuleList = ruleDict[key]
    		self.ApplyRule(ruleDict, depth, key)
    		print self.sumRuleList
    		
    	def ApplyRule(self, ruleDict, dpt, k):
    		self.sumRuleList = list(k)
    		if dpt == 0:
    			return
    		while dpt > 0:
    			self.tmpList = []
    			for n in range(len(self.sumRuleList)):
    				if self.sumRuleList[n] == k:
    					for i in self.ruleList:
    						self.tmpList.append(i)
    				else:
    					self.tmpList.append(self.sumRuleList[n])
    			
    			self.sumRuleList = self.tmpList
    			dpt -= 1
    		
    
    class Command(object):
    	def __init__(self):
    		pass
    		
    class Fractal(object):
    	def __init__(self):
    		pass
    		
    TestObj = Rule('F', {'F':['F','L','F','R','F','L','F']}, 2)
    
    
  2. In Topic: Quick help with inserting list into list.

    Posted 29 Oct 2014

    View Postwoooee, on 29 October 2014 - 01:39 PM, said:

    Quote

    But as far as i can see that does not help me a lot
    Why not? You didn't post an example of what you want as a final result. Try using append instead of +/extend, but I don't know if that is what you want either (difference between append and extend).
    orig_list=[1, 2, 3, 4, 5]
    insert_list=["a", "b", "c"]
    insert_position=2
     
    inserted_list=orig_list[:insert_position]
    inserted_list.append(insert_list)
    print inserted_list
    ##
    ## you can finish the rest if this does what you want 
    

    Yeah sorry if that came out a bit rough. You are still helpful. :) The ting i wanted is to input a list into a list and remove the element which it has been inputed on such that: list a = [1, 2, 3] where if i wanted to input on 1 and 3 would become a =[[list], 2, [list]]

    But i've found a way around it and is currently working on the code. I will post it as soon as i finish up.

    Thumbs up for your help anyways. :)
  3. In Topic: Quick help with inserting list into list.

    Posted 29 Oct 2014

    View Postwoooee, on 29 October 2014 - 11:01 AM, said:

    Generally, slicing is used although you can iterate over the list with a for loop, appending to a new list, and execute the insert code when some number is reached. Note that there is an insert method for lists, but I don't use it for no good reason, so can't help there.
    orig_list=[1, 2, 3, 4, 5]
    insert_list=["a", "b", "c"]
    insert_position=2
    
    print orig_list[:insert_position]+insert_list+orig_list[insert_position:] 
    


    Hey thanks for responding.
    I might be a little tired and blind in code. :)

    But as far as i can see that does not help me a lot - sorry... :)

    Though i see your logic.

    The thing is i want a list of lists? I've also tried the insert function but that also applies the [,,,] list insted of the [FBF] list.
    I hope you can still help me. Maybe elaborate on your example?
  4. In Topic: Sierpinski's Fractal Triangle.

    Posted 28 Sep 2014

    Problem solved!!! :D

    heres the code for anyone who's having the same problem as me.
    from swampy.TurtleWorld import *
    world = TurtleWorld()
    bob = Turtle()	
    bob.delay = 0.0
    print bob
    
    def Triangle(turt, len):
    	for i in range(3):
    		fd(turt, len)
    		lt(turt, 120)		
    		
    def SierpinskiTri(turt, len, depth):
    	if depth == 0: #basecase
    		Triangle(turt, len)
    		return
    	else:	#logic
    		for i in range(3):
    			#Triangle(turt, len)
    			fd(turt, 2**depth*len)
    			lt(turt, 120)
    			SierpinskiTri(turt, len, depth - 1)
    	
    pu(bob)
    rt(bob)
    fd(bob, 500)
    lt(bob)
    pd(bob)			
    SierpinskiTri(bob, 3, 8)
    wait_for_user()
    
    
  5. In Topic: Sierpinski's Fractal Triangle.

    Posted 28 Sep 2014

    I've already done this and i can do it to a depth of 4.

    Heres how in pseudocode:

    
    def triangle(length):
    for i in range(3)
       if i != 2: 
          forwards(length)
          leftturn(120degree)
       else:
           forward(length)
           leftturn(120degree)
           forward(length * 2)
    
    def SierpinskiTriangle(len, depth1, depth2):
       if depth == 0: return
    
       index = depth2 - depth1
    
       for i in range(3):
           Drawtriangle(lenght)
           leftturn(120)
           if index == 0:
              forward(len * 2)
    
        if index == 1:
           forward( 2 * lenth)
           leftturn(120)
           fd( 2 * length
    
        SierpinskiTriangle(length, depth1, depth2)
    
    


    Now i can do the index steps again and again manually and that way increase the depth.
    But i can not figure out a way to do it so that is is n depth and not a fixed amount that is hardcoded in :S

    Please help. :)

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Magn0733 hasn't added any friends yet.

Comments

Magn0733 has no profile comments yet. Why not say hello?