Jon,  I haven't been using J for a while so I tried your problem. In a way I 
must think like a beginner again.  Here's my take after a false start where I 
used APL!

[A=:?6#50
40 5 19 46 34 40
   >/A
1
   >./A
46
  
    
   i.$A
0 1 2 3 4 5
   
     
   
   A=>./A
0 0 0 1 0 0
   
   i.$A
0 1 2 3 4 5
      (A=>./A)    #i.$A
3
   
   f=: 13 :'(y=>./y)#i.$y'
   f A
3
   
   f
(] = >./) # [: i. $
   

So this is "beginner Tacsit" that seems to work. Then it is fun to see what I 
can learn from the masters who have  already solved your problem.  Keep sending 
your questions. They are goo for all of us.

Linda



-----Original Message-----
From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf 
Of 'Jon Hough' via Programming
Sent: Tuesday, January 24, 2017 11:29 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Return of max of list and it's index in single pass

Yep, that's what I was looking for. Thanks! 

--------------------------------------------
On Wed, 1/25/17, Raul Miller <rauldmil...@gmail.com> wrote:

 Subject: Re: [Jprogramming] Return of max of list and it's index in single     
pass
 To: "Programming forum" <programm...@jsoftware.com>
 Date: Wednesday, January 25, 2017, 12:01 PM
 
    maxIndexAndValue=:
 ((i.,]) >./)
 
 I hope this
 helps,
 
 --
 Raul
 
 
 On Tue, Jan 24, 2017 at 9:58 PM, 'Jon
 Hough' via Programming
 <programm...@jsoftware.com>
 wrote:
 > I want to get the max value of a
 list, and return the first index of its occurrence in the  list, tacitly.
 >
 > My
 solution
 >
 >
 maxWithIndex =: {.@:I.@:(= >./), >./
 >
 > works ok, but
 calculates >./ twice. Is there a tacit way to do this  with only a single calc 
of >./ ?
 >
 > Thanks,
 > Jon
 >
 ----------------------------------------------------------------------
 > 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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to