Author Topic: Routine request.  (Read 2804 times)

0 Members and 1 Guest are viewing this topic.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Routine request.
« 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.
« Last Edit: November 19, 2010, 05:53:17 pm by nemo »


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routine request.
« Reply #1 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?
« Last Edit: November 19, 2010, 07:10:23 pm by Deep Thought »




Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routine request.
« Reply #2 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() :/


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routine request.
« Reply #3 on: November 19, 2010, 07:17:17 pm »
Oh, okay. Why not

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




Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routine request.
« Reply #4 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!


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routine request.
« Reply #5 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!
« Last Edit: November 19, 2010, 07:26:22 pm by Deep Thought »




Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Routine request.
« Reply #6 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


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routine request.
« Reply #7 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).
« Last Edit: November 19, 2010, 07:37:51 pm by Deep Thought »