0

Here is a different approach for the Project Euler #1 solution:

+/~.(3*i.>.1000%3),5*i.>.1000%5

How to refactor it?

Jader Dias
  • 88,211
  • 155
  • 421
  • 625

3 Answers3

3
+/(#~ ( (0= 3| ]) +. (0 = 5 |]) )) 1+i.999

0 = ( 3 | ]) uses (twice) the trick of verb train (fork) with n u v (discussed at the end of http://www.jsoftware.com/help/learning/09.htm)

A different way of writing it:

+/(#~ ( ((0&=) @ (3&|)) +. ((0&=) @ (5&|)))) 1+i.999
Zhe Hu
  • 3,777
  • 4
  • 32
  • 45
3
[:+/@~.@,3 5([*i.@>.@%~)]

usage example:

f =: [:+/@~.@,3 5([*i.@>.@%~)]
f 1000

or

+/~.,3 5([*i.@>.@%~)1000

%~                        = 4 : 'y % x'
i.@>.@%~                  = 4 : 'i. >. y % x'
[*i.@>.@%~                = 4 : 'x * i. >. y % x'
3 5([*i.@>.@%~)]          = 3 : '3 5 * i. >. y % 3 5'
[:+/@~.@,3 5([*i.@>.@%~)] = 3 : '+/ ~. , 3 5 * i. >. y % 3 5'
ephemient
  • 198,619
  • 38
  • 280
  • 391
1

Here is another approach, using a simple, generic verb

multiplesbelow =: 4 : 'I. 0 = x | i.y'
+/ ~. ,3 5 multiplesbelow"0 [ 1000
MPelletier
  • 16,256
  • 15
  • 86
  • 137