1

The algorithm is as follows:

 Input m 
 if m < 0 then {m = - m}
 repeat_until { (m <= 5) } { m = m-1 }

Now, here is what I would like to know:

  1. What is the value of (m) to skip the loop?
  2. What is the value of (m) to enter the loop once?

I've tried to implement the algorithm in Scratch, and analyzed what could be the answer to the questions. However, I would like to know multiple opinions on what could be the answer to those 2 questions.

CrSb0001
  • 151
  • 1
  • 11
  • When you are asking for opinions, then stackoverflow.com is off-topic (sorry!) see: [What topics can I ask about here?](https://stackoverflow.com/help/on-topic)) Maybe https://math.stackexchange.com/ is a better place to ask ? – Luuk Mar 12 '23 at 17:59
  • 1
    There is only one answer to each question. Hint: Consider m = 1, m = 2, m = 3, m = 4, .... In particular, consider values of `m` around `5` (+/- 1) since you only ever enter the loop if `m` is less than or equal to five. – Aleksandr Hovhannisyan Mar 12 '23 at 18:08
  • @Jurakin That is both incorrect, and irrelevant to the question. – Ruud Helderman Mar 14 '23 at 20:30
  • 1
    @AleksandrH "There is only one answer to each question." There are two; you forgot negative numbers. – Ruud Helderman Mar 14 '23 at 20:34
  • @AleksandrH "you only ever enter the loop if `m` is less than or equal to five." Incorrect; this is an 'until' loop, not a 'while' loop. – Ruud Helderman Mar 14 '23 at 20:40

2 Answers2

0

Just to illustrate the value of properly asked question...

I would like to know multiple opinions on what could be the answer to those 2 questions.

Q. 1: -6, -5,..0,..4, 5, 6.

Q. 2: -6, -5,..0,..4, 5, 6.

Now you have "multiple opinions". What is a value in that?

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
0

For question 1:

To skip the loop, you will have to have a number that when you take the absolute value of it, it will equal 5. Now, knowing m is equal to m-1:

Put this into this format: |m-1|=5

There are going to be 2 values where this will be true: m-1+1=5+1 (adding 1 to both sides) to get m=6, or:

-(m-1)(-1)=5(-1) => m-(1(-1))=-5 => m-(-1)=-5 => m+1-1=-5-1 => m=-6

So we know that variable m must be equal to 6 or -6

Now for question 2:

Since we know that the range of numbers required to have the loop run is
-6 -> 6, the values of m required to be inside of the loop are
-6, -5, -4,...4, 5, 6.

Here's the code for it that I threw together rather quickly:

Hope this helps!

Edit: just realized that this code is only good when |m| is less than 5, sorry! Here's a new image that correctly answers the code solution:

CrSb0001
  • 151
  • 1
  • 11