├── queen.py └── wjugmanual.py /queen.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX = 20 4 | self.A = [0]*self.MAX 5 | 6 | def placement(self,i,j): 7 | for k in range(1,i): 8 | if(self.A[k] ==j) or abs(self.A[k] -j) ==abs(k-i): 9 | return False 10 | print(self.A) 11 | return True 12 | 13 | def printplacedqueen(self,N): 14 | print('Arrangement--->') 15 | print() 16 | 17 | for i in range(1,N+1): 18 | for j in range(1,N+1): 19 | if self.A[i]!=j: 20 | print('\t_', end=' ') 21 | else: 22 | print('\tQ', end=' ') 23 | print() 24 | print() 25 | 26 | def N_Queens(self,i,j): 27 | for k in range(1,N+1): 28 | if self.placement(i,k): 29 | self.A[i]=k 30 | if i==N: 31 | self.printplacedqueen(N) 32 | else: 33 | self.N_Queens(i+1,N) 34 | 35 | N= int(input("Enter queen's value")) 36 | obj = solution() 37 | obj.N_Queens(1,N) 38 | -------------------------------------------------------------------------------- /wjugmanual.py: -------------------------------------------------------------------------------- 1 | import math 2 | a=int(input("Enter A capacity")) 3 | b=int(input("Enter B capacity")) 4 | ai=int(input("Initial state of A")) 5 | bi=int(input("Initial state of B")) 6 | af=int(input("Final state of A")) 7 | bf=int(input("Final state of B")) 8 | if a<=0 or b<=0: 9 | print("Jug capacitites cannot be negative") 10 | exit(1) 11 | if ai<0 or bi<0 or af<0 or bf<0: 12 | print("negative values not allowed") 13 | exit(1) 14 | def wjug(a,b,ai,bi,af,bf): 15 | print("List of Operations\n") 16 | print("1. Fill A completely") 17 | print("2. Fill B completely") 18 | print("3. Empty A completely") 19 | print("4. Empty B completely") 20 | print("5. Pour from A till B is full or A is empty") 21 | print("6. Pour from B till A is full or B is empty") 22 | print("7. Pour all from B to A") 23 | print("8. Pour all form A to B") 24 | while ai!=af or bi!=bf: 25 | op=int(input("Enter Operation (1-8)")) 26 | if op==1: 27 | ai=a 28 | elif op==2: 29 | bi=b 30 | elif op==3: 31 | ai=0 32 | elif op==4: 33 | bi=0 34 | elif op==5: 35 | pour_amt=min(ai,b-bi) 36 | ai-=pour_amt 37 | bi+=pour_amt 38 | elif op==6: 39 | pour_amt=min(bi,a-ai) 40 | bi-=pour_amt 41 | ai+=pour_amt 42 | elif op==7: 43 | pour_amt=min(bi,a-ai) 44 | ai+=pour_amt 45 | bi-=pour_amt 46 | elif op==8: 47 | pour_amt=min(ai,b-bi) 48 | bi+=pour_amt 49 | ai-=pour_amt 50 | else: 51 | print("Invalid Operation") 52 | continue 53 | print(f" A: {ai}, B: {bi}") 54 | if ai==af and bi==bf: 55 | print("Final State Reached: A=", ai,", B= ", bi) 56 | return 57 | gcd=math.gcd(a,b) 58 | if(af<=a and bf<=b) and (af%gcd==bf%gcd==0): 59 | wjug(a,b,ai,bi,af,bf) 60 | else: 61 | print("The final state is not achievable with givn capacities") 62 | exit(1) 63 | 64 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------