exceed Posted June 17, 2022 Share Posted June 17, 2022 this is a simple routine to put in numbers into the Collatz conjecture. https://en.wikipedia.org/wiki/Collatz_conjecture Command - collatz : graphic mode, like the gif above. - collatztxt : text mode, like below Command: COLLATZTXT input start number : 12302198909 12302198909>36906596728>18453298364>9226649182>4613324591>13839973774>6919986887>20759960662>10379980331>31139940994>15569970497>46709911492>23354955746>11677477873>35032433620>17516216810>8758108405>26274325216>13137162608>6568581304>3284290652>1642145326>821072663>2463217990>1231608995>3694826986>1847413493>5542240480>2771120240>1385560120>692780060>346390030>173195015>519585046>259792523>779377570>389688785>1169066356>584533178>292266589>876799768>438399884>219199942>109599971>328799914>164399957>493199872>246599936>123299968>61649984>30824992>15412496>7706248>3853124>1926562>963281>2889844>1444922>722461>2167384>1083692>541846>270923>812770>406385>1219156>609578>304789>914368>457184>228592>114296>57148>28574>14287>42862>21431>64294>32147>96442>48221>144664>72332>36166>18083>54250>27125>81376>40688>20344>10172>5086>2543>7630>3815>11446>5723>17170>8585>25756>12878>6439>19318>9659>28978>14489>43468>21734>10867>32602>16301>48904>24452>12226>6113>18340>9170>4585>13756>6878>3439>10318>5159>15478>7739>23218>11609>34828>17414>8707>26122>13061>39184>19592>9796>4898>2449>7348>3674>1837>5512>2756>1378>689>2068>1034>517>1552>776>388>194>97>292>146>73>220>110>55>166>83>250>125>376>188>94>47>142>71>214>107>322>161>484>242>121>364>182>91>274>137>412>206>103>310>155>466>233>700>350>175>526>263>790>395>1186>593>1780>890>445>1336>668>334>167>502>251>754>377>1132>566>283>850>425>1276>638>319>958>479>1438>719>2158>1079>3238>1619>4858>2429>7288>3644>1822>911>2734>1367>4102>2051>6154>3077>9232>4616>2308>1154>577>1732>866>433>1300>650>325>976>488>244>122>61>184>92>46>23>70>35>106>53>160>80>40>20>10>5>16>8>4>2>1 code is below ; COLLATZ - 2022.06.17 exceed ; this is a simple routine to plug in numbers into the "Collatz conjecture" ; ; Command List ; collatztxt - Only text output. When you enter a number, it does a Colatz conjecture until it reaches 1. ; collatz - run collatz guesses by 100, starting at 2 It rotates +5 degrees for odd numbers and -5 degrees for even numbers. ; It asks if you want to continue every 100 in case of freezing. (defun c:collatz ( / a ) (setq a 1) (while (getstring "\n continue? (SpaceBar - Continue / ESC - End) - ") (repeat 100 (ex:collatzgr a) (setq a (+ a 1)) ) (princ "\n collatz graph done - from ") (princ (- a 100)) (princ " to ") (princ a) (command "_.Zoom" "_E") ) (princ) ) (defun c:collatztxt ( / n ) (setq n (getreal "\n input start number : ")) (princ (strcat "\n " (rtos n 2 0))) (while (> n 1) (cond ((= (rem n 2) 1) (setq n (+ (* n 3) 1)) (princ (strcat ">" (rtos n 2 0))) ) ((= (rem n 2) 0) (setq n (/ n 2)) (princ (strcat ">" (rtos n 2 0))) ) ) ) (princ) ) (defun EX:COLLATZGR ( n / mspace basedeg deltadeg basept pt2 collatzline ) (vl-load-com) (defun dtr (x) (* pi (/ x 180.0)) ) (defun rtd (x) (* x (/ 180.0 pi)) ) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq basedeg 90) (setq deltadeg 5) (setq basept (list 0 0 0)) ;(princ (strcat "\n " (rtos n 2 0))) (while (> n 1) (cond ((= (rem n 2) 1) (setq n (+ (* n 3) 1)) (setq pt2 (polar basept (dtr basedeg) n)) (setq basedeg (+ basedeg deltadeg)) (setq collatzline (vla-addline mspace (vlax-3d-point basept)(vlax-3d-point pt2))) (setq basept pt2) ;(princ (strcat ">" (rtos n 2 0))) ) ((= (rem n 2) 0) (setq n (/ n 2)) (setq pt2 (polar basept (dtr basedeg) n)) (setq basedeg (- basedeg deltadeg)) (setq collatzline (vla-addline mspace (vlax-3d-point basept)(vlax-3d-point pt2))) (setq basept pt2) ;(princ (strcat ">" (rtos n 2 0))) ) ) ) (princ) ) 2 Quote Link to comment Share on other sites More sharing options...
mhupp Posted June 17, 2022 Share Posted June 17, 2022 (edited) Edited June 17, 2022 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
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.