[Jprogramming] Recursive verbs

Raul Miller rauldmiller at gmail.com
Tue Nov 27 16:06:40 UTC 2018


Sure, ... that's a bit bulkier than I prefer, but it works.
Here's another alternative:
 evenodd=: , (_1 2,:_1 4)&p.@{:
 evenodd evenodd 4
4 7 15 29 59
Thanks,
-- 
Raul
On Tue, Nov 27, 2018 at 10:44 AM 'Pascal Jasmin' via Programming
<programming at jsoftware.com> wrote:
>> Another approach,
>> ar =: 1 : '5!:1 <''u'''
>> even =: 3 : ' (,(+: - 1:)@{:) ar , (y`:6) ar'
> odd =: 3 : ' (,(+: + 1:)@{:) ar , (y`:6) ar'
> even odd even odd (+: - 1:) ar , 4 ar
> ┌──────────────────────────────┬──────────────┐
> │┌─┬──────────────────────────┐│┌─┬──────────┐│
> ││2│┌─┬──────────────────────┐│││0│7 15 29 59││
> ││ ││,│┌─┬──────────────────┐│││└─┴──────────┘│
> ││ ││ ││@│┌─────────────┬──┐││││ │
> ││ ││ ││ ││┌─┬─────────┐│{:│││││ │
> ││ ││ ││ │││3│┌──┬─┬──┐││ │││││ │
> ││ ││ ││ │││ ││+:│-│1:│││ │││││ │
> ││ ││ ││ │││ │└──┴─┴──┘││ │││││ │
> ││ ││ ││ ││└─┴─────────┘│ │││││ │
> ││ ││ ││ │└─────────────┴──┘││││ │
> ││ ││ │└─┴──────────────────┘│││ │
> ││ │└─┴──────────────────────┘││ │
> │└─┴──────────────────────────┘│ │
> └──────────────────────────────┴──────────────┘
>> ________________________________
> From: Raul Miller <rauldmiller at gmail.com>
> To: Programming forum <programming at jsoftware.com>
> Sent: Tuesday, November 27, 2018 10:25 AM
> Subject: Re: [Jprogramming] Recursive verbs
>>>> It's more like this, actually:
>> seqodd=: +: - 1:
> seqevn=: +: + 1:
> (,seqevn@{:)@(,seqodd@{:)^:8]4
> 4 7 15 29 59 117 235 469 939 1877 3755 7509 15019 30037 60075 120149 240299
>> More generally, either:
>> a) you keep explicit track of which position in the sequence you are
> generating, so you can choose between the odd or the even method, or
>> b) you generate the numbers in pairs
>> If you generate the numbers in pairs, you can rearrange things in a
> variety of ways.
>> Thanks,
>> --
> Raul
>>> On Tue, Nov 27, 2018 at 7:37 AM 'Pascal Jasmin' via Programming
> <programming at jsoftware.com> wrote:
> >
> > If the verb you want is repetitive double - 1 then
> >
> > 5 (1 -~ +:@])^:(<@[) 4
> > 4 7 13 25 49
> >
> > Otherwise, Mike's 2 at a time approach is the way to go.
> >
> > ________________________________
> > From: Skip Cave <skip at caveconsulting.com>
> > To: "Programming at jsoftware.com" <Programming at jsoftware.com>
> > Sent: Tuesday, November 27, 2018 2:10 AM
> > Subject: [Jprogramming] Recursive verbs
> >
> >
> >
> > How would you write an implicit or explicit recursive verb for this
> >
> > sequence formula?
> >
> >
> > a1=.4
> >
> >
> > a1 , (a2=.1-~2*a1) , (a3=.1+~2*a2) , (a4=.1-~2*a3) , (a5=.1+~2*a4) ...
> >
> > (an=.1(+-)~2*an-1
> >
> >
> >
> > The verb would be specified as x f y, where x is the starting integer a1,
> >
> > and y is the number of terms (n) - or vice versa.
> >
> >
> > The result will be a vector n items long. Note the alternating sign in each
> >
> > term
> >
> >
> >
> > Example:
> >
> >
> > 4 f 5
> >
> >
> > 4 7 15 29 59
> >
> >
> >
> > Skip
> >
> > ----------------------------------------------------------------------
> >
> > 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

AltStyle によって変換されたページ (->オリジナル) /