Coder Social home page Coder Social logo

cs-f214-a1's Introduction

Logic in Computer Science (CS F214)

Assignment-1 (Fall Semester '19)

Problem 1: Given a weighted undirected graph G = (V, E). The weight on an edge (v1, v2) represents the distance between the vertices v1 and v2 {vi V; and (vi, vj) E}. Given a set of weights of edges in the form of prolog clauses:

weight(p, q, 20).
weight(q, r, 5).

Write a prolog program to check if there exists a path between two given vertices. Print the path and its length, if it exists. For example: ?- findPath(p, r, Path, L). the prolog interpreter should print

Path = [p, q, r]
L = 25

Note that the user should print an alternative path if it exists on each press of a semi colon and print no if no path exists. Your program should avoid traversing through cycles, if any.

Problem 2: Write a Prolog predicate for each of the following operations on a list:

  • sublist(X,Y): true if list X is a sublist of list Y. A sublist is the original list, in the same order, but with no/some elements removed.
  • has_triplicate(X): true if list X contains at least three copies of an element. It also prints the element which is triplicated.
  • remove_nth(N,X,Y): prints list Y which is the list X with its Nth element removed. If X does not have an Nth element then the predicate should fail. Assume that N > 0.
  • remove_every_other(X,Y): prints a list Y which is the list X with every other element removed (the two lists should have the same first element).

Note: Each predicate should be able to print the alternative solutions if they exist.

Contributors:

cs-f214-a1's People

Contributors

jshreyans avatar pranagupt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.