Write a predicate (function that returns t or nil) that answers the question: Is this year a leap year?

Examples:

(leap-yearp 1995) => NIL
(leap-yearp 1996) => T
(leap-yearp 1900) => NIL
(leap-yearp 2000) => T

TASK-B WRITE A RECURSIVE FUNCTION THAT RETURNS ALL THE FACTORS OF (I.E. NUMBERS THAT DIVIDE EVENLY INTO) A POSITIVE INTEGER EXCEPT FOR 1 AND THE NUMBER ITSELF.

For example:

> (factors 31)
NIL
> (factors 32)
(2 4 8 16)
> (factors 33)
(3 11)

Hints:

  • You will probably need some sort of helper function, along the lines of that described below, but it can be a separate function.
  • Note that no factor can be bigger than half the original number.
  • You may want to use the REM function.

TASK-D

  • Write a recursive function that performs a binary search on a binary tree of sorted numbers represented as a list. For example, the binary tree:     4
       /
     2     6
    /   /
    1  3  5   7
    can be represented as: (4 (2 1 3) (6 5 7)). The function should return T (or the number itself) if the number is found, NIL if it is not.For example:> (defvar prime-tree ‘(17 (5 (2 1 3) (11 7 13))
                             (31 (23 19 29) (41 37 43))))
    PRIME-TREE

    > (binary-search 3 prime-tree)
    T

    > (binary-search 4 prime-tree)
    NIL

    > (trace binary-search)
    (BINARY-SEARCH)

    > (binary-search 4 prime-tree)
    0: (BINARY-SEARCH 4 (17 (5 (2 1 3) (11 7 13)) (31 (23 19 29) (41 37 43))))
      1: (BINARY-SEARCH 4 (5 (2 1 3) (11 7 13)))
        2: (BINARY-SEARCH 4 (2 1 3))
          3: (BINARY-SEARCH 4 3)
          3: returned NIL
        2: returned NIL
      1: returned NIL
    0: returned NIL
    NIL

    > (binary-search 43 prime-tree)
    0: (BINARY-SEARCH 43 (17 (5 (2 1 3) (11 7 13)) (31 (23 19 29) (41 37 43))))
      1: (BINARY-SEARCH 43 (31 (23 19 29) (41 37 43)))
        2: (BINARY-SEARCH 43 (41 37 43))
          3: (BINARY-SEARCH 43 43)
          3: returned T
        2: returned T
      1: returned T
    0: returned T
    When you test this out, the function will be traced. You should see the same levels of the search shown, at least if the code is interpreted.
    Task-E Card game basics with some global variables
    Assume you are starting to work on a card game.
    Set the value of the global variable *standard-suits* to ‘(hearts diamonds clubs spades) and the global variable *standard-values* to ‘(ace king queen jack 10 9 8 7 6 5 4 3 2).
    Create a recursive function, MAKE-DECK, which takes two arguments, a list of suits and a list of values and creates a full deck from these (i.e., ((ace hearts) (king hearts) …), and assigns it to the global variable *deck*. (Note: It’s generally preferred to minimize the use of global variables to avoid unintended consequences, but this exercise uses them for demonstration purposes.)
    Create a recursive function, SHUFFLE, which takes a deck (as created above) as an argument and shuffle