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.


  Input         Result

  1. 100              STAA100
  2. 2201             STAB201
  3. 676001           STAA0001
  4. 677111           STAA1111
  • \$\begingroup\$ Hi, welcome to PPCG! Currently your question is incomplete because it lacks an objective winning criterion. \$\endgroup\$
    – absinthe
    Oct 10 '14 at 7:34
  • \$\begingroup\$ In addition, if you are asking a general programming question, it will better suited at Stack Overflow.​​​​​​​​​​​​​​​ \$\endgroup\$
    – absinthe
    Oct 10 '14 at 7:35
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – absinthe
    Oct 10 '14 at 7:52
  • 1
    \$\begingroup\$ Trivial variant of Mixed Base Conversion \$\endgroup\$ Oct 10 '14 at 8:13
  • 2
    \$\begingroup\$ 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! \$\endgroup\$
    – Doorknob
    Oct 10 '14 at 12:36

CJam, 9


Just prints the number back, no fancy algorithm.

  • \$\begingroup\$ @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... \$\endgroup\$
    – spocot
    Oct 10 '14 at 12:19
  • \$\begingroup\$ @spocot no if the input is 676001 means the result must be STAA0001. \$\endgroup\$
    – Arasuvel
    Oct 10 '14 at 12:23
  • \$\begingroup\$ 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. \$\endgroup\$
    – Arasuvel
    Oct 10 '14 at 12:26
  • 2
    \$\begingroup\$ @knt You didn't specify that in your question. My answer clearly matches your requirements. Please edit your question. \$\endgroup\$
    – Shujal
    Oct 10 '14 at 12:29
  • 2
    \$\begingroup\$ @knt Example≠clear question \$\endgroup\$
    – Shujal
    Oct 10 '14 at 12:33

Pyth, 9



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

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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – spocot
    Oct 10 '14 at 12:23
  • \$\begingroup\$ @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. \$\endgroup\$
    – isaacg
    Oct 10 '14 at 12:30
  • \$\begingroup\$ I see, my mistake \$\endgroup\$
    – spocot
    Oct 10 '14 at 12:32
  • \$\begingroup\$ @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'. \$\endgroup\$
    – Arasuvel
    Oct 10 '14 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.