Question

Voici une approche différente pour le projet Euler solution n ° 1:

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

Comment refactoriser?

Était-ce utile?

La solution

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

Exemple d'utilisation:

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

ou

+/~.,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'

Autres conseils

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

utilisations 0 = ( 3 | ]) (deux fois) le tour d'un train de verbe (à fourche) avec nuv (discuté à la fin de http://www.jsoftware.com/help/learning/09.htm )

Une autre façon de l'écrire:

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

Voici une autre approche, en utilisant un simple verbe générique

multiplesbelow =: 4 : 'I. 0 = x | i.y'
+/ ~. ,3 5 multiplesbelow"0 [ 1000
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top