Write a function differBy which takes two arguments, a number N and a list of numbers L, and returns a new list containing all pairs of adjacent (side-by-side) numbers X and Y in the list L where the difference between X and Y is exactly N. Each such pair of numbers should be in a sublist of the returned list. For example, the call (differBy 1 (4 3 56734)) returns the list ((4 3) (5 6) (6 7) (34)) because the input number N is equal to 1, and the first two numbers (4 and 3) differ by 1, as do the third and fourth numbers (5 and 6), the fourth and fifth numbers (6 and 7) and the sixth and seventh numbers (3 and 4). Note that pairs of numbers are returned in the order they appear in the input list.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

10

Can someone please answer the following question in LISP/RACKET

 

Write a function differBy which takes two arguments, a number N and a list of numbers L, and returns a new list containing all pairs of adjacent (side-by-side) numbers X and Y in the list L where
the difference between X and Y is exactly N. Each such pair of numbers should be in a sublist of the returned list.
For example, the call
(differBy 1 '(4 3 567 3 4))
returns the list
((4 3) (5 6) (6 7) (3 4))
because the input number N is equal to 1, and the first two numbers (4 and 3) differ by 1, as do the third and fourth numbers (5 and 6), the fourth and fifth numbers (6 and 7) and the sixth and
seventh numbers (3 and 4). Note that pairs of numbers are returned in the order they appear in the input list.
For example:
Test
Result
((4 3) (56) (6 7) (34))
(differBy 1 (4 3 5 6 7 3 4))
(differBy 2 (8 6 5 6 4 2) )
((8 6) (64) (42))
(differBy 3 (5 1 4 8 5 2 3))
((1 4) (8 5) (5 2))
Transcribed Image Text:Write a function differBy which takes two arguments, a number N and a list of numbers L, and returns a new list containing all pairs of adjacent (side-by-side) numbers X and Y in the list L where the difference between X and Y is exactly N. Each such pair of numbers should be in a sublist of the returned list. For example, the call (differBy 1 '(4 3 567 3 4)) returns the list ((4 3) (5 6) (6 7) (3 4)) because the input number N is equal to 1, and the first two numbers (4 and 3) differ by 1, as do the third and fourth numbers (5 and 6), the fourth and fifth numbers (6 and 7) and the sixth and seventh numbers (3 and 4). Note that pairs of numbers are returned in the order they appear in the input list. For example: Test Result ((4 3) (56) (6 7) (34)) (differBy 1 (4 3 5 6 7 3 4)) (differBy 2 (8 6 5 6 4 2) ) ((8 6) (64) (42)) (differBy 3 (5 1 4 8 5 2 3)) ((1 4) (8 5) (5 2))
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY