Johann Hibschman wrote:
Part of the problem here is that filter is not a verb; it's an *adverb*.
That's the key insight one needs, yes.
I'm just a beginner myself, so I'm not sure that this can't be done
tacitly, but an explicit version is:
filter =: 1 : '#~ x'
Some beginner advice here.
Thanks Bill David,
And thanks for NOT sending the spoiler, Bill, I'd rather work on it some
more for now. The tip re @: was just what I was after, I think.
I haven't had occasion to use the f. adverb yet, I'll go read it up now.
On Sat, 2010-08-28 at 11:15 +0800, bill lam wrote:
to get the
'',1 2 3
1 2 3
NB. OK
'',0 [1 2 3
|length error
| '',0[1 2 3
NB. Is this because there are NO atoms in LH argument?
NB. I would have preferred to have seen 1 2 3
1 2 3,0/ 4 5 6
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6
NB. OK
'',0/ 4 5 6
NB. I would have preferred to
As http://www.jsoftware.com/help/primer/agreement.htm states in the last
paragraph: (...) one frame must be a prefix of the other (...)
The frames of
'',0 [1 2 3
are 0 and 3, since 0=$'' and 3=$1 2 3 . Since 0 is not a prefix of 3 you get
a length error.
See also
Oops, before we go any further, I've stumbled on a real gotcha
e.g.
digits 1974 123
1 9 7 4
0 1 2 3
now, when I apply (+!) to that lot, it is also applied to the leading
zero of 0123 - which, of course, leads to a wrong result when summed.
AAARGH!
Never mind that when I try to sum with /+
From: Alex Gian
Sent: Sunday, 29 August 2010 00:23
Oops, before we go any further, I've stumbled on a real gotcha
e.g.
digits 1974 123
1 9 7 4
0 1 2 3
now, when I apply (+!) to that lot, it is also applied to the leading
zero of 0123 - which, of course, leads to a wrong result
It is important to note that when changing rank there are three numbers
involved.
By only giving one number it sets all number to the same
(10#.inv0) b. 0
0 0 0
The first number being the monadic case and the other two for left and right
of the dyadic case
2010/8/28 Sherlock, Ric
From: Sherlock, Ric
Sent: Sunday, 29 August 2010 00:56
From: Alex Gian
Sent: Sunday, 29 August 2010 00:23
Oops, before we go any further, I've stumbled on a real gotcha
e.g.
digits 1974 123
1 9 7 4
0 1 2 3
now, when I apply (+!) to that lot, it is also applied to the
@ Ric Bjorn,
re rank
Thanks guys, I actually knew I had to use 0 but I was messing up the
syntax somewhere, your examples and commentary are making it a whole lot
easier.
--
For information about J forums see
Thanks a lot for that Ric.
I actually managed to get as far as this:
digits =. 10#.inv
fp1 =. +!
spsum =. +/ @ |: @ fp1 @ digits
special =. = spsum
(#~ special)i.10
which gave me 85837 correctly
also,
(#~ special)i.100
41086 408297
gives the correct larger number in very acceptable
From: Alex Gian
Sent: Sunday, 29 August 2010 02:01
Thanks a lot for that Ric.
I actually managed to get as far as this:
digits =. 10#.inv
fp1 =. +!
spsum =. +/ @ |: @ fp1 @ digits
special =. = spsum
(#~ special)i.10
which gave me 85837 correctly
also,
(#~
I expect the following to be faster:
Apply digits to the whole array at once, and also
apply (+!) to the result of that. But before you apply
+/1, do something about the elements corresponding
to leading 0 digits, e.g. (* -.@:(*/\1)@:(0=)) .
- Original Message -
From: Sherlock, Ric
(* +./\1@(0~:))
- Original Message -
From: Roger Hui rhui...@shaw.ca
Date: Saturday, August 28, 2010 8:26
Subject: Re: [Jprogramming] Splitting an integer into its digits
To: Programming forum programming@jsoftware.com
I expect the following to be faster:
Apply digits to the whole
I find your explanation very helpful, especially because of the links
you have given to the primer, which I had not studied carefully. Refer
to the following link, please, where we read, For a dyad the left
rank of the verb and the rank of the left argument determine the frame
of the left
I see that the example I meant to show literal arguments was not
included so I am adding it now, though it is certainly not noteworthy.
''(,0) frame '123'
┌─┬─┐
│0│3│
└─┴─┘
And the next examples show a monadic verb and a dyadic verb with
literal arguments.
+ frame 2 3 4
┌─┐
│3│
15 matches
Mail list logo