Can you guys point me out a formula? A number sequence, it has to begin with number from 0 to 45 has a 5 step, and if it comes to 0 or 45 it will continue decreasing or increasing. It’s like 10 15 20 25 30 35 40 45 40 35 30 25 20 15 10 5 0 5 10 15 etc.
Yes, I got there too, but how do you return from 45 to 0 back again?
Yes, but I want to begin with a random number not 0 or 45 but maybe 25 or 40, it has to know that the sequence goes backwards when reached 45 or 0
Ok, after doing some research its called an oscillating sequence.
Probably should be solved with some imperative code, which I’ll let others handle. But it’s fun doing it with geometry as well! (And very expensive, computationally speaking…)
The simplest option would be to build a “cache” of values and fetch only what you need from that:
A more interesting and efficient approach would be to create a generator. DS doesn’t have an equivalent to the yeld call, so here’s a python example instead:
The second solution is impressive and I believe you programming guys call it syntactic sugarish. Thank you all.