ollie Posted June 8, 2010 Posted June 8, 2010 Hi all, Anyone intrested in the collatz conjuncture (Half or triple plus one) may enjoy this (vl-load-com) (defun c:colCountMap( / col ulmit ms) (setq ms (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object)))) (setq lbound (getreal "\nEnter lower limit")) (setq ubound (getreal"\nEnter higher limit")) (while(<= lbound ubound) (vla-addcircle ms (vlax-3d-point (list (float lbound )(setq col(collatz lbound nil)) 0.0)) 0.25) (setq lbound (1+ lbound)) (if(> col ulimit) (setq ulimit col) ) ) (vla-addline ms(vlax-3d-point (list 0.0 0.0 0.0))(vlax-3d-point(list 0.0 (float ulimit)))) (vla-addline ms(vlax-3d-point (list 0.0 0.0 0.0))(vlax-3d-point(list (float ubound) 0.0 0.0))) ) (defun collatz(lbound flag / stop return) (setq stop nil) (setq return (list lbound)) (while (= nil stop) (if(> lbound 1 ) (progn (if(= 0 (rem lbound 2)) (setq return (append return (list (/ lbound 2)))) (setq return (append return (list (1+(* 3 lbound))))) ) (setq lbound (nth (1- (length return)) return)) ) (setq stop t) ) ) (if(/= t flag) (setq return (length return)) ) return ) Basically it works out the number of iterations between a user defined range until the starting number reaches it's stopping point (1) Each value is plotted to a scatter graph of sorts cheers Quote
Lee Mac Posted June 8, 2010 Posted June 8, 2010 Interesting Ollie - I love the mathematical threads I would be inclined to code it like this: (defun c:colCountMap ( / ms lbound ubound col ulimit ) (vl-load-com) (setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (if (and (setq lbound (getint "\nEnter Lower limit: ")) (setq ubound (getint "\nEnter Upper limit: "))) (progn (while (<= lbound ubound) (vla-put-color (vla-addcircle ms (vlax-3d-point (list lbound (setq col (Collatz lbound)) 0.0)) 0.25 ) acyellow ) (setq lbound (1+ lbound)) (if (> col ulimit) (setq ulimit col)) ) (mapcar (function (lambda ( p ) (vla-put-color (vla-AddLine ms (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point p)) acGreen ) ) ) (list (list 0. ulimit 0.) (list ulimit 0. 0.)) ) ) ) (princ) ) (defun Collatz ( num ) ( (lambda ( i ) (while (< 1 num) (setq i (1+ i)) (setq num (if (zerop (logand 1 num)) (/ num 2) (1+ (* 3 num))) ) ) i ) 0 ) ) I hope you don't mind Quote
Lee Mac Posted June 8, 2010 Posted June 8, 2010 Some more down the same avenue... http://www.cadtutor.net/forum/showthread.php?t=40416 http://www.cadtutor.net/forum/showthread.php?t=45082 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.