Define a predicate same-digits? (a b) which returns #t if the integers a and b contain the same digits. If a digit occurs n times in a, it must also occur n times in b. For example, (same-digits? 133042 420313) → #t, but (same-digits? 133042 42013) → #f.

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Topic Video
Question
  1. Define a predicate same-digits? (a b) which returns #t if the integers a and b contain the same digits. If a digit occurs n times in a, it must also occur n times in b. For example, (same-digits? 133042 420313) → #t, but (same-digits? 133042 42013) → #f.

     

To solve the problem, one technique would be to add some extra procedures for manipulating digits inside a number. Here are some hints:

  • To find the number of digits in a number, count how many times you need to divide it by 10 until you reach 0.
  • To extract the second digit of 5784: floor( 5784/102 ) mod 10=7. Note that mod in racket is modulo or remainder
  • To assemble the digits 3, 4, and 5 into a number: 3×102+4×101+5×10= 345

The standard Scheme procedures modulo and floor may prove useful. The solution only needs to consider non-negative integers.

Or..... you could "cheat" and convert each number to a list, sort, and check for equality.

check_circle
Expert Solution
Step 1

Given:-

# source_code

       # lang racket/base

      # lang racket/base

           (define(reverse_digit n)

            (define(loop n reserved_Num)

             (if (<=n 0 )

                  reversed_ Num

                    (let((lastDigit(modulo n  10)))

                 (loop(/(-n lastDigit)10)(+(*reversed_Num 10)lastDigit)))))

            (loop n 0)   

                (reserve_digit 397164)

           

 

Output:

              461793


    
 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Propositional Calculus
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, advanced-math and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,