Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dr . Eva Thomas is an underwater geographer studying mountains and valleys in the Atlantic Ocean. She models mountain and valley ranges using integers whose

Dr. Eva Thomas is an underwater geographer studying mountains and valleys in the Atlantic Ocean. She models mountain and valley ranges using integers whose digits alternate between increasing and decreasing. You have been hired to write a program that, given two integers a and b, determines how many numbers model mountain and valley ranges in the range between a and b, inclusive.
An n-digit integer, for n >=2, with digits d1d2d3d4...dn models:
a mountain range if it has the pattern /\/..., that is, d1< d2 d2,> d3, d3< d4, etc.
a valley range if it has the pattern \/\..., that is d1> d2, d2< d3, d3> d4, etc.
Examples:
1503 has 1<5,5>0, and 0<3, so it models a mountain range.
7120 has 7>1,1<2, and 2>0, so it models a valley range.
7113 has consecutive 1s, so it models neither.
For a =15 and b =25, the answer is 8 mountain ranges and 2 valley ranges.
The numbers 15,16,17,18,19,23,24, and 25 are mountain ranges.
The numbers 20 and 21 are valley ranges.
The number 22 is neither a mountain nor a valley range.
For a =1234 and b =4321, the answer is 753 mountain ranges and 351 valley ranges.
For a =10 and b =1000, the answer is 276 mountain ranges and 330 valley ranges.
See the following how we got the solution for a =15 and b =25, and how to handle 2,3, or 4 digits. These are examples of some of the cases; your program will need to account for more digits.

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

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago