-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Thursday, September 04, 2014 9:05 PM
To: [email protected]
Subject: Re: [Jprogramming] repeated applications of a verb
It is even better for binary numbers as you don't need to determine the
number os 2's
#. inv 197
1 1 0 0 0 1 0 1
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Thursday, September 04, 2014 8:41 PM
To: [email protected]
Subject: Re: [Jprogramming] repeated applications of a verb
g=: 13 :'+/!10 #. inv y'
g
[: +/ [: ! 10 #.^:_1 ]
Interesting...
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Thursday, September 04, 2014 8:33 PM
To: [email protected]
Subject: Re: [Jprogramming] repeated applications of a verb
Nice!
10 #. inv 4365
4 3 6 5
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of 'Pascal
Jasmin' via Programming
Sent: Thursday, September 04, 2014 8:17 PM
To: [email protected]
Subject: Re: [Jprogramming] repeated applications of a verb
there is also
([: +/@:! 10 #. inv ]) 169
#. inv is like #: except you don't need to calculate the right number of
copies of x (10).
----- Original Message -----
From: Linda Alvord <[email protected]>
To: [email protected]
Cc:
Sent: Thursday, September 4, 2014 7:59:21 PM
Subject: Re: [Jprogramming] repeated applications of a verb
f=: 13 :'+/!(($":y)#10)#:y'
f 169
363601
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raul Miller
Sent: Thursday, September 04, 2014 5:39 PM
To: Programming forum
Subject: Re: [Jprogramming] repeated applications of a verb
Just so it's clear what has happened here:
;:'SumOfFact^:3 169'
+---------+--+-----+
|SumOfFact|^:|3 169|
+---------+--+-----+
In other words, 3 169 is a single word. It's a word that happens to have a
space in it, but that's actually not at all unusual. Here's another example
of a word with a space in it:
'this is a test'
Actually, that particular word has three spaces in it. But that counts,
right?
Note that some people prefer to call words "tokens" for various reasons.
Note also that we train our eyes to see these things. To someone who has
never studied computer programming languages, 'this is a test' might look
like four words where two of them contain apostrophes. But someone familiar
with quoting rules can see it as a single "thing" and - if they've played
with implementations of parsers or similar things - they'll have an idea
about why it's worth calling this thing a "word" or a "token".
Anyways, I have had this happen to me relatively often, so I am familiar
with its symptoms. I'll have a J sentence which uses a number and I will
add another number to it, and I will want it to be a different word, and I
have to remind myself to make it be one.
Meanwhile some other messages have provided some examples of how to break 3
169 into two separate words, so I'll skip that part. But I'll note that I
see four different ways of using a single pair of parenthesis to accomplish
this.
Thanks,
--
Raul
On Thu, Sep 4, 2014 at 2:55 PM, alessandro codenotti <[email protected]> wrote:
> I'm working on PE#74, which asks for the sum of the factorials of the
digits in a number
> (i.e. if the number is 169 then it asks for 1!+6!+9!).
>
> I wrote this verb that performs the required operation:
> SumOfFact=: 3 : 0
> +/!"."0@": y
> )
> It works perfectly, but now I need to reiterate it to produce a chain
like 169 -> 363601 -> 1454 -> 169,so I tried:
> SumOfFact^:3 169
>
> But instead of working as I hoped it simply writes "SumOfFact^:3 169" as
output.
>
> What am I doing wrong and how am I supposed to repeatedly apply a verb to
an argument?
>
> ----------------------------------------------------------------------
> 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
----------------------------------------------------------------------
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