Jump to content

zak100

Senior Members
  • Posts

    233
  • Joined

  • Last visited

Everything posted by zak100

  1. Hi, Thanks a lot. That's why posted this problem because I new that somebody will tell me the good approach. I did not this solution on the internet. So we have got something new. God blesses you . Zulfi.
  2. Hi, Thanks a lot. I have to learn debugger. Yes people suggested me to use the debugger, I tried but then got problems and stopped. I would specifically start a thread for debugger. Thanks for your solution using numpy. I solved the problem last night. My solution is more traditional import numpy as np #from array import * class Board: Matrix = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) #Matrix.fill(0) def __init__(self, n): self.n = n def displayBDMatrix(self, n): #for i in range(n): #for j in range(n): #print(Board.Matrix[i][j]), for i in range(n): print(str(Board.Matrix[i][0]) + " " + str(Board.Matrix[i][1]) + " " + str(Board.Matrix[i][2]) + " " + str(Board.Matrix[i][ 3]) + " " + str(Board.Matrix[i][4]) + " " + str(Board.Matrix[i][5]) + " " + str(Board.Matrix[i][6]) + " " + str(Board.Matrix[i][ 7])) def main(self): n=8 #self.display(n) self.displayBDMatrix(n) #self.displayPieces() if __name__ == "__main__": objBoard = Board(8) objBoard.main() Thanks a lot. God blesses you. Zulfi.
  3. Hi, I am trying to create an integer 2D array. I have used numpy, but it creates a floating point array. When I am printing this 8 * 8 array, its printing each entry of 8*8 array in a separate line. I want to print each row on a new line import numpy as np class Board: Matrix = np.empty((8, 8)) Matrix.fill(0) def __init__(self, n): self.n = n def displayBDMatrix(self, n): for i in range(n): for j in range(n): print(Board.Matrix[i][j]), def main(self): n=8 #self.display(n) self.displayBDMatrix(n) #self.displayPieces() if __name__ == "__main__": objBoard = Board(8) objBoard.main() I am getting following output: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 and so on. Somebody please guide me. Zulfi.
  4. 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.
  5. 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)
  6. 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.
  7. 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.
  8. 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.
  9. Hi, Thanks for removing this fundamental confusion in a very good manner. Zulfi.
  10. 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.
  11. 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.
  12. Hi, Thanks a lot for your explanation. If we include 'c', should not we provide 'c' input for all states? Zulfi.
  13. 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.
  14. Hi, I am able to understand evrything which you said. Very Good. Thanks for removing this confusion. God blesses you. Zulfi.
  15. 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.
  16. 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.
  17. 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.
  18. 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.
  19. Hi, You are right. I have Ubuntu 18.04. I think it has built in python and then I am using pycharm IDE which has a different python. Zulfi.
  20. Hi, Thanks for your response. $ pip install anytree But still I am getting the same error. 'Hint' is changing from anytree import Node, RenderTree to import anytree but its not doing any good to my code. Somebody please guide me. Some Zulfi.
  21. Hi, I am trying to run th efollowing program, I got it from :Tree with Multiple children from anytree import Node, RenderTree udo = Node("Udo") marc = Node("Marc", parent=udo) lian = Node("Lian", parent=marc) dan = Node("Dan", parent=udo) jet = Node("Jet", parent=dan) jan = Node("Jan", parent=dan) joe = Node("Joe", parent=dan) I am getting th efollowing error: File "PycharmProjects/AIHW/venv/TreeDS.py", line 1, in <module> from anytree import Node, RenderTree ModuleNotFoundError: No module named 'anytree' Somebody please guide me. Zulfi.
  22. Hi, I am getting the answer: [14. 14, 14, 14, 14] instead of : [10, 11, 12, 13, 14] This is the confusion. Somebody please guide me why the output is: [14. 14, 14, 14, 14] Zulfi.
  23. Hi, I can't understand the code, is it creating five lambda function definition with in the list, I have got the following code; print("list3") fun_list3 = [lambda e: e+i for i in range(5)] #The lambda function returns e+i for i in range(5), Note e is the argument of lambda function print([f(10) for f in fun_list3]) The output is: I can’t understand the output of the function, its printing: From print statement we are passing 10 to the lambda function argument, lambda function evaluates “e+i” so its output is 10 first time, and second time, it should be 11, and 3rd time 12 and so on, but I can’t understand this output. Somebody please guide me. Zulfi.
  24. Hi, Following is the program similar to : Storing the function in the list fun_list2 = [ ] for i in range(5): def fun2(e, iv=i): return e + iv fun_list2.append(fun2) print([f(10) for f in fun_list2]) From the above link, I am able to understand the above code. However, I have problem in understanding the '[....]' in the print statement. If I run the above program without square brackets like: print(f(10) for f in fun_list2) I am getting the message: Somebody please guide me. Zulfi.
  25. Hi timo- Thanks a lot. God blesses you. I have one question What you mean by the statement after '=' : fun1(e)= e +0, fun1(e)=e+0, fun1(e)=e+1, fun1(e)=e+2, fun1(e)=e+3 and fun1(e)=e+4. Does it mean the code of function? 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.