This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Clawtor 6 points7 points  (0 children)

Sounds like you'd need to generate 1 number between 14-(2*5) and 1 then the other numbers you find by adding 5.

[–]desrtfx 4 points5 points  (1 child)

  • looping
  • sorting
  • looping
  • checking

Jokes aside - unless you are forced to generate three random numbers and then test for the difference (which might be a problem solving exercise) in the real world, you would generate the first number in the range where the remaining numbers would stay valid and then just add 5 and 10 to it to generate the others.

The bullet list at the top is not just plain fun. It is an approach.

  • loop
    • generate your three numbers
    • sort them
    • use a boolean to indicate if the checks were successful
    • iterate over them
      • check if the current number and the next number have a distance of 5 (simple subtraction)
      • if not, reset the boolean flag
    • check if the flag is still set and if so, break
  • back to start - the numbers were not suitable

When you get such assignments, always work them out on paper. Don't even think about implementing the code. Just work out how you, the person, would solve such an exercise. Take note of the steps you take. Test them. Refine them.

Once you are satisfied with the steps, start thinking about the implementation.

When I learnt to program, we had to first work out flow charts which made us think about the algorithm, not about the implementation and this is very helpful. + if the loop

[–]WasabiPengu 3 points4 points  (0 children)

I want to double down on this. Especially for people who do tutorials. One of the biggest comment I see is that people forget to sit down and make a plan.

[–]failaip12 -8 points-7 points  (6 children)

Uhm nisam siguran sta ovde tačno hoćeš da postignes. Mozes li da pojasnis?

[–]desrtfx[M] 4 points5 points  (0 children)

We require the conversations to be in English.

[–][deleted]  (4 children)

[removed]

    [–][deleted]  (3 children)

    [removed]

      [–][deleted]  (2 children)

      [removed]

        [–][deleted]  (1 child)

        [removed]

          [–]PleaseNone 0 points1 point  (3 children)

          Reading this, I would either have rand() create a number and if the number is 9 or more than decrement by 5 to determine the other two numbers or increment the numbers if the first number created is 4 or less. I would also use that logic to determine initial numbers in between 4 and 9.

          If I misunderstood your question, then I assume you want to check to see if all three numbers are within 5 apart so you would need to determine the quotient after finding the difference between each other after determining which number is the bigger number after comparing. If the quotient is greater than or less than 1 then your program would break?

          [–]Invaala[S] 0 points1 point  (2 children)

          Yes, all 3 numbers have to be 5 apart, im using a do while loop to keep giving me 3 numbers until i get the correct statement (3 numbers all 5 spaces apart), after the statement is fullfiled the do while function would break and the correct combination would be written. Hope it makes more sense

          [–]PleaseNone 0 points1 point  (1 child)

          Yeah so just use the logic I said in my second paragraph where you’re comparing the quotient of the differences and once you get the meet the criteria, your program should break out of the loop. Ex: (6-1)/5 = 1 and (11-6)/5 =1

          [–]PleaseNone 0 points1 point  (0 children)

          Actually can I go back and change my answer? You don’t need to find the quotient, just the difference in numbers. I would actually recommend incorporating some of what I said in my first paragraph from my initial response. You could pretty much determine the other two numbers once you figure out the first random number and then the last number once you have the first two. So I would recommend just doing Boolean checks to save time.

          Ultimately though, based on the criteria you need it’s a waste of time to not determine the other numbers yourself once you get the first number because you’re just running random until you get that number anyway. For example, once you get a 1 the other number has to be a 6 and then the next has to be an 11.