Avoiding too many GOSUBs, possible?
Hello.
I have some code, which, based on value of the X variable (changes from 1 to 30)
Should call some GOSUBs as shown below:
Code:
IF X=1 THEN GOSUB ONE
IF X=2 THEN GOSUB ONE: GOSUB TWO
IF X=3 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE
IF X=4 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE
IF X=5 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE: GOSUB TWO
IF X=6 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE: GOSUB TWO: GOSUB THREE
This is from 1 to 6, but I have to do it up to 30, and there it gets way too long. So maybe there's some way to make things less complex?
One way I see it to create another set of GOSUBs, each for group of 3, like
[code]
ONE-X:
GOSUB ONE
RETURN
TWO-X:
GOSUB ONE: GOSUB TWO
RETURN
THREE-X:
GOSUB ONE: GOSUB TWO: GOSUB THREE
RETURN
[code]
But how to "split" the X in the proper way?
So for example, when X=8, THREE-X will be called 2 times and ONE-X - 1 times?
Re: Avoiding too many GOSUBs, possible?
[QUOTE=CuriousOne;154813]Hello.
I have some code, which, based on value of the X variable (changes from 1 to 30)
Should call some GOSUBs as shown below:
Code:
IF X=1 THEN GOSUB ONE
IF X=2 THEN GOSUB ONE: GOSUB TWO
IF X=3 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE
IF X=4 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE
IF X=5 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE: GOSUB TWO
IF X=6 THEN GOSUB ONE: GOSUB TWO: GOSUB THREE: GOSUB ONE: GOSUB TWO: GOSUB THREE
I am just sitting here with a cup of coffee and wondering if this might work?
Code:
FOR LP = 1 to X/3
[If X//3 = 0 THEN] GOSUB ONE: GOSUB TWO: GOSUB THREE
? NEXT LP
If X//3 = 1 THEN GOSUB ONE
If X//3 = 2 THEN GOSUB ONE: GOSUB TWO
? NEXT LP
Looking again, it may be that I have misread your intent. I think then that a bare loop is not right and you might complete the loop portion before evaluating the remainder. If this is the case, no "IF" is required (The x//3 = 0 conditional]
Sorry that I'm not able to test this. In my mind it was so clear and produced the pattern illustrated with beautiful simplicity. Perhaps it might still be of some use.
Re: Avoiding too many GOSUBs, possible?
I need somehow to break down the incoming number into 3s 2s and 1s, and giving them priority....
Re: Avoiding too many GOSUBs, possible?
I Assume your objective is to get something like this
Code:
READY
1 1
2 1,2
3 1,2,3
4 1,2,3,1
5 1,2,3,1,2
6 1,2,3,1,2,3
7 1,2,3,1,2,3,1
8 1,2,3,1,2,3,1,2
9 1,2,3,1,2,3,1,2,3
10 1,2,3,1,2,3,1,2,3,1
11 1,2,3,1,2,3,1,2,3,1,2
12 1,2,3,1,2,3,1,2,3,1,2,3
13 1,2,3,1,2,3,1,2,3,1,2,3,1
14 1,2,3,1,2,3,1,2,3,1,2,3,1,2
15 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
16 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1
17 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2
18 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
19 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1
20 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2
21 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
22 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1
23 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2
24 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
25 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1
26 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2
27 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
28 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1
29 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2
30 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
Quote:
So for example, when X=8, THREE-X will be called 2 times and ONE-X - 1 times?
perhaps should be
So for example, when X=8, THREE-X will be called 2 times and ONE-X - 3 times and TWO-X - 3 times?
Quote:
I need somehow to break down the incoming number into 3s 2s and 1s, and giving them priority....
priority over what exactly ?
Re: Avoiding too many GOSUBs, possible?
Yes my code looks like that :D
Priority I mean 10 can be achieved with 1+1+1+1+1+1+1+1+1+1 combo, but I need it to be done with 3+3+3+1
So I need a formula which will break down the incoming number into 3s 2s and 1s.
Re: Avoiding too many GOSUBs, possible?
So what happened to the twos*s then
you Need to state your objectives more effectively
Re: Avoiding too many GOSUBs, possible?
So if output is 11, then it will be 3+3+3+2
8=3+3+2
9=3+3+3
10+3+3+3+1
11=3+3+3+2
12=3+3+3+3
But these are sub-routines, which already include other statement, s so 3 here is actually doing 1+2+3, 2 is doing 1+2, and 1 is doing just 1 :)
1 Attachment(s)
Re: Avoiding too many GOSUBs, possible?
MY code that produced the printout in #4 called digit 1 ,2 and 3 subs [c1 c2 c3 ]as needed when the input is broken down
Attachment 9519
Re: Avoiding too many GOSUBs, possible?
Thanks, but there's no code in #4?
Re: Avoiding too many GOSUBs, possible?
you can remove all the gosubs entirely with a bit of thought to get the same printout
Code:
LOOPY: FOR X = 1 TO 30
DEBUG 13,10,DEC X,9
GOSUB CX
NEXT
PAUSE 5000
GOTO LOOPY
CX:
XX = x
y = 0
WHILE XX
DEBUG 49 + y
y = y + 1
if y == 3 then y = 0
Xx = Xx - 1
IF XX THEN DEBUG ","
WEND
RETURN