I decided to learn J so that I could better take part in code golfing. Starting it off relatively simple, I tried writing a solution to this problem:
Find the sum of all the multiples of 3 or 5 below 1000.
After a bit of tinkering, I came up with the following J code that solves it:
x=:i.1000
+/x#(0=3|x)+.0=5|x
Basically, what I'm doing is taking two lists of numbers from 1 to 1000, and finding one modulo 3, and the other modulo 5. Then I OR them together to get a list of indicies where a number is divisible by either 3 or 5. I then use that to sum the numbers.
What I ask is, how do I shorten this? I'm new to J and so do not have enough experience to shorten it any further.
Also, if anyone has a solution shorter than this in another language, I'd be interested to see that as well!
233168
\$\endgroup\$