diff --git a/8q.json b/8q.json new file mode 100644 index 0000000..b5c2226 --- /dev/null +++ b/8q.json @@ -0,0 +1,11 @@ +{"matrix": [ + + [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], + [1, 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]]} + diff --git a/8q.py b/8q.py new file mode 100644 index 0000000..688a32c --- /dev/null +++ b/8q.py @@ -0,0 +1,38 @@ +import json +inf=open("8q.json") +board=json.loads(inf.read()) +board=board["matrix"] +for i in board: + print(i) +def issafe(row,col): + for i in range(8): + for j in range(8): + if(board[i][j]==1): #if a queen exists here, then check if it attacks our queen + if(row==i): + return False + if(col==j): + return False + if(abs(row-i)==abs(col-j)): + return False + return True + +def place(col): + if(col>=8): #if all 8 queens are placed, then finish + print("\t\tCompleted...") + return True + for i in range(8): #checking for all rows in that column + if(issafe(i,col)): #is it safe? + board[i][col]=1 #queen is placed here + if(place(col+1)==True): #recursive call to place next queen + return True + board[i][col]=0 #if not placed, then backtrack, i.e it sets to zero and the loop iterates to check for next position + return False +if(place(1)==True): + print("solution found") +else: + print("Solution not possible") +for i in board: + print(i) + + + diff --git a/untitled-1.py b/Bubble_Sort_By_DT-1.py similarity index 99% rename from untitled-1.py rename to Bubble_Sort_By_DT-1.py index 2f30a56..74a8119 100644 --- a/untitled-1.py +++ b/Bubble_Sort_By_DT-1.py @@ -19,4 +19,4 @@ - \ No newline at end of file + diff --git a/Folder1/folder2 b/Folder1/folder2 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Folder1/folder2 @@ -0,0 +1 @@ + diff --git a/GuessMyNumber.py b/GuessMyNumber.py new file mode 100644 index 0000000..879a94a --- /dev/null +++ b/GuessMyNumber.py @@ -0,0 +1,23 @@ +import random +print "Welcome to the game : Guess My Number" +range="1 to 10" +num = random.randint(1,10) +#print num +while True: + + userNum = int(input("Guess the number in "+range+": ")) + if userNum>num: + print "Number is high" + else: + if userNum