Interpretation of an algorithm

Asked

Viewed 586 times

3

I have to solve a problem with the following statement:

The houses on that street

Context

A computer programmer lives on a street with houses only on one side. The houses on this street are numbered sequentially starting from number 1 (one). Every day the programmer leaves home to walk and, randomly choosing a direction, right or left, goes to the end of the street and back. One day she decided to add up the numbers of the houses she passed on the way to and from, excluding her own home. The other day she took the other direction and also added the numbers of the houses she passed, on the way and on the way back, excluding the house itself. To your surprise the sums were equal.

Description

Write a program that prints pairs of integer and positive numbers, the first representing the number of a house and the second representing the number of houses on the street, such that the property observed by the programmer occurs. For example, the first pair of numbers with this property is 6 and 8. That is, if the programmer lives in house 6 on a street that has 8 sequentially numbered houses, then the sum of the houses on the way back and forth to the end of the street will be the same in both directions. The second pair with this property will be 35 and 49.

I have not yet noticed the "math" and/or relationship behind these street houses. For example: the first pair is 6 and 8, the second is 35 and 49. What is the relationship between them? Could someone explain to me or create a simple model in pseudocode so that I have an idea?

  • I think the question is clearer now ;)

  • 1

    Curious question. I think the question is very objective, it does not ask for an opinion, it is clear what you are asking, it is not so wide, it seems to me to be part of our focus and it is certainly not duplicated. Because I still think it’s bad? Is it because the OP has done nothing and wants it done? I don’t even know if it is. But if it is, it’s a matter of negative and not close.

  • I don’t want anything ready. I just said I didn’t understand the problem command, so I’m not able to do it in code.

  • I edited the question including the main part of the statement here on the website. So it is easier to understand than you are talking.

  • Much better that way, thank you!

  • @Lucas took the liberty of changing his question a little more, because the tag c it didn’t seem relevant to her. I also traded "portugol" for "pseudocode", not everyone knows what is portugol, I think you will have more chances if you stay like this, however if you prefer can undo the changes

  • It’s just fine. Thank you!

  • 2

    You speak in Portugol but used the tag of C. This is not clear what you need. People think it’s unclear what you want. Could you give more information than you want or try to explain better what you need? I even understood. Some people might think that you haven’t tried anything before posting something here and want it all done. If it’s not that, you could post what you understood of the statement, what you’ve managed to do even if wrong?

  • Sorry anything, it’s the first time I ask a question here. Well, I didn’t do anything precisely because I didn’t understand what to do. I have not yet noticed the "math" and/or relationship behind these street houses. For example: the first pair is 6 and 8, the second is 35 and 49. What is the relationship between them? I don’t understand.

  • 1

    Well, the assistance to improve the question is great! I just don’t know if the title needs the "in C" c/c @NULL

  • 2

    @brasofilo state of "affection" taking care of the people, rsrs

Show 6 more comments

1 answer

5

As shown in the example: (6,8)

The programmer lives in house 6 of 8, so:

//Right:

{7,8} -> 7 + 8 = 15

Left:

{1,2,3,4,5} -> 1 + 2 + 3 + 4 + 5 = 15

Pseudocode

Inteiro esquerda = 0
Inteiro direita = 0 
//Direita
Para i = numeroCasaProgramadora faça:
     Se i < UltimaCasa Então:
        direita + = 1
     i + = 1
//esquerda
Para i = numeroCasaProgramadora faça:
     Se i > 0 Entao:
        esquera + = 1
     i - = 1    
Se esquerda == direita Então:
   Imprime "O par " + numeroCasaProgramadora + " e " + UltimaCasa + "é válido"
  • Now I get it. I’m going to try to create an algorithm. Thank you very much!

  • @Lucas you can post what you can do after you understand to help other people too.

  • @Bigown Ok! If everything goes well, tomorrow put the result here. Thanks for everything ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.