No necesariamente voy a usar la misma forma, porque a veces no se puede o no la se, por ahora con tal que ande esta todo bien.
aca va el resultado del primer problema
python
# Add all the natural numbers below one thousand that are multiples of 3 or 5.
# If we list all the natural numbers below 10 that are multiples of 3 or 5,
# we get 3, 5, 6 and 9. The sum of these multiples is 23.
# Find the sum of all the multiples of 3 or 5 below 1000.
def calculate():
return sum(x for x in xrange(1000) if x % 3 == 0 or x % 5 == 0)
def print_result():
print calculate()
if __name__ == '__main__':
print_result()
en erlang
-module(ej_001).
-export([calculate/0, print_result/0]).
calculate() -> lists:sum([X || X <- lists:seq(0, 1000), X rem 3 == 0 orelse X rem 5 == 0]).
print_result() -> io:format("~w~n", [calculate()]).
en lisp
(defun multiple-of-3-or-5 (value)
(or (eq (rem value 3) 0)
(eq (rem value 5) 0))
)
(defun calculate-helper (value accum limit)
(cond ((= value limit)
accum)
((multiple-of-3-or-5 value)
(calculate-helper (+ value 1) (+ accum value) limit))
(T
(calculate-helper (+ value 1) accum limit))
)
)
(defun calculate () (calculate-helper 0 0 1000))
(defun print-result ()
(print (calculate)))
(print-result)
1 comentario:
yo ya voy 28 en python, ayudame con el 15!
Publicar un comentario