# Unique code generation [closed]

As input, you are given a positive integer n. Output a code in response. Each n should generate a unique code. There are some constraints on the code that it outputs:

• The code must be 7 or more characters long in based on the input.
• The code will be have only 7 characters when input string is less than 676000 and must be unique.
• The code always begins with ST
• The third and fourth characters are letters from A-Z
• The remaining characters are numbers.

so if 1 then STAA001

  2 then STAA002


upto 999 then STAA999

  1K then STAB000


this will continue unto 676599 then STZZ999, (still this total count is 7) so after this for 676000 then STAA0000 (count is 8) and so on.

This is code golf, so the shortest entry in bytes wins.

KMT's original post for reference:

I need the generate the code using input value. The code must be 7 or more character Consider Sample code STAA000 in which 'ST' is always constant and next to characters changes based on the input they must alphabets from A-Z and the remaining characters are number.

EX:

  Input         Result

1. 100              STAA100
2. 2201             STAB201
3. 676001           STAA0001
4. 677111           STAA1111

• Hi, welcome to PPCG! Currently your question is incomplete because it lacks an objective winning criterion. Oct 10 '14 at 7:34
• In addition, if you are asking a general programming question, it will better suited at Stack Overflow.​​​​​​​​​​​​​​​ Oct 10 '14 at 7:35
• knt: You asked me to edit it so that it could be posted here. I have done that, but note that PPCG is not for real-life programming questions. You may not like the answers you'll get. Oct 10 '14 at 7:52
• Trivial variant of Mixed Base Conversion Oct 10 '14 at 8:13
• If you're looking for a real-world solution, this isn't the right place to ask. This site is for programming challenges and contests, not general programming questions. You might want to try Stack Overflow instead. Thanks!
– Doorknob
Oct 10 '14 at 12:36

## CJam, 9

"STAA00"r


Just prints the number back, no fancy algorithm.

• @knt His code works fine, you specified that it must be at least 7 characters, his does that. If you input 676001 it will output 'STAA00676001' which is a valid code by your description... Oct 10 '14 at 12:19
• @spocot no if the input is 676001 means the result must be STAA0001. Oct 10 '14 at 12:23
• The algorithm is 0-999 will have code from STAA000-STAA999 from 1000-1999 it will have STAB000-STAB999 so by using this we will have 676000 combination and if the number is 676001 then we will code with STAA0001. Now it is possible to understand the algorithm. Oct 10 '14 at 12:26
• @knt Example≠clear question Oct 10 '14 at 12:33

# Pyth, 9

p*w3"STAA


Examples:

$pyth -c 'p*w3"STAA' <<< 0 STAA000$ pyth -c 'p*w3"STAA' <<< 677111
STAA677111677111677111


This is exactly equivalent to the following python 3 code:

print("STAA", end=input()*3)


The *3 is necessary to guarantee the result is at least 7 characters.

• You should just change 'STAA' to 'STAA00' and remove the *3 because the *3 produces a code with a length of 5 if the user inputs a 0. Oct 10 '14 at 12:23
• @spocot Your suggestion, e.g. pw"STAA00 works just as well. However, see the first example, which demonstrates a user input of 0. In particular, a string multiplication by 3 is performed, not an integer multiplication by 3. Oct 10 '14 at 12:30
• I see, my mistake Oct 10 '14 at 12:32
• @isaacg Also please refer the example I have given in the question. Only it should begin with ST, but when input is 1999 it must STAB999, also when 677111 it should be STAA1111 but not always 'STAA'. Oct 10 '14 at 12:34