ollie 发表于 2022-7-6 11:03:26

Collatz连接

大家好,
 
任何对collatz连接感兴趣的人(一半或三加一)都可以享受这一点
 

(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
)

 
基本上,它计算出用户定义范围内的迭代次数,直到起始数达到其停止点(1)
 
将每个值绘制成各种散点图
 
干杯

Lee Mac 发表于 2022-7-6 11:39:00

有趣的奥利-我喜欢数学线程
 
我倾向于这样编码:
 

(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
)
)
 
我希望你不介意

Lee Mac 发表于 2022-7-6 12:24:21

在同一条大街上还有一些。。。
 
http://www.cadtutor.net/forum/showthread.php?t=40416
 
http://www.cadtutor.net/forum/showthread.php?t=45082
页: [1]
查看完整版本: Collatz连接