visit my blog to see full content and its a humble request to follow the blog so you can get the latest postings which are going to be uploaded soon on the blog.
Assignment 1 Problem – Write a program to find out the next state of a given 8-puzzle problem. Solution : import heapq # Define the goal state goal_state = [[1, 2, 3], [4, 5, 6], [7, 8, 0]] # Define the possible moves moves = [(0, 1), (0, -1), (1, 0), (-1, 0)] def heuristic(state): # Manhattan distance heuristic distance = 0 for i in range(3): for j in range(3): if state[i][j] != 0: goal_row, goal_col = (state[i][j] - 1) // 3, (state[i][j] - 1) % 3 ...
Prolog Clause Prolog programs describe relations, defined by means of clauses. Pure Prolog is restricted to Horn clauses. There are two types of clauses: facts and rules. A rule is of the form Head :- Body and is read as "Head is true if Body is true". For example animal (X) :- cat (X). mean for all X, X animal if X is cat. Fact is a clause without body. For example ‘Tom is a cat.’ is a fact and represented in prolog as cat (‘ Tom’ ). It may also be represented as cat ( tom ):- true. Term A term in prolog may be Atom: An atom is a general-purpose name with no inherent meaning. Examples of atoms include x , red , 'Taco' , 'some atom’ . Number : It can be floats or in...
Comments
Post a Comment
Kaushikmadhav77@gmail.com