Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Define a function MY-SUBLIST that takes two proper lists of atoms L1 and L2 and returns T only if L1 is a sublist of

1. Define a function MY-SUBLIST that takes two proper lists of atoms L1 and L2 and returns T only if L1 is a sublist of L2. Use EQ to test for equality of corresponding elements. Testing input:

(MY-SUBLIST '(1 2 3) '(1 2 3 4 5)) T

(MY-SUBLIST '(3 4 5) '(1 2 3 4 5)) T

(MY-SUBLIST '(C D) '(A B C D E)) T

(MY-SUBLIST '(3 4) '(1 2 3 5 6)) NIL

(MY-SUBLIST '(1 2 3 4 5) '(3 4 5)) NIL

(MY-SUBLIST '(2 4) '(1 2 3 4 5)) NIL

(MY-SUBLIST '(1 3 5) '(1 2 3 4 5)) NIL

2. Define a function MY-ADD that takes two proper lists of single digit integers, N1 and N2, which represent large magnitude positive integer numbers called big-nums, and returns a list in this big-num representation corresponding to adding the two big-nums N1 and N2. Each element of a big-num is in the range 0 to 9. big-nums are stored in reverse order so that the first element is the ones digit, the second element is the tens, the third is the hundreds, etc. Be sure to handle carry, and ensure no integer element exceeds 9 in value. Valid big-nums will never be nil from the start. Zero is represented by the list (0), 10 is (0 1), 1999 is (9 9 9 1). (This is a LeetCode problem testing fluency with singly linked lists, the hardest problem this week. Handling the carry and dealing with numbers of different lengths are the hard parts.)

(MY-ADD '(0) '(0)) (0)

(MY-ADD '(1) '(1)) (2)

(MY-ADD '(9) '(9)) (8 1)

(MY-ADD '(1 1 1 1 1 1 1 1 1 1) '(9 9 9 9 9 9 9 9 9 9)) (0 1 1 1 1 1 1 1 1 1 1)

(MY-ADD '(1) '(9 9 9 9 9 9 9 9 9 9)) (0 0 0 0 0 0 0 0 0 0 1)

PLEASE EXPLAIN THE CODE AND MAKE SURE ALL CASES PASS. ALSO PLEASE NOTE THE BELOW CONSTRAINT:

Pure Lisp, limited to only the following Common Lisp functions:

DEFUN

COND

CONS

CAR

CDR

QUOTE

EQ, EQUAL

NULL

ATOM

LISTP

SYMBOLP, STRINGP, NUMBERP

AND, OR, NOT

APPLY

any arithmetics +, -, *, /, <, >, 1+, 1-, MOD, FLOOR

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions