ICS 361 -- ARTIFICIAL INTELLIGENCE PROGRAMMING

Logic Programming

Assignment #6

This assignment worth 100 points.

  1. (20 P) Create a PROLOG program LISTLENGTH that counts the number of items (at the top level) in a list.
    LISTLENGTH([9, 5, 6, 4],L).
    RETURNS ==>   L = 4. 
    LISTLENGTH([5, [6, 7, 8]], L).
    RETURNS -->   L = 2  
  2. (20 P) Create a recursive FACTORIAL program in PROLOG. Your program should work for Integers N >= 0 (include a check for negative numbers).
    MYFAC(0,X).
    RETURNS ==> X = 1
    MYFAC(3, Z).
    RETURNS ==> Z = 6 
  3. (60 P) Find solutions for each of the following colored ball problems with different sets of constraints.
  4. (25 P) Extra Credit - Write a functor named SPLIT3(N,L) that takes two parameters: N, A POSITIVE INTEGER, AND L, A LIST OF POSITIVE INTEGERS. You may assume that the list L is flat, i.e., it does not contain sublists.
    The functor SPLIT3 returns TRUE if the list L can be partitioned into three sublists (with elements in the same oder), such that the sum of the integers in each subset is less than or equal to N. Otherwise, it returns FALSE. Examples:
    ?-SPLIT3(5,[]).
    FALSE
    ?-SPLIT1(6,[5, 5, 12]).
    FALSE
    ?-SPLIT3(14,[6, 5, 10, 1, 1, 1, 14]).
    TRUE
    ?-SPLIT3(5,[3, 1, 4, 1, 2]).
    TRUE
    ?-SPLIT3(6,[4, 3, 5, 2, 1]).
    FALSE
    ?-SPLIT3(7,[4, 5, 7, 2, 3]).
    FALSE
    ?-SPLIT3(8,[3,5,4,2,7,1]).
    TRUE. 
    ?-SPLIT3(3,[1, 2, 2, 2, 1, 1]).
    FALSE
    

Turn in the following:

Plain text files containing your code and scripts. A report with your results and discussion in a standard format like rtf, pdf, or text.

(c) N. E. Reed, 2004-2016