Write a function divisibleBy which takes two arguments, a numberN and a list of numbers L, and returns a new list containing all numbers X in the list L where either X divides N exactly, or N divides X exactly. You can assume that all numbers will be integers, and you can assume that the input number N will never be 0 (but numbers in the list L may be 0). You probably want to use the built-in modulo function here. The call (modulo X N) gives the remainder you get after dividing X by N. For example, the call (divisibleBy 10 '(4 30 11 5 0)) returns the list (30 5 0) because 10 divides 30 exactly (3*10=30), 5 divides 10 exactly (5*2=10), and 10 divides 0 exactly (10*0 = 0). A hint: Notice a mathematical quirk here: every number E divides exactly into 0: (modulo 0 E)=0 for all possible numbers E, but you cannot divide a number by 0: (modulo E 0) will give a "divide-by-zero" error. This means that you will need to add a special case to your function to "catch" the situation where an element (car L) in the list L is equal to 0, to make sure you don't call (modulo E (car L)). For example: Test Result (divisibleBy 10 '(4 30 11 5 0)) (30 5 0) (divisibleBy 6 '(2 6 1 9 18) ) (2 6 1 18)
Write a function divisibleBy which takes two arguments, a numberN and a list of numbers L, and returns a new list containing all numbers X in the list L where either X divides N exactly, or N divides X exactly. You can assume that all numbers will be integers, and you can assume that the input number N will never be 0 (but numbers in the list L may be 0). You probably want to use the built-in modulo function here. The call (modulo X N) gives the remainder you get after dividing X by N. For example, the call (divisibleBy 10 '(4 30 11 5 0)) returns the list (30 5 0) because 10 divides 30 exactly (3*10=30), 5 divides 10 exactly (5*2=10), and 10 divides 0 exactly (10*0 = 0). A hint: Notice a mathematical quirk here: every number E divides exactly into 0: (modulo 0 E)=0 for all possible numbers E, but you cannot divide a number by 0: (modulo E 0) will give a "divide-by-zero" error. This means that you will need to add a special case to your function to "catch" the situation where an element (car L) in the list L is equal to 0, to make sure you don't call (modulo E (car L)). For example: Test Result (divisibleBy 10 '(4 30 11 5 0)) (30 5 0) (divisibleBy 6 '(2 6 1 9 18) ) (2 6 1 18)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
THIS HAS TO BE WRITTEN IN THE
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education