You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A collection of the practice problems for CS403. These are the most recent recommended practice problems and they can be found here. Each language (Scheme, Haskell, Prolog, Smalltalk, Cilk) has their own table of problems that you can find below. You can find the exam problems here.
Write a filter function such that (filter P L) returns the elements in list L for which predicate P yields #t. Example: (filter (lambda (x) (> x 0)) '(1 -2 3 -4 5 0 8 9)) returns (1 3 5 8 9).
Write a reject function such that (reject P L) returns the elements in list L for which predicate P yields #f. Example: (reject (lambda (x) (> x 0)) '(1 -2 3 -4 5 0 8 9)) returns (-2 -4 0).
Write an applyeach function such that (applyeach L1 L2) applies each function in list L1 to the corresponding value in list L2. Example: (applyeach (list car cdr length null? last) '((1 2) (4 5 6 7) (8 9 10) (11 12) (13 14))) returns (1 (5 6 7) 3 #f 14).
Write function (forall P L) which returns #t iff all values in L satisfy predicate P. Also write function (exists P L) which returns #t iff some value in L satisfies predicate P.
Write a filter function such that (filter P L) returns the elements in list L for which predicate P yields #t. Example: (filter (lambda (x) (> x 0)) '(1 -2 3 -4 5 0 8 9)) returns (1 3 5 8 9).
Write a reject function such that (reject P L) returns the elements in list L for which predicate P yields #f. Example: (reject (lambda (x) (> x 0)) '(1 -2 3 -4 5 0 8 9)) returns (-2 -4 0).
Write an applyeach function such that (applyeach L1 L2) applies each function in list L1 to the corresponding value in list L2. Example: (applyeach (list car cdr length null? last) '((1 2) (4 5 6 7) (8 9 10) (11 12) (13 14))) returns (1 (5 6 7) 3 #f 14).
Write function (forall P L) which returns #t iff all values in L satisfy predicate P. Also write function (exists P L) which returns #t iff some value in L satisfies predicate P.
Create a database of your family members. Include facts and rules for parent, father, mother, child, son, daughter, sibling, brother, sister, grandparent, grandchild, ancestor, descendant, aunt, uncle, niece, nephew, cousin. Try to have as few facts as possible, and then use rules as much as possible to infer all the remaining relations.
Write predicates power(M,N,X), log(M,Q,X), and comb(N,K,X) which are analogous to the Scheme functions described above. Here X denotes the result value.
Write predicates insertion_sort(L,Z), selection_sort(L,Z), merge_sort(L,Z), and quick_sort(L,Z). Here L is a list, and Z is the same list rearranged into sorted order. You will also need to write some helper functions.
We can store a binary search tree in Prolog as a nested list that has this structure: [root, left_subtree, right_subtree]. Write the predicate member(X, T) which succeeds iff X is a key in binary search tree T. Also write predicates insert(X, T, NewT) and remove(X, T, NewT) where NewT denotes the resulting modified tree.
Write classes in Smalltalk that implement each of these abstract data types: fraction and complex number. Provide methods for standard arithmetic operations such as +, -, *, /, and =.
Write classes in Smalltalk that implement each of these abstract data types: stack, queue, deck (double-ended queue), and binary search tree. Provide methods for adding and removing elements, for traversing the data structure, and iterator methods such as do: and collect:.
Write functions that select all the odd elements or all the negative elements in a given 1D or 2D array. Also write a general "filter" function for a 1D array.
Write a function that counts the number of times each letter A through Z appears within a given string, and return these counts in an array of size 26.
Write a function that approximates pi/4 by generating random pairs (x, y) of floats in the range -1 to 1 and counting how many pairs are within the unit circle centered at (0, 0).