I'm a complete beginner of Factor, but I just managed to solved Euler Problem #1 using it, and would love to have the code reviewed. Anything that can be improved? In particular I'm wondering if there is a cleaner or more idiomatic way to write the mult3or5? word.USING: math kernel sequences math.ranges prettyprint ;IN: euler1: mult? ( x y -- ? ) rem 0 = ;: mult3? ( x -- ? ) 3 mult? ;: mult5? ( x -- ? ) 5 mult? ;: mult3or5? ( x -- ? ) dup mult3? swap mult5? or ;: sumMultsOf3or5 ( seq -- n ) [ mult3or5? ] filter sum ;: solveEuler1 ( -- ) 0 1000 (a,b) sumMultsOf3or5 . ;
Project Euler problem 1 in Factor
project euler;factor lang
dup f swap g is a common idiom, so Factor has bi.: mult3or5? ( x -- ? ) [ mult3? ] [ mult5? ] bi or ;