Skip to content

mvbmir/Predicates-discrete-mathematics

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 

Repository files navigation

Assignment 2
Discrete Mathematics: Student Calendar

Programming in logic brain organ, brainstorm, genius, head, logic, memory, strategy icon

Create a program i Prolog. You can either invent your own problem to solve or use one of the ideas described below. The program should include facts and rules. Also a set of meaningful questions to the program should be presented. Please push to github and supply a README.md file.

Student calendar Student free icon

Create a program that models students, classes, rooms, dates, and their relations.

First thing we did, was to come up with some data 📋:

class(a, mo).
class(a, hallur) .
class(b, lars).
class(b, jens).
class(c, ali).
class(d, tom).
class(a, kasper).

class_date(date(2019, 7, 30), a).
class_date(date(2019, 5, 30), b).
class_date(date(2019, 3, 30), c).
class_date(date(2019, 3, 30), d).

room(a).
room(b).
room(c).
room(d).

student(mo).
student(hallur).
student(jens).
student(lars).
student(kasper).
student(ali).
student(tom).

Secondly, we wrote down some ideas for methods, that had the requirement of including facts and rules

  • get all information on a student
  • does student a go in the same class as student b
  • does student a go to class at the same date as student b
  • get all students
  • get all classes
  • get all dates

To see the original file, click here 📃

Commands in SWI-Prolog

Open the ass2.pl file in SWI then run those commands Command Window free icon :

  • getStudentInfo(hallur) .
    getStudentInfo(A):- 
        class(Class, A),
        writeln(Class),
        class_date(D, Class),
        writeln(D).
    
  • sameClass(mo, hallur) .
    <li>sameClass(mo,hallur) .
    sameClass(A,B):-
       class(Class, A),
       class(Class,B),
       writeln(Class).
       
  • sameDate(ali, tom) .
    sameDate(A,B):-
       class(ClassA, A),
       class(ClassB,B),
       class_date(StudentDate, ClassA),
       class_date(StudentDate, ClassB),
       writeln(StudentDate).
       
  • getAllDates() .
    getAllDates():-
       forall(class_date(ClassDates, S), writeln(ClassDates)) .
  • getAllStudents() .
    getAllStudents():-
       forall(student(Student) ,
       writeln(Student)) .
       
  • getAllClasses() .
    getAllClasses():-
       forall(room(Name), writeln(Name)) .
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Prolog 100.0%