Jump to content

zak100

Senior Members
  • Content Count

    130
  • Joined

  • Last visited

Community Reputation

0 Neutral

About zak100

  • Rank
    Baryon

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi, I think I have solved that problem: import numpy as np class CPieces: pieceIndex=0; def __init__(self, pieceIndex): if (pieceIndex<8): self.pieceIndex = pieceIndex else: self.pieceIndex = pieceIndex class B: Matrix = np.empty((8, 8)) Matrix.fill(0) def __init__(self, n): self.n=n CPieces.pieces = []#no error if commented obj1 = CPieces(0) obj2 = CPieces(1) CPieces.pieces.append(obj1) CPieces.pieces.append(obj2) def display(self, n): print(n) def main(self): n=8 self.display(n) if __name__ == "__main__": objB = B(8) objB.main() Zulfi.
  2. import numpy as np class CPieces: pieceIndex=0; def __init__(self, pieceIndex): if (pieceIndex<8): self.pieceIndex = pieceIndex else: self.pieceIndex = pieceIndex class B: Matrix = np.empty((8, 8)) Matrix.fill(0) def __init__(self, n): self.n=n CPieces.pieces = []#no error if commented for i in range(n): #no error if commented CPieces.pieces.append = CPieces(self, i)#no error if commented def display(self, n): print(n) def main(self): n=8 self.display(n) if __name__ == "__main__": objB = B(8) objB.main() Hi, Following is the output. If I remove th elines which have associated comments, I won't get error, please guide me. Zulfi. Hi, I removed the self from: but I am still getting error: CPieces.pieces.append = CPieces( i)
  3. Hi, Ok but this is not a DFA because there is confusion. Am I right? With input "b" at q2 we are going to both q3 and q4. So let's remove the transition from q2 to q3. Now start again from q1 with "a" input to q1. At q2 we got a "b",so at q4 we have "ab". Now q4 is inputting a,b, what would happen? is q4 and q5 accepting "aa" and "bb" or not? Zulfi.
  4. Hi, Thanks a lot. q2 will get an "a", its fine. q2 will pass this "a" to q4 and now at q4 we have "ab" via q1q2q4. Now q4 can accept both 'a' and 'b'. Q4 is already having "ab" and if it gets "b", the accepted string would be "abb" which is not good. I am saying that q4 should not accept 'a' or 'b' becase then we would accept string like "aa" or "bb" instead q4 should send the input 'a' or 'b' to garbage state. Is the arc with a, b on q4 and q5 correct? I am saying its wrong because both q4 and a5 are accepting states and we don't want to accept a substring "aa" or "bb". But with arc having input a,b, both q4 and q5 can accept "aa" or "bb" which our DFA don't want. Please guide me. Zulfi.
  5. Hi, I have one more DFA and I have a confusion whether it accepts substring "aa" or "bb" or not. It is given below: I have a problem in understanding the state q4 and q5. If we give input a,b, randomly there is a possibility that we get two 'a's together or two 'b's together. Also if we get one 'a' then it can merge with previous 'a' comming from q3 to form "aa" which q5 would accept and we dont want. Same is the case with q4 in connection with a,b input. Somebody please guide me. Zulfi.
  6. Hi, Thanks for removing this fundamental confusion in a very good manner. Zulfi.
  7. Hi, Yes you are right. Okay then please tell me about (3) alone. Can the start state produce string of repeated 'a's to be accepted in the final state? Zulfi.
  8. Hi, What is the difference between (3) and (4)? The above (3) does not seem to accept substring "bb" but does the above accept "aa"? What is the difference between (3) and (4)? Does the (4) accept "aa"? Somebody please guide me. Zulfi.
  9. Hi, Thanks a lot for your explanation. If we include 'c', should not we provide 'c' input for all states? Zulfi.
  10. Hi, The above DFA has 3 final states: q0, q1 and q3 and q0 as its start state. It accepts strings: b, ba, bab, baba. Somebody please guide me whether it accepts aa or bb as a substring?I think it accepts string: abbaa. I want to create a DFA which does not accept aa and bb as substrings. Zulfi. Similalry the following one: I think this one does not accept aa and bb but its not correct because it does not accept any string. Somebody please guide me. Zulfi.
  11. Hi, I am able to understand evrything which you said. Very Good. Thanks for removing this confusion. God blesses you. Zulfi.
  12. Hi, I can't understand the path specified in red arcs in the attached slide. The slide shows a movement from A to C and then from C to B and then from B to D. I can’t understand the C to B and B to D movements (or arcs) because there is no edge supporting these movements. Somebody please explain me the path shown in the red dotted line in the slide.
  13. Hi, Thanks for explaining me this whole process. I would come back to the program later on. Right on I am thinking of the fact that if initially we have (4, 2) why our program does not start from this situation: i.e. Empty jug2 (4, 0) Pour jug1 water into jug2 (1, 3) Empty jug2 (1, 0) Please guide me why we can't solve the problem in this manner? Thanks for helping me to understand the output. God blesses you. Now I would like to discuss about the program: 1) What is the purpose of exit command? I found that it is used to exit. So it is same as ending th eprogram 2)We have several calls to WaterJugSolver(...) so its a recursive program. For 1st call (4,2), 1st if is false. After that we would come to 2nd if, in which case is false so we would print (4,2). Then we come to the statement: visited[(4, 2)]= True, what is the purpose of this statement 3)Then we come to the statement: if (waterJugSolver(0, amt2)): exit(1) which is false because we have (4,2), then we would come to the statement: if (waterJugSolver(amt1 + min(amt2, (j1 - amt1)), amt2 - min(amt2, (j1 - amt1)))): exit(1) i.e.if(waterJugSolver(4+min(2, (5-4)), 2 - min(2,(5 - 4)))): i.e. if(waterJugSolver(4+min(2, 1), 2-min(2, 1))) i.e. if(waterJugSolver(5, 2-1)) i.e. if water JugSolver(5, 1) Am I write? I don't think so, 2nd output is: 0,2 Please guide me. Zulfi. Zulfi.
  14. Hi, I am trying to understand the following python code: from collections import defaultdict j1 = 5 j2 = 3 # aim = int(input("Enter the capacity of goal litters : ")) # the already visited node is to stored to save time and memory. visited = defaultdict(lambda: False) def waterJugSolver(amt1, amt2): if (amt1 == 1 and amt2 == 0): print(amt1, amt2) return True if visited[(amt1, amt2)] == False: print(amt1, amt2) visited[(amt1, amt2)] = True if (waterJugSolver(0, amt2)): exit(1) if (waterJugSolver(amt1, 0)): exit(1) if (waterJugSolver(j1, amt2)): exit(1) if (waterJugSolver(amt1, j2)): exit(1) if (waterJugSolver(amt1 + min(amt2, (j1 - amt1)), amt2 - min(amt2, (j1 - amt1)))): exit(1) if (waterJugSolver(amt1 - min(amt1, (j2 - amt2)), amt2 + min(amt1, (j2 - amt2)))): exit(1) else: return False print("Steps: ") waterJugSolver(4, 2) I am getting the following output: First iteration is 4,2 which is fine. But i can't understand the remaining iterations but I understand how we get the final result of 1,0. Somebody please guide me how the program displays the out 0 2, 0 0, 5 0, 5 3. If I get this understanding, I would be able to understand the code. (Note for Editing code, click Edit and then press on angle brackets.
  15. Hi, I am trying to execute the following algorithm shown in the image. I am trying to get the table shown in the image: 1st Iteration L2: 1:CS=A, SL = A, NSL = A L3: while NSL!=[]: true L4: L6:no children: false L17:NSL =BCDA L18:CS:=B L19:SL=BA L20, L21 2nd Iteration L3:While NSL (true) L4: L6:no children: false L17: NSL=EFBCDA L18: CS:=E L19:SL:= EBA L20, L21 3rd Iteration L3:while NSL (true) L4: L6:no children: false L17:NSL= HIEFBCDA L18: CS:= H L19:SL:=HEBA L20, L21 At this point its fine but when there are no more children of current node, it has to backtrack, so it should execute the while loop, at that point I am losing the track: L3:while NSL(true) L4: L6:no children: true L7:begin L8:while SL is not empty (true) and CS:=H L9: DE=H L10:SL=EBA L11:NSL=IEFBCDA L12:CS=I L14:SL= IEBA Now it should keep traversing the while loop but I am having problem with this. Somebody please correct this algorithm or guide me a better backtracking algorithm which has the contents of table. Zulfi. Zulfi.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.