Skip to main content
2 of 2
added 475 characters in body
Dennis
  • 211.7k
  • 41
  • 380
  • 830

CJam, 13 bytes

1aq~{1$f*+}/p 

Reads an array (e.g., [2 3 5 7]) from STDIN. Try it online.

An anonymous function would have the same byte count:

{1a\{1$f*+}/} 

Example run

$ cjam <(echo '1aq~{1$f*+}/p') <<< '[]' [1] $ cjam <(echo '1aq~{1$f*+}/p') <<< '[2 3 5 7]' [1 2 3 6 5 10 15 30 7 14 21 42 35 70 105 210] 

How it works

1a " Push R := [1]. "; q~ " Read an array A from STDIN. "; { }/ " For each a ∊ A: "; 1$f*+ " R += { ra : r ∊ R } "; p " Print. "; 
Dennis
  • 211.7k
  • 41
  • 380
  • 830