Thinking this through just a little bit more:

NB. brute force adverb:
pe1Ab=: 1 :'m&([:+/@I. 0 +./ .= (|/ i.))'

NB. moebius adverb:
mu=: (1 _1 0 */@:{~ 2 <. _ q: ])"0
mf=: -.&0@(- * mu)@(, ~.@,@:(*/)~)
pe1Am=: 1 :'(mf m) +/@([ * 2 ! 1 + (<.@% |)~) <:'

   3 5 pe1Ab 1000
233168
   3 5 pe1Am 1000
233168
   3 5 pe1Ab
3 5&([: +/@I. 0 +./ .= (|/ i.))
   3 5 pe1Am
3 5 _15 +/@([ * 2 ! 1 + (<.@% |)~) <:
   3 5 pe1Ab 1e6
233333166668
   3 5 pe1Am 1e6
233333166668
   timespacex '3 5 pe1Ab 1e6'
0.028942 2.51717e7
   timespacex '3 5 pe1Am 1e6'
6.4e_5 8576
   3 5 pe1Am 10000000000000000x
23333333333333331666666666666668

Thanks,

-- 
Raul

On Thu, May 5, 2016 at 2:48 PM, Raul Miller <rauldmil...@gmail.com> wrote:
> If this matters:
>
>    mu=: 1 _1 0 */@:{~ 2 <. _ q: ]  NB. moebius
>
> But it's maybe simpler to describe this as removing the "double
> counting" which would result from counting multiples of 15 twice (once
> for multiples of 3 and the other as multiples of 5).
>
> --
> Raul
>
> On Thu, May 5, 2016 at 10:03 AM, Mike Day <mike_liz....@tiscali.co.uk> wrote:
>> Yes, quite right!  You're my conscience as ever,  Raul.
>>
>> Sorry - I misremembered and didn't check.
>> Moebius mu(n) is 1 for 3 and 5,  _1 for 3*5=15, and 0 for powers higher
>> than one of 3 and 5 and their products,  so (eg) 0 for 25, 27 etc.
>> Also,  99 is the upper inclusive bound.
>>
>> So:
>>     +/99 (]*2!>:@(<.@%|)) 3 5 _15   NB. correctly hand-coded moebius!
>> 2318
>>
>> cf
>>     +/I.+./3 5 (0=|)"0/i.100   NB. Direct method
>> 2318
>>
>> Right idea.  Previously almost completely wrong example!!!
>> I hope it hasn't put Geoff off.
>>
>> Mike
>>
>>
>> On 05/05/2016 14:31, Raul Miller wrote:
>>>
>>> On Thu, May 5, 2016 at 4:31 AM, Mike Day <mike_liz....@tiscali.co.uk>
>>> wrote:
>>>>
>>>>      +/1683 1050 _594 315 _250 162 _135
>>>> 2231
>>>
>>> Er... is that the right answer, somehow?
>>>
>>> Thanks,
>>>
>>
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>> ----------------------------------------------------------------------
>> 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