Last active
December 23, 2015 13:49
-
-
Save triclops200/6644302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun nfib (a b c n) | |
(if (= n 0) | |
a | |
(nfib b c (/ (+ b c) a) (1- n)))) | |
(defmacro while (test &body body) | |
`(do () | |
((not ,test)) | |
,@body)) | |
(defmacro with-gensyms (syms &body body) | |
`(let ,(mapcar #'(lambda (x) `(,x (gensym))) syms) | |
,@body)) | |
(defmacro collect-list (end-condition next-value var) | |
"Generates a list based on the next-value provided." | |
(with-gensyms (acc) | |
`(let ((,acc nil)) | |
(while (not ,end-condition) | |
(push ,var ,acc) | |
(setq ,var ,next-value)) | |
(nreverse (cons ,var ,acc))))) | |
(defun range (x y &optional (step 1)) | |
"Generates a range with an optional step parameter. It is non-inclusive." | |
(if (> (abs (- y (+ step x))) (abs (- y x))) | |
nil | |
(nbutlast (collect-list (= x y) (+ x step) x)))) | |
(with-open-file (f "data.txt" :direction :output :if-exists :supersede) | |
(format f | |
"~{~a~%~}" | |
(loop for x in (range 1 2001) collect (nfib 2.0 1 2 x)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid.axislines import SubplotZero | |
file = open("data.txt","rU") | |
xs = [] | |
for line in file: | |
xs.append(float(line.strip())) | |
fig = plt.figure(1) | |
ax = SubplotZero(fig,111, | |
xlabel="N", | |
ylabel="Number of Prime Lengthed Chains Less Than or Equal To N Divided By N") | |
fig.add_subplot(ax) | |
x = range(1,len(xs)+1) | |
ax.plot(x,xs) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment