DEV Community

Discussion on: Project Euler #1 - Multiples of 3 and 5

Collapse
 
derfugu profile image
Daniel Bruynooghe • Edited

q)sum (&) 0=min mod/:[; 3 5](!)1000

Collapse
 
derfugu profile image
Daniel Bruynooghe • Edited

k) +/&0=min{x-y*x div y}/:[;3 5](!)1000

For a change my k solution is more wordy because the mod function is rather long. Said that, the q above has k in it as well. In pure q it would read

q)sum where 0=min mod/:[;3 5]til 1000

terse and somewhat obfuscated, though the main elements are recognizable, i.e. create the list up to 1000, compute the remainders when dividing by 3 and by 5 and sum across all where either remainder is 0.