大家好,
任何对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)
将每个值绘制成各种散点图
干杯 |