# Numeric to Alphabetic Organization [closed]

I have a list of images grouped numerically (YI0.png, YI1.png...YI20479.png). I want them sorted alphabetically, like so:

YI0.png -> YIA.png
YI1.png -> YIAA.png


without my last image having 20479 As in it.

## Input

A directory name.

## Output

All files in that directory will be alphabetically renamed.

## Constraints

• The pattern is always Prefix Number.Extension
• There are no subdirectories
• All files in the directory adhere to the pattern
• Number starts at 0
• Prefix doesn't contain numbers

## Example

Directory consisting of Pie0.txt, Pie1.txt, all the way to Pie11.txt would be renamed to PieA.txt, PieB.txt, all the way to PieL.txt.

If it goes to Pie28.txt, they would be renamed like so:

Pie0.txt -> PieA.txt
Pie1.txt -> PieAA.txt
Pie2.txt -> PieAB.txt
Pie3.txt -> PieB.txt
Pie28.txt -> PieZ.txt


Remember, this is , so the answer in the shortest bytes wins.

• will all files in the dir be of the form "some_letters_that_are_always_the_sameNumber.txt"? – Maltysen Sep 5 '16 at 16:19
• Yes, it will have a pattern of PrefixNumber.Extension @Maltysen – Soren Sep 5 '16 at 16:20
• will be ever have three length codes? – Maltysen Sep 5 '16 at 16:37
• @Jonathan Allan only letters, not numbers. Lowercase and uppercase are allowed though. – Soren Sep 5 '16 at 18:53
• This needs a spec. At present we have to guess what it might be from two examples. – Peter Taylor Sep 5 '16 at 21:20

# Perl, 65 bytes

Assumes the number sequence starts with 0 and has no holes (or duplicates if there are extra leading zeros). No error checking. Assumes only plain files, filenames do not start with . and the user can enter the directory.

Run with the directory as argument

alphaorg.pl directory


alphaorg.pl:

#!/usr/bin/perl
chdir pop;$a=A;@F=sort map$a++,<*>;rename$_,s/\d+/$F[$&]/r for<*>  If the directory name can't contain digits and your sytem will accept / as directory separator (unix and windows do), this 61 byte version is shorter (give directory name on STDIN here): #!/usr/bin/perl -ln$a=A;@F=sort map$a++,@;=<$_/*>;rename$_,s/\d+/$F[$&]/r for@  # Haskell - 97 bytes I probably picked the wrong language; Haskell has painfully long names for IO operations r p=do f<-getDirectoryContents p;sequence_.zipWith renameFile(sort f).sort$permutations['A'..'Z']


(this program has O(26^26) in run-time unless you're on a quantum computer)

• Maybe I am on a Quantum Computer :^) no lol I wish though – Soren Sep 5 '16 at 18:51
• @moo_we_all_do You could be- IBM is handing out access to a 6 qubit quantum computer at the moment (I got it, so it can't be that hard). Unfortunately you're gonna need about 123 qubits to run this program in real time .. – BlackCap Sep 5 '16 at 19:05
• I also now have access to it. If I had $100 dollars, I would pay you$100 to write this program in QASM. That would astound me! – Soren Sep 5 '16 at 19:48
• @moo_we_all_do R x|-Zip(Sort x).Sort\$Permutations['A'..'Z']. This is QML, a haskell inspired quantum language with a compiler written in haskell: sneezy.cs.nott.ac.uk/qml Obviusly you can't read files or anything yet, so you have to pass it the file names as a list of strings. It is in my opinion by far the best effort at a high level quantum language as of now. Don't ask me why he chose to have uppercase names for functions – BlackCap Sep 5 '16 at 21:20