Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: nemo on November 19, 2010, 05:45:20 pm
-
i need a routine/snippet of code to, from a list of 3 elements, two guaranteed to be an arbitrary value greater than zero, and one guaranteed to be zero, return index of the element with 0.
so {235,532,0} returns 3. {0,532,25} returns 1. {235,0,18729} returns 2. assume this list is {A,B,C}.
i'm looking for size here, not speed.
if you have a more elegant solution, please post it.
edit: here's what i have:
max({A=0,2not(B),3not(C //nazi.
-
Well, I don't have one for {A,B,C}, but here's one for a list in Ans:
:max(not(Ans)cumSum(binomcdf(2,0 //darn, no Nazis
It's 11 bytes. As I said, it doesn't work with a list of A, B, and C, but I guess you could change Ans to {A,B,C}, but that's two bytes more than what you have. How exactly is your list stored?
-
the first 3 elements of L1 == {A,B,C}. the only problem is that L1 is {A,B,C,D,E,F}, and the only way to i know of to get a sublist is using seq() :/
-
Oh, okay. Why not
:not(A)+2not(B)+3not(C
then?
-
Oh, okay. Why not
:not(A)+2not(B)+3not(C
then?
yeah.. i usually overcomplicate things. thanks DeepThought!
-
Wait, wait! If you want a pinch of the awesome factor, how about this?
:2+sum(ΔList(not({A,B,C
It's exactly the same size ;D
EDIT: Overcomplication FTW!
-
Wait, wait! If you want a pinch of the awesome factor, how about this?
:2+sum(ΔList(not({A,B,C
It's exactly the same size ;D
EDIT: Overcomplication FTW!
i would, but i feel like adding is faster than doing two list operations and a logic operation :P
-
Yeah, true. The first one is somewhat faster (1:23 compared to 1:30 over 1000 iterations).