Skip to main content
shivas3219
Participating Frequently
Dec 29, 2024 6:31 PM UTC
Question

Fetch unique 3 character code

How to create list of unique 3 character alphabet code. If i pass "AAA" and 2, it should return "AAB", "AAC". 2 unique codes after "AAA"

    17 replies

    venkatrea696188
    Inspiring
    Dec 30, 2024 11:52 AM UTC

    Couple of questions , where you intended to use this and the limit of iteration count ?? This you can write using Code and char function .

    Pasting a Sample code for your reference , You need to change the code if the iteration count is more than 25

    a!localVariables(
      local!inputcodes: if(
        a!isNullOrEmpty(ri!input),
        null,
        code(ri!input)
      ),
      local!iterate: a!forEach(
        items: enumerate(ri!iterationCount+1),
        expression: a!localVariables(
          local!index:fv!item,
        concat(
          char(local!inputcodes[1]),
          char(local!inputcodes[2]),
          char(local!inputcodes[3] + local!index)
        ))
      ),
      local!iterate
    )

    mathieud0001
    Genius
    Dec 30, 2024 2:59 PM UTC

    Random != Unique.

    Very curious as to why you would need to do this but here is some code to generate a string variable length with random characters. Not unique though. You should look into UUIDs if you want to achieve this.

    a!localVariables(
      local!character: "A",
      local!numberOfCharactersToAppend: 2,
      local!allCharacters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      local!charactersToAppend: a!forEach(
        items: enumerate(local!numberOfCharactersToAppend),
        expression: a!localVariables(
          local!randomIndex: rounddown((rand() * 26 + 1), 0),
          mid(
            local!allCharacters,
            local!randomIndex,
            1
          )
        )
      ),
      concat(
        local!character,
        joinarray(local!charactersToAppend, "")
      )
    )

    shivas3219
    Participating Frequently
    Dec 30, 2024 5:32 PM UTC

    Thanks all for the response. [mention:ba9672c2f5294cb98c0a2b8fb79cf967:e9ed411860ed4f2ba0265705b8793d05] If i pass "AAZ" and 2. its returning "AA[" and "AA\" where it should be "ABA" and "ABB"

    venkatrea696188
    Inspiring
    Dec 30, 2024 6:25 PM UTC

    Yup it's gonna give you that .I just pasted sample code how it needs be done 

    Very curious as to why you would need to do this

    Same here ,Can I know why you need this in the first place . We can suggest alternatives