Anonymous user
Largest int from concatenated ints: Difference between revisions
Largest int from concatenated ints (view source)
Revision as of 15:01, 25 January 2018
, 6 years ago→{{header|Common Lisp}}: Showing a Common Lisp implementation that goes by the task's suggestions
m (→{{header|REXX}}: added wording to the REXX section header, used a template for the output.) |
(→{{header|Common Lisp}}: Showing a Common Lisp implementation that goes by the task's suggestions) |
||
Line 452:
6054548546
998764453341
</pre>
Implementing the second algorithm suggestion :
<lang lisp>
(defun int-concat (ints)
(read-from-string (apply #'concatenate (cons 'string (mapcar #'princ-to-string ints)))))
(defun by-biggest-result (first second)
(> (int-concat (list first second)) (int-concat (list second first))))
(defun make-largest-int (ints)
(int-concat (sort ints #'by-biggest-result)))
</lang>
{{out}}
<pre>
> (make-largest-int '(1 34 3 98 9 76 45 4))
998764543431
> (make-largest-int '(54 546 548 60))
6054854654
</pre>
|