RosettaCodeData/Task/Largest-int-from-concatenated-ints/Factor/largest-int-from-concatenated-ints.factor
2018-06-22 20:57:24 +00:00

15 lines
689 B
Factor

USING: assocs io kernel math qw sequences sorting ;
IN: rosetta-code.largest-int
: pad ( target seq -- padded )
2dup length / swap <repetition> concat swap head ;
: largest-int ( seq -- )
dup dup [ length ] map supremum ! find longest length so we know how much to pad
[ swap pad ] curry map ! pad the integers
<enum> sort-values ! sort the padded integers
keys ! find the original indices of the sorted integers
swap nths ! order non-padded integers according to their sorted order
reverse concat print ;
qw{ 1 34 3 98 9 76 45 4 } qw{ 54 546 548 60 } [ largest-int ] bi@