How to resolve the algorithm Largest int from concatenated ints step by step in the NetRexx programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Largest int from concatenated ints step by step in the NetRexx programming language

Table of Contents

Problem Statement

Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer. Use the following two sets of integers as tests   and   show your program output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Largest int from concatenated ints step by step in the NetRexx programming language

Source code in the netrexx programming language

/* NetRexx */
options replace format comments java crossref symbols nobinary

runSample(arg)
return

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method largestInt(il) public static
  ri = ''
  wa = ''
  -- put the list into an indexed string
  wa[0] = il.words
  loop ww = 1 to wa[0]
    wa[ww] = il.word(ww)
    end ww

  -- order the list
  loop wx = 1 to wa[0] - 1
    loop wy = wx + 1 to wa[0]
      xx = wa[wx]
      yy = wa[wy]
      xy = xx || yy
      yx = yy || xx
      if xy < yx then do
        -- swap xx and yy
        wa[wx] = yy
        wa[wy] = xx
        end
      end wy
    end wx

  -- rebuild list from indexed string
  loop ww = 1 to wa[0]
    ri = ri wa[ww]
    end ww
  return ri.space(0) -- concatenate the list elements into a single numeric

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
  ints = [ -
    '1 34 3 98 9 76 45 4', -
    '54 546 548 60' -
    ]
  loop il over ints
    say largestInt(il).right(20) ':' il.space(1, ',')
    end il
  return

  

You may also check:How to resolve the algorithm Permutations step by step in the Stata programming language
You may also check:How to resolve the algorithm Introspection step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the Groovy programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the C++ programming language
You may also check:How to resolve the algorithm Calendar - for REAL programmers step by step in the Kotlin programming language