Sum multiples of 3 and 5: Difference between revisions

Emacs Lisp: Improve examples, replace redundant one with vanilla version
(Sum multiples of 3 and 5 in various BASIC dialents)
(Emacs Lisp: Improve examples, replace redundant one with vanilla version)
Line 1,332:
 
=={{header|Emacs Lisp}}==
 
===version 1===
Vanilla:
<lang Emacs Lisp>
 
<lang Lisp>(defun sum-3-5 (n)
(apply '+ (mapcar
(let ((sum 0))
'(lambda (x) (if (or (= 0 (% x 3) ) (= 0 (% x 5) ))
(dotimes (x 0) n)
(number-sequencewhen 1(or (-zerop n(% 1x 3)) (zerop (% x 5)))
(setq sum (+ sum x))))
sum))</lang>
===version 2===
 
<lang Emacs Lisp>
{{libheader|seq.el}}
<lang Lisp>(defun sum-3-5 (n)
(apply '+ (seq-filter
(apply #'+ (mapcarseq-filter
'(lambda (x) (or (= 0 (% x 3) ) (= 0 (% x 5) )))
(number-sequencelambda 1(x) (-or n(zerop (% x 1)3) ) (zerop (% x 5))))
(number-sequence 1 (- n 1)))))</lang>
</lang>
<b>Eval:</b>
<lang Emacs Lisp>
(insert (format "%d" (sum-3-5 100) ))
(insert (format "%d" (sum-3-5 1000) ))
</lang>
<b>Output:</b>
<pre>
2318
233168
</pre>
 
=={{header|Erlang}}==
Anonymous user