1. Yuriy Netesov
  2. euler

Commits

Yuriy Netesov  committed f35ee6b

euler 2 solve

  • Participants
  • Parent commits b6f3746
  • Branches default

Comments (0)

Files changed (3)

File euler_1.lisp

View file
-(defun get-weight (numb multiplies)
-  (loop for multi in multiplies when (eq (rem numb multi) 0) do
-	   (return-from get-weight numb))
-  0)
+(use-package 'euler-lib)
 
 (defun calculate (bel multiplies) 
   (loop for i from 1 below bel sum
-	   (get-weight i multiplies)))
+	   (get-weight-when-multiplies i multiplies)))
 
 (defun solve ()
   (calculate 1000 '(3 5)))

File euler_2.lisp

View file
+(defun get-fib-num (a b)
+  (+ a b))
+
+(defun even-p (num)
+  (eq (rem num 2) 0))
+
+(defun calculate-fib-sum (prelast last acc below)
+  (let ((fbn (get-fib-num last prelast)))
+		(if (< fbn below)
+			(if (even-p fbn)
+				(calculate-fib-sum last fbn (+ acc fbn) below)
+				(calculate-fib-sum last fbn acc below))
+			acc)))
+
+(defun solve ()
+  (calculate-fib-sum 1 1 0 4000000))

File euler_lib.lisp

View file
+(defun get-weight-when-multiplies (numb multiplies)
+  (loop for multi in multiplies when (eq (rem numb multi) 0) do
+	   (return-from get-weight-when-multiplies numb))
+  0)