Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: nemo on November 19, 2010, 05:45:20 pm

Title: Routine request.
Post 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:
Code: [Select]
max({A=0,2not(B),3not(C   //nazi.
Title: Re: Routine request.
Post by: Deep Toaster on November 19, 2010, 06:56:27 pm
Well, I don't have one for {A,B,C}, but here's one for a list in Ans:

Code: (TI-BASIC) [Select]
: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?
Title: Re: Routine request.
Post by: nemo on November 19, 2010, 07:06:43 pm
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() :/
Title: Re: Routine request.
Post by: Deep Toaster on November 19, 2010, 07:17:17 pm
Oh, okay. Why not

Code: (TI-BASIC) [Select]
:not(A)+2not(B)+3not(C
then?
Title: Re: Routine request.
Post by: nemo on November 19, 2010, 07:22:45 pm
Oh, okay. Why not

Code: (TI-BASIC) [Select]
:not(A)+2not(B)+3not(C
then?

yeah.. i usually overcomplicate things. thanks DeepThought!
Title: Re: Routine request.
Post by: Deep Toaster on November 19, 2010, 07:24:56 pm
Wait, wait! If you want a pinch of the awesome factor, how about this?

Code: (TI-BASIC) [Select]
:2+sum(ΔList(not({A,B,C
It's exactly the same size ;D

EDIT: Overcomplication FTW!
Title: Re: Routine request.
Post by: nemo on November 19, 2010, 07:30:40 pm
Wait, wait! If you want a pinch of the awesome factor, how about this?

Code: (TI-BASIC) [Select]
: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
Title: Re: Routine request.
Post by: Deep Toaster on November 19, 2010, 07:37:36 pm
Yeah, true. The first one is somewhat faster (1:23 compared to 1:30 over 1000 iterations).