French license plates

Pure Bash (no external utils), 64

  • 2 bytes saved thanks to @NahuelFouilleul
x={A..Z}
eval f=($x$x-%03d-$x$x)
printf ${f[$1/1000]} $[$1%1000]

Try it online! - takes about 10s to run over the 7 testcases.

  • Line #1 is a simple assignment of a string to a variable
  • Line #2 is a brace expansion to build an array of printf format strings, one for all 456,976 possible letter combinations, with the digits not yet specified. The eval is required to ensure variable expansion (of x) occurs before brace expansion.
  • Line #3 indexes the array to get the appropriate format string and takes the digits portion as its parameter.

Perl 5 (-ap), 47 bytes

$_=AAAA000;$_++while$F[0]--;s/(..)(\d+)/-$2-$1/

Try it online!


PHP, 74 bytes

for($a=AAAA000;$argn--;$a++);echo preg_replace('/(..)(\d+)/','-$2-$1',$a);

Try it online!


Ruby, 61 59 55 bytes

->n{s='AA-AA000-';eval's.succ!;'*n;s[2]+=s[5,4];s[0,9]}

Also 55 bytes:

->n{s='AA-AA000-';eval's.succ!;'*n;s[2]+=s.slice!5,4;s}

Try it online!

This initializes a counter to AA-AA000-, increments it n times (by multiplying a string of the code that does so by n and evaling), and then moves the last 4 characters after the 3nd.