How do I convert this Java code to Rexx inorder to generate Luhn compatible credit cards?

233 views Asked by At
       public string GenerateCardTokenOptimised()
        {
            int[] checkArray = new int[15];
            
            var cardNum = new int[16];
 
            for (int d = 14; d >= 0; d--)
            {
                cardNum[d] = _random.Next(0, 9);
                checkArray[d] = ( cardNum[d] * (((d+1)%2)+1)) % 9;
            }
 
            cardNum[15] = ( checkArray.Sum() * 9 ) % 10;
 
            var sb = new StringBuilder(); 
 
            for (int d = 0; d < 16; d++)
            {
                sb.Append(cardNum[d].ToString());
            } 
            return sb.ToString();
        }

It seems Rexx does not have the usual arrays in other languages so how can I implement this

1

There are 1 answers

2
Bruce Martin On

Rexx has stem variables. Stem variables are Associate arrays like Map<String, String> in Java and are used instead of arrays.

You can do

    do i = 1 to 10
       myArray.i = i
    end

you can also use strings as key in stem variables

    color = 'green'
    say "Color value: " colorLookup.color

You can also check if something is found

   false = 0
   true = 1

   found. = false /* initialize stem to false (0) */

   do i = 1 to 10
      square = i * i
      found.square = true
   end

   do i = 1 to 100
      if found.i = true then do
         say i "is a square"
      end
   end