[Jprogramming] Index of item in table
Gilles Kirouac
g1201 at myriade.ca
Wed Dec 27 06:05:16 UTC 2023
With p defined as
p=.3 4 5$?.60$50 NB. ?.
33 (($@])#:[(I.@:=),@]) p
0 2 0
2 1 1
2 3 1
~ Gilles
Le 2023-12-26 à 21:06, 'Skip Cave' via Programming a écrit :
> What would a general "find the index of the value x in the array y" verb
> named fixv look like?
>
> It would work like this:
>
> ] p=.3 4 5$?60$50
>
> 10 49 11 0 4
>
> 39 33 34 32 38
>
> 49 24 43 36 41
>
> 1 21 11 14 27
>
>
> 7 28 38 9 26
>
> 24 42 39 12 3
>
> 8 28 33 1 4
>
> 46 40 7 49 0
>
>
> 10 8 49 37 39
>
> 5 45 46 39 6
>
> 7 38 32 2 7
>
> 5 10 48 16 37
>
>
> 45 fixv p
>
> 2 1 1
>
>
> If there were more than one match, what should the output be?
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Tue, Dec 26, 2023 at 7:48 PM LdBeth <andpuke at foxmail.com> wrote:
>
>> This is related to the question I asked several days ago,
>>
>> http://jsoftware.com/pipermail/programming/2023-December/062994.html
>>
>> My suggestion would be
>>
>> 8 (($@])#:[i.~,@]) A
>> 1 3
>>
>> Although you might want to an alternative behavior when there are
>> multiple matches.
>>
>> LdBeth :)
>>
>>>>>>> In <CAMw+KcroqQ4g=
>> O4rKysTUQVjqQQTfxpqjy38ZwArNCD_TTLzgA at mail.gmail.com>
>>>>>>> David Pinchbeck <dpinchbe at gmail.com> wrote:
>>> Having trouble finding this in the wiki: I know that we can select from
>> a
>>> table using a boxed pair
>>
>>> A
>>
>>> 0 1 2 3 4
>>
>>> 5 6 7 8 9
>>
>>> 10 11 12 13 14
>>
>>> 15 16 17 18 19
>>
>>> 20 21 22 23 24
>>
>>
>>> (<1 3){A
>>
>>> 8
>>
>>> How do I write a verb f to do the reverse, so that
>>> 8 f A
>>> yields the result 1 3 ?
>>
>>> Thanks,
>>> David
>>> --
>>> David Pinchbeck
>>> Associate Professor of Mathematics
>>> St. Joseph's College
>>> Standish, ME
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list