views:

145

answers:

2

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

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

How to refactor it?

+1  A: 
[:+/@~.@,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
this is legible for you? I am still trying to figure out each step of the refactoring...
Jader Dias
thanks for the last edit, that was clarifying
Jader Dias
+1  A: 

Here is another approach, using a simple, generic verb

multiplesbelow =: 4 : 'I. 0 = x | i.y'
+/ ~. ,3 5 multiplesbelow"0 [ 1000
MPelletier
Nice! How about `multiplesBelow =: 4 : '(#~ +./(0 = x | ])"0) i. y'`? Then you can say `+/ 3 5 multiplesBelow 1000`.
Gregory Higley