bob fissle wrote:I'm trying to write a loop that will print to the buffer based on the following conditions:
The example above is a dumbed down version of what I'm trying to do, I'm mainly interested in the logic. Please assume that variables a and b will have an infinite amount of numbers -- for the sake of this example. The main point that i'm trying to illustrate is the pattern in the variables a and b; a starts with 0 and 1, and then every other two numbers are found in the variable a, and the opposite for b. I'm trying to figure out how to write logic that will print out values a or b based on the pattern described above inside a loop.
bob fissle wrote:
I DON'T want to hardcode all possible values for variables a and b
Jeff Verdegan wrote:
bob fissle wrote:
So, is there a pattern, a set of rules, that determines which numbers are in set A and which are in set B? If so, write code that matches that pattern. If you need help with that, you'll have to spell out the rules
bob fissle wrote:
That's the main issue that I'm having, determining a way to code the "rule"/pattern.
Here's the pattern again:
a = 0,1,4,5,8,9,12,13,16,17 and son on..
b = 2,3,6,7,10,11,14,15,18,19 and so on..
a starts the pattern with 0 and 1 and includes other next set of consecutive numbers
Jon Swanson wrote:Are you really looking for the pattern 0,1,4,5,8,9...? or 2,3,6,7,...? One thought that occurs to me is that if you use i/2 you get 0,0,2,2,4,4... and 1,1,3,3,... and you can then test whether (i/2) % 2 is zero or not. Of course, that assumes the exact pattern that you showed.
bob fissle wrote:I'm trying to write a loop that will print to the buffer based on the following conditions:
The example above is a dumbed down version of what I'm trying to do, I'm mainly interested in the logic. Please assume that variables a and b will have an infinite amount of numbers -- for the sake of this example. The main point that i'm trying to illustrate is the pattern in the variables a and b; a starts with 0 and 1, and then every other two numbers are found in the variable a, and the opposite for b. I'm trying to figure out how to write logic that will print out values a or b based on the pattern described above inside a loop.
Sebanti Sanyal wrote:
Please check if the following code works.
Runrioter Wung wrote:
... some code...
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|