1
$\begingroup$

So here is my question:

Is there an algorithm that generates a pattern, in which when comparing each subsequent number, every number is a rounded version of the previous number, rounded down 1 place-value.

For example, the pattern generated from this algorithm could be:

1848  185  19  2

Every number after the first number in the pattern is a rounded form of the previous number.

My research online has held no results to such an algorithm that can generate a series of number like this. Do any of you possibly know?

EDIT

In response to a mistake on my question, I am seeking an algorithm in which the numbers generated don't have to be floored. Or modified after being generated.

Optimally the algorithm I am seeking should generate the numbers already in integer form.

$\endgroup$
1
$\begingroup$

Along the same lines as Yujie's answer is (but without explicitly using floor function): $x_{n+1} = (x_n + 5 - (x_n+5 \mod 10))/10$.

Alternatively, since the OP asked for "an algorithm", I'd infer that means more latitude than a recurrence relation. For example an algorithm could be:

  1. Add 5
  2. Drop last digit
  3. Output result
  4. Goto 1 unless result is less than 10.
$\endgroup$
  • $\begingroup$ This is much more in line with what I was looking for, as the "alternative floor method" in the mod function is in my opinion more elegant, and provides a solid-integer at the end of generation. Thank you so much for this answer! $\endgroup$ – Cubit Industries May 11 '17 at 0:20
3
$\begingroup$

You could do

$x_{n+1} = \lfloor \frac{x_n + 5}{10} \rfloor$, here the division is integral division (i.e. floor of the divided result).

$\endgroup$
  • $\begingroup$ This answer was insightful, as it made me google what Subscripts were and thus taught me something new, however it isn't what I was looking for. I'm looking for such an algorithm where the numbers generated are already integers, and don't require me to floor them. If it does take too long to get the answer I am seeking however, then I will go ahead and mark your's as the answer to hopefully help others in the future.Thanks for your response :). $\endgroup$ – Cubit Industries May 10 '17 at 18:35
  • $\begingroup$ @CubitIndustries Ah, Ok. I kinda see your point. No problems! $\endgroup$ – Yujie Zha May 10 '17 at 19:12
  • 1
    $\begingroup$ @CubitIndustries Please add the condition you describe in this comment to the OP. That way folks don't give an answer to a question, only to find out the question was incomplete. $\endgroup$ – Χpẘ May 10 '17 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.