HomeAboutCodePastes
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordieggsy <dieggsy@pm.me>2021-04-26 16:52:49 -0400
committerdieggsy <dieggsy@pm.me>2021-04-26 16:52:49 -0400
commit394f2225e9d716c9fd494b960a058dea6b5304cd (patch)
tree2b2054ebf44e3f309d7b1b246e053ccfb91c3d9f
parentaffcc930b25b0ebb17863f06978e8e11ebdaf803 (diff)
downloadproject-euler-394f2225e9d716c9fd494b960a058dea6b5304cd.tar.gz
Add p65 solution in lisp
-rw-r--r--data/matrix.txt (renamed from data/p81-matrix.txt)0
-rwxr-xr-xsbcl/p65.lisp38
2 files changed, 38 insertions, 0 deletions
diff --git a/data/p81-matrix.txt b/data/matrix.txt
index f65322a..f65322a 100644
--- a/data/p81-matrix.txt
+++ b/data/matrix.txt
diff --git a/sbcl/p65.lisp b/sbcl/p65.lisp
new file mode 100755
index 0000000..8a25663
--- /dev/null
+++ b/sbcl/p65.lisp
@@ -0,0 +1,38 @@
+#!/usr/bin/sbcl --script
+(setf *print-circle* t)
+
+(defun inf-frac (head repeat)
+ (let ((lst (cons head repeat)))
+ (setf (cdr (last (cdr lst)))
+ (cdr lst))
+ lst))
+(defparameter sqrt2-conv
+ (inf-frac 1 '(2)))
+
+(defparameter e-conv
+ (cons 2
+ (loop :for i = 1 :then (+ 1 i)
+ :until (> i 34)
+ :append `(1 ,(* 2 i) 1))))
+
+(defun get-value (n conv)
+ (if (= n 0)
+ (car conv)
+ (labels ((helper (n lst)
+ (/ 1
+ (+ (car lst)
+ (if (= n 0)
+ 0
+ (helper (1- n) (cdr lst)))))))
+ (+ (car conv)
+ (helper (1- n) (cdr conv))))))
+
+(defun p65 ()
+ (let ((num (numerator (get-value 99 e-conv))))
+ (loop :for n = num :then x
+ :as (x y) = (multiple-value-list (floor n 10))
+ :until (= x 0)
+ :sum y :into sum
+ :finally (return (+ sum y)))))
+
+(time (princ (p65)))