[Jprogramming] Return of max of list and it's index in single pass

Linda A Alvord lindaalvord at verizon.net
Fri Jan 27 07:43:16 UTC 2017


Raul,  When I wrote this message I was using my Android phone.  I have been using your idea of capital letters for nouns and small letters for verbs as you suggested a long time ago.

 However, I wonder if a,b,c,d,e would be better for nouns and f,g,h,i.... for verbs. It takes two strokes to get a capital when using the phone which is annoying but using the caps key doesent seem quite such a bother.

What do you think or do you have a different idea entirely these days?

Linda

-----Original Message-----
From: Programming [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Linda A Alvord
Sent: Wednesday, January 25, 2017 9:31 AM
To: programming at jsoftware.com
Subject: Re: [Jprogramming] Return of max of list and it's index in single pass

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-bounces at forums.jsoftware.com] On Behalf Of 'Jon Hough' via Programming
Sent: Tuesday, January 24, 2017 11:29 PM
To: programming at 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 <rauldmiller at gmail.com> wrote:

 Subject: Re: [Jprogramming] Return of max of list and it's index in single	pass
 To: "Programming forum" <programming at 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
 <programming at 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



More information about the Programming mailing list