0 Members and 1 Guest are viewing this topic.
(defun Smallest1 (n / d) (setq d 1.) (while (and (not (equal (rem d n) 0. 1.e-16)) (< d 1.797693134862315e308)) (setq d (+ (* d 10.) 1.)) ) d)
_$ (Smallest1 2011)1.11111e+233
Brute force method:Code: [Select](defun Smallest1 (n / d) (setq d 1.) (while (and (not (equal (rem d n) 0. 1.e-16)) (< d 1.797693134862315e308)) (setq d (+ (* d 10.) 1.)) ) d)Result:Code: [Select]_$ (Smallest1 2011)1.11111e+233I don't think it's the correct one though: 233 - 1's. But it's as close as AutoLisp is going to get to it using just its internal data structures. You'd probably get a better result if you could use BigInts and run it for several days.
This is my answer.
_$ (BenchMark '((test1) (test2) (test3)))Benchmarking ..............Elapsed milliseconds / relative speed for 2048 iteration(s): (TEST3).....1062 / 4.81 <fastest> (TEST1).....2781 / 1.84 (TEST2).....5109 / 1.00 <slowest>_$
and this is by Python, Brute force is adopted. Python support big num operation, and the speed is acceptable.