Don't have an account? Register now to chat, post, use our tools, and much more.
» Goto page 1, 2, 3  Next
I just made a nifty routine that "searches" whether a number is in a list or not. I think it should help a lot of people with certain algorithms.

Code:
```If max(iPart(L/k)*fPart(k/L))=1 Then // k is in L Else // k is not in L EndIf ```
Ohh, nice! Like inString, but for a list!
it would be nice if you explained (for the n00bs i mean) how it works - then it can be more tip worthy
To see if A is in L1:
Code:
```If max((A=L1)seq(X,X,1,dim(L1 Then...```
It has the added bonus of giving the list element.
Yeah, but yours is slower too. Mine just checks and is much faster.
I vote that both of these go in the 1337 Guide.
I second Radical Pi's for 1337 Guide worthyness. I am actually going to use it in my current project (if it's okay with pi^.5), which is an expansion or a recently released program and as a part of FuncStuf (one of the too many projects under construction). I hopefully will have time/ability to port it to the 83+ at some point.
I think yours is useful too, for though it's slower, it finds the list element.
Looks good, though you might be able to use the IS>( command for it... Don't know if it would slow it down or now...

/me thanks you for using this section, no one else was
After some fiddling around, I have discovered some problems with the current routines.

Mine fails horribly when either the list or the number is 0. I have found a fix for it (and a typo above) though with:

Code:
```If min(abs(L))=a and a=0 or max(iPart(a/L)*iPart(L/a))=1 Then // a is in L Else // a is not in L EndIf```

And Radical Pi's only returns the last instance of it in the list, not every one. In addition, I cannot find a way to implement it simply on the 68k (a=L returns false, not a list of comparisons). That will have to be done by an algorithm initiated one it is in fact shown to be in the list for 68k (and z80 if all instances are wanted).
My routine (created by Weregoose before I get more credit) only needs one list element. It serves as a backwards-searching inString().

Code:
`If 1=min(abs(L))=a and not(a) or max(iPart(a/L)iPart(L/a`
is a little more 1337.
I was using 68k above (where parentheses must be ended). Unfortunately, it still fails when there's a 0 in the list (Div by 0 error on the z80 and max(1, undef) on the 68k, which is just about the worst thing you could get). I'd also like to know why the 1= is in there at first...
Oh.
The EndIf should have made it obvious but I didn't notice; I assumed it was z80 and reorganized it with 1= first so the )) could be removed.
Well, it's on the wrong spot anyway, but that's okay...I've still got a few things to add to it anyway to get around the darn 0 in the list error...
Oh yes! I just got an idea to use this routine in a shootem game.
To give each enemy a list element and access it through this routine?
Yes. Since the list searches for the first occurrence of element, I'll use it to see which enemy should be deleted by comparing shooter's location and enemy's location.
Oooh, nice!
You could also use it in a (3d?) layering engine.
How so?

» Goto page 1, 2, 3  Next
» All times are GMT - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum