Question
Can you help me solve this problem on Racket In this problem, you will write functions that examine the individual digits of an Integer. For
Can you help me solve this problem on Racket
In this problem, you will write functions that examine the individual digits of an Integer. For instance, the number 122333 is both a number over one hundred thousand, and a number comprised of six digits: one 1, two 2s, and three 3s when viewed as a decimal number.
We can use basic mathematical operations to access the individual digits of any such number, by exploiting how the place-value system (also known as "positional notation") works: think about how to get the digit in the ones place, and how to get the set of digits that result from "chopping off" the ones place using simple operations.
If we want to investigate a property of the digits of an arbitrary number, we would need to examine the digits in turn, but we cannot anticipate how many there are in advance. Recursion gives us the ability to scan down the digits, however many there may be.
We need to be precise about how to handle zeros in the decimal representation of a number. For instance, the number 15100 has two zeros. But the exact same number can be written as 015100 -- this has the same mathematical value, but appears to have three zeros. These so-called "leading zeros" do not change the value of the number, and we can have arbitrarily many of them, confusing the issue of counting the number of zeros in a number. For this problem, we will never attempt to count leading zeros.
On a related note, consider the number 0 itself. We write a single digit, the digit 0, when we write this number. But it serves almost as a placeholder to show that there is a number being written; arguably this digit is itself a leading zero in front of a blank number. So, we will consider the number 0 to have no digits at all, for the purposes of this problem.
Write the following functions:
contains-digit?, which takes in an Integer, representing a number, and a second Integer, representing a single digit, and evaluates to true if and only if at least one copy of that digit is present in the number; it is an error to be given a digit outside of the range 0-9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started