Here's a look from a mathematics perspective and sets:
set=: 13 :'0 = x | y'
]A=:3 set 1+i.35
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0
]B=:5 set 1+i.35
0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
A+.B
0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 1 0 1
A*.B
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
(A+.B)*.A*:B
0 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 1
(1+i.35)#~ (A+.B)*.A*:B
3 5 6 9 10 12 18 20 21 24 25 27 33 35
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Don Kelly
Sent: Wednesday, April 09, 2014 12:01 AM
To: [email protected]
Subject: Re: [Jprogramming] Euler Project Problem 1
sorry- I originally used + which duplicated 15 where I should have
used or (+. )
On 08/04/2014 8:52 PM, Don Kelly wrote:
> try=: 3 : '( (0=3|y)+.(0=5|y))#y' **or** try1=: ] #~ (0 = 3 | ]) +. 0
> = 5 | ] *
> *
> try1 1+i.19
>
> 3 5 6 9 10 12 15 18
>
>
> Don Kelly
>
>
>
> On 08/04/2014 8:30 AM, Jon Hough wrote:
>> Euler Project #1 is:If we list all the natural numbers below 10 that
>> are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these
>> multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
>> In C/Java I could easily do something like:
>> int total =0;
>> for (int counter = 0; counter < 1000; counter ++ ){if(counter %3 = 0
>> || counter %5 = 0){ total += counter;}}
>> return counter;
>>
>> The main features here being the if statement and the for-loop.
>> Obviously in J things need to be done differently. Here is my first
>> attempt:
>> div3 =. 0&(="0)@:( 3&|) NB. is residue zerodiv5 =. 0&(="0)@:( 5&|)
>> div3or5 =. div3"0 +."0 div5"0
>> dummy =. 1&*"0 NB. You'll see why I need this...
>> result =. dummy * div3or5
>> NB. final result is:
>> +/result i.1000
>>
>> I used dummy because I wanted to do something like multiply the
>> value of y by "div3or5 y" so only multiples of 3 or 5 would be nonzero.
>> Before attempting this problem I assumed it could be done in only one
>> line and am pretty unhappy by my long solution. Any help explaining
>> where I have gone wrong, or why my attempt at a fork is silly would
>> be appreciated.
>> Thanks in advance,
>> 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