French license platesSlices of triangular alphabetsPerfect License PlatesStraddling Checkerboard...
I reverse the source code, you reverse the input!
When did Unix stop storing passwords in clear text?
How many stack cables would be needed if we want to stack two 3850 switches
Delete n lines skip 1 line script
"I will not" or "I don't" as an answer for negative orders?
Is it possible to change an API response using the host file?
Smallest PRIME containing the first 11 primes as sub-strings
Maximize assigned tasks to each worker
What was Han searching through when he found where Lando was?
GPLv3 forces us to make code available, but to who?
Discrepancy regarding AoE point of origin between English and German PHB
what organs or modifications would be needed to have hairy fish?
What should I consider when deciding whether to delay an exam?
A famous scholar sent me an unpublished draft of hers. Then she died. I think her work should be published. What should I do?
Avoiding dust scattering when you drill
Is it ok if I haven't decided my research topic when I first meet with a potential phd advisor?
My machine, client installed VPN,
Sci-fi movie with one survivor and an organism(?) recreating his memories
LM324 - Issue with output in negative feedback
Question about a degree 5 polynomial with no rational roots
Concerning a relationship in the team
What is Weapon Handling?
After viewing logs with journalctl, how do I exit the screen that says "lines 1-2/2 (END)"?
Why is Pelosi so opposed to impeaching Trump?
French license plates
Slices of triangular alphabetsPerfect License PlatesStraddling Checkerboard CipherPronounce numbersThe Spain license plates gameHow many points does my license plate give?Find the average of a wordGenerate Numpad-Friendly NumbersSimple String Reflection
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Sandbox
French License Plates
French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD
Challenge
Write a program or function that, for a given number, outputs the corresponding french license plate number. Your program should not handle any special case as specified in the linked page. It should be able to generate the full 26*26*1000*26*26 => 456 976 000
possible plates, or as far as your language can support.
The numbering system goes as follows:
- AA-000-AA to AA-999-AA (numbers evolve first);
- AA-000-AB to AA-999-AZ (then the last letter on the right);
- AA-000-BA to AA-999-ZZ (then the first letter on the right);
- AB-000-AA to AZ-999-ZZ (then the last letter on the left);
- BA-000-AA to ZZ-999-ZZ (then the first letter on the left).
Input
- The plate number's index as an integer
Output
- The corresponding french license plate number
Additional information
- Letters have to be uppercase
- You can use both 0-based and 1-based indexing to generate the plates (meaning AA-000-AA can correspond to
0
or1
, assuming all the other test cases use the same indexing.
This is code-golf, shortest answer in every language wins!
Test cases (0-based indexing)
0 -> AA-000-AA
1 -> AA-001-AA
999 -> AA-999-AA
1000 -> AA-000-AB
675 999 -> AA-999-ZZ
676 000 -> AB-000-AA
456 975 999 -> ZZ-999-ZZ
code-golf string number base-conversion
$endgroup$
add a comment
|
$begingroup$
Sandbox
French License Plates
French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD
Challenge
Write a program or function that, for a given number, outputs the corresponding french license plate number. Your program should not handle any special case as specified in the linked page. It should be able to generate the full 26*26*1000*26*26 => 456 976 000
possible plates, or as far as your language can support.
The numbering system goes as follows:
- AA-000-AA to AA-999-AA (numbers evolve first);
- AA-000-AB to AA-999-AZ (then the last letter on the right);
- AA-000-BA to AA-999-ZZ (then the first letter on the right);
- AB-000-AA to AZ-999-ZZ (then the last letter on the left);
- BA-000-AA to ZZ-999-ZZ (then the first letter on the left).
Input
- The plate number's index as an integer
Output
- The corresponding french license plate number
Additional information
- Letters have to be uppercase
- You can use both 0-based and 1-based indexing to generate the plates (meaning AA-000-AA can correspond to
0
or1
, assuming all the other test cases use the same indexing.
This is code-golf, shortest answer in every language wins!
Test cases (0-based indexing)
0 -> AA-000-AA
1 -> AA-001-AA
999 -> AA-999-AA
1000 -> AA-000-AB
675 999 -> AA-999-ZZ
676 000 -> AB-000-AA
456 975 999 -> ZZ-999-ZZ
code-golf string number base-conversion
$endgroup$
add a comment
|
$begingroup$
Sandbox
French License Plates
French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD
Challenge
Write a program or function that, for a given number, outputs the corresponding french license plate number. Your program should not handle any special case as specified in the linked page. It should be able to generate the full 26*26*1000*26*26 => 456 976 000
possible plates, or as far as your language can support.
The numbering system goes as follows:
- AA-000-AA to AA-999-AA (numbers evolve first);
- AA-000-AB to AA-999-AZ (then the last letter on the right);
- AA-000-BA to AA-999-ZZ (then the first letter on the right);
- AB-000-AA to AZ-999-ZZ (then the last letter on the left);
- BA-000-AA to ZZ-999-ZZ (then the first letter on the left).
Input
- The plate number's index as an integer
Output
- The corresponding french license plate number
Additional information
- Letters have to be uppercase
- You can use both 0-based and 1-based indexing to generate the plates (meaning AA-000-AA can correspond to
0
or1
, assuming all the other test cases use the same indexing.
This is code-golf, shortest answer in every language wins!
Test cases (0-based indexing)
0 -> AA-000-AA
1 -> AA-001-AA
999 -> AA-999-AA
1000 -> AA-000-AB
675 999 -> AA-999-ZZ
676 000 -> AB-000-AA
456 975 999 -> ZZ-999-ZZ
code-golf string number base-conversion
$endgroup$
Sandbox
French License Plates
French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD
Challenge
Write a program or function that, for a given number, outputs the corresponding french license plate number. Your program should not handle any special case as specified in the linked page. It should be able to generate the full 26*26*1000*26*26 => 456 976 000
possible plates, or as far as your language can support.
The numbering system goes as follows:
- AA-000-AA to AA-999-AA (numbers evolve first);
- AA-000-AB to AA-999-AZ (then the last letter on the right);
- AA-000-BA to AA-999-ZZ (then the first letter on the right);
- AB-000-AA to AZ-999-ZZ (then the last letter on the left);
- BA-000-AA to ZZ-999-ZZ (then the first letter on the left).
Input
- The plate number's index as an integer
Output
- The corresponding french license plate number
Additional information
- Letters have to be uppercase
- You can use both 0-based and 1-based indexing to generate the plates (meaning AA-000-AA can correspond to
0
or1
, assuming all the other test cases use the same indexing.
This is code-golf, shortest answer in every language wins!
Test cases (0-based indexing)
0 -> AA-000-AA
1 -> AA-001-AA
999 -> AA-999-AA
1000 -> AA-000-AB
675 999 -> AA-999-ZZ
676 000 -> AB-000-AA
456 975 999 -> ZZ-999-ZZ
code-golf string number base-conversion
code-golf string number base-conversion
asked 9 hours ago
ElcanElcan
5062 silver badges10 bronze badges
5062 silver badges10 bronze badges
add a comment
|
add a comment
|
15 Answers
15
active
oldest
votes
$begingroup$
Ruby, 61 59 bytes
->n{s='AAAA000';eval's.succ!;'*n;[s[0,2],s[4,3],s[2,2]]*?-}
Also 59 bytes:
->n{s='AAAA000';eval's.succ!;'*n;s[1]+=?-+s[4,3]+?-;s[0,9]}
The crux of both of these is the same -- they initialize a counter to AAAA000
, increment it n
times (by multiplying a string of the code that does so by n and eval
ing), and then adjust the string to fit the format requested (in two different ways).
Try it online!
$endgroup$
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
add a comment
|
$begingroup$
JavaScript (Node.js), 82 bytes
n=>'32-654-10'.replace(/d/g,x=>Buffer([x&4?n/10**(x-4)%10+48:n/1e3/26**x%26+65]))
Try it online!
$endgroup$
add a comment
|
$begingroup$
R, 101 bytes
b=0:3;a=scan()%/%c(10^b,1e3*26^b)%%rep(c(10,26),e=4);intToUtf8(c(a[8:7],-20,a[3:1]-17,-20,a[6:5])+65)
Try it online!
Just does the needed arithmetic computations. I saved 5 bytes by including in the vector a
a useless value at a[4]
, allowing me to reuse the helper vector b
.
$endgroup$
add a comment
|
$begingroup$
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!
$endgroup$
add a comment
|
$begingroup$
Python 3, 79 78 77 bytes
lambda n:f"%c%c-{n%1000:03}-%c%c"%(*(65+n//1000//26**i%26for i in[3,2,1,0]),)
Try it online!
I somehow never realised that the f"string"
format shortcut exists until seeing Black Owl Kai's answer.
New contributor
$endgroup$
$begingroup$
78 bytes by replacingtuple
by(*...,)
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
APL+WIN, 61 bytes
Prompts for integer:
m←⎕av[4↑66+n←((4⍴26),1E3)⊤⎕]⋄(2↑m),'-',(¯3↑'00',⍕4↓n),'-',2↓m
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment
|
$begingroup$
PHP, 96 bytes
for($l=$r=AA;$x++<(0^$argn/1e3);)$r>ZY?++$l+$r=AA:$r++;echo"$l-".str_pad($argn%1e3,3,0,0)."-$r";
Try it online!
I take advantage of the fact that you can increment letters in PHP! So AA++
would become AB
and AZ++
would become BA
. I calculate how many times the letters have to be incremented by getting integer part of input/1000
. Then then increment right side if it is less than ZZ
, else increment left side and reset right side to AA
. At the end the middle number is calculated by input%1000
and padded with zeros in the left.
PHP, 98 bytes
for($l=$r=AA;$argn--;)$n>998?($n=0)||$r>ZY?++$l+$r=AA:$r++:$n++;echo"$l-".str_pad($n,3,0,0)."-$r";
Try it online!
This is the original idea, similar to the above solution, but the number part itself is incremented too. So basically the loop runs input
times. This isn't an optimal solution and becomes slow for large inputs, but this is code golf, so...!
$endgroup$
$begingroup$
Looks like it breaks for456975999
, it returnsYYAA999ZZ
, also you need the dashes inbetween the parts :P
$endgroup$
– Elcan
8 hours ago
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
add a comment
|
$begingroup$
Haskell, 85 81 79 77 bytes
([h++'-':n++'-':t|h<-q"AZ",t<-q"AZ",n<-q"099"]!!)
q g=mapM(_->[g!!0..g!!1])g
Try it online!
$endgroup$
add a comment
|
$begingroup$
Jelly, 28 bytes
ØA,ØDṗ"4,3Œp⁸ịF+2,7¦”-65œ?
A monadic Link accepting an integer (1-indexed) which yields a list of characters... Crazy-slow since it builds all the plates first!
Try it online! (wont complete)
Or try a reduced alphabet version (only "ABC" for the letters).
For code which completes in a timely manner here's a 32 byte full-program (0-indexed):
dȷ+“©L§“£ż’µḢṃØAṙ1¤ḊŒHW€jDḊ€$j”-
Try this one!
$endgroup$
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,€2,4
should be€2,5
.
$endgroup$
– Grimy
6 hours ago
|
show 1 more comment
$begingroup$
Pure Bash (no external utils), 66
f=({A..Z}{A..Z}-%03d-{A..Z}{A..Z})
printf ${f[$1/1000]} $[$1%1000]
Try it online! - takes about 10s to run over the 7 testcases.
- Line #1 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.
- Line #2 indexes the array to get the appropriate format string and takes the digits portion as its parameter.
$endgroup$
add a comment
|
$begingroup$
Charcoal, 33 bytes
Nθ¹✂I⁺θφ±³≔⪪⍘⁺X²⁶¦⁵÷θφα²η¹⊟ηM⁹←⊟η
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the number.
¹
Print a -
.
✂I⁺θφ±³
Add 1000 to the number, then cast the result to string, and print the last three digits.
≔⪪⍘⁺X²⁶¦⁵÷θφα²η
Divide the number by 1000, then add 26⁵, so the conversion to custom base using the uppercase alphabet results in a string of length 6, which is then split into pairs of letters.
¹
Print a -
.
⊟η
Print the last pair of letters.
M⁹←
Move to the beginning of the number plate.
⊟η
Print the rest of the desired letters.
$endgroup$
add a comment
|
$begingroup$
Python 2, 88 bytes
lambda n:g(n/676000)+'-%03d-'%(n%1000)+g(n/1000)
g=lambda n:chr(65+n/26%26)+chr(65+n%26)
Try it online!
$endgroup$
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 3, 89 bytes
lambda n:h(n//676)+f"-{n%1000:03}-"+h(n)
h=lambda x:'%c%c'%(x//26000%26+65,x//1000%26+65)
Try it online!
-1 byte thanks to mypetition
$endgroup$
$begingroup$
Changechr(x//26000%26+65)+chr(x//1000%26+65)
to'%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.
$endgroup$
– mypetlion
7 hours ago
add a comment
|
$begingroup$
J, 56 49 bytes
226950 A.'--',7{._3|.[:,a.{~65 48+/(4 3#26 10)#:]
Try it online!
The whole thing is nothing but 8 nested trains -- if that ain't fun, what is?
┌─ 226950
├─ A.
│ ┌─ '--'
──┤ ├─ ,
│ │ ┌─ 7
└────────┤ ├─ {.
│ │ ┌─ _3
└──────┤ ├─ |.
│ │ ┌─ [:
└────┤ ├─ ,
│ │ ┌─ 'abc...'
└────┤ ├─ ~ ──────── {
│ │
└────┤ ┌─ 65 48
│ ├─ / ───── +
└──────────┤
│ ┌─ '4 3#26 10'
└───────┼─ #:
└─ ]
$endgroup$
add a comment
|
$begingroup$
Clean, 107 bytes
import StdEnv
A=['A'..'Z']
N=['0'..'9']
$n=[[a,b,'-',x,y,z,'-',c,d]\a<-A,b<-A,c<-A,d<-A,x<-N,y<-N,z<-N]!!n
Try it online!
Defines $ :: Int -> [Char]
giving the n-th zero-indexed licence plate.
$endgroup$
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f193432%2ffrench-license-plates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Ruby, 61 59 bytes
->n{s='AAAA000';eval's.succ!;'*n;[s[0,2],s[4,3],s[2,2]]*?-}
Also 59 bytes:
->n{s='AAAA000';eval's.succ!;'*n;s[1]+=?-+s[4,3]+?-;s[0,9]}
The crux of both of these is the same -- they initialize a counter to AAAA000
, increment it n
times (by multiplying a string of the code that does so by n and eval
ing), and then adjust the string to fit the format requested (in two different ways).
Try it online!
$endgroup$
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
add a comment
|
$begingroup$
Ruby, 61 59 bytes
->n{s='AAAA000';eval's.succ!;'*n;[s[0,2],s[4,3],s[2,2]]*?-}
Also 59 bytes:
->n{s='AAAA000';eval's.succ!;'*n;s[1]+=?-+s[4,3]+?-;s[0,9]}
The crux of both of these is the same -- they initialize a counter to AAAA000
, increment it n
times (by multiplying a string of the code that does so by n and eval
ing), and then adjust the string to fit the format requested (in two different ways).
Try it online!
$endgroup$
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
add a comment
|
$begingroup$
Ruby, 61 59 bytes
->n{s='AAAA000';eval's.succ!;'*n;[s[0,2],s[4,3],s[2,2]]*?-}
Also 59 bytes:
->n{s='AAAA000';eval's.succ!;'*n;s[1]+=?-+s[4,3]+?-;s[0,9]}
The crux of both of these is the same -- they initialize a counter to AAAA000
, increment it n
times (by multiplying a string of the code that does so by n and eval
ing), and then adjust the string to fit the format requested (in two different ways).
Try it online!
$endgroup$
Ruby, 61 59 bytes
->n{s='AAAA000';eval's.succ!;'*n;[s[0,2],s[4,3],s[2,2]]*?-}
Also 59 bytes:
->n{s='AAAA000';eval's.succ!;'*n;s[1]+=?-+s[4,3]+?-;s[0,9]}
The crux of both of these is the same -- they initialize a counter to AAAA000
, increment it n
times (by multiplying a string of the code that does so by n and eval
ing), and then adjust the string to fit the format requested (in two different ways).
Try it online!
edited 21 mins ago
answered 7 hours ago
Doorknob♦Doorknob
56.2k17 gold badges121 silver badges362 bronze badges
56.2k17 gold badges121 silver badges362 bronze badges
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
add a comment
|
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
51 bytes
$endgroup$
– G B
5 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
$begingroup$
@GB I think that's sufficiently different that you can post it as a separate answer.
$endgroup$
– Doorknob♦
2 hours ago
add a comment
|
$begingroup$
JavaScript (Node.js), 82 bytes
n=>'32-654-10'.replace(/d/g,x=>Buffer([x&4?n/10**(x-4)%10+48:n/1e3/26**x%26+65]))
Try it online!
$endgroup$
add a comment
|
$begingroup$
JavaScript (Node.js), 82 bytes
n=>'32-654-10'.replace(/d/g,x=>Buffer([x&4?n/10**(x-4)%10+48:n/1e3/26**x%26+65]))
Try it online!
$endgroup$
add a comment
|
$begingroup$
JavaScript (Node.js), 82 bytes
n=>'32-654-10'.replace(/d/g,x=>Buffer([x&4?n/10**(x-4)%10+48:n/1e3/26**x%26+65]))
Try it online!
$endgroup$
JavaScript (Node.js), 82 bytes
n=>'32-654-10'.replace(/d/g,x=>Buffer([x&4?n/10**(x-4)%10+48:n/1e3/26**x%26+65]))
Try it online!
answered 8 hours ago
ArnauldArnauld
93.3k7 gold badges110 silver badges379 bronze badges
93.3k7 gold badges110 silver badges379 bronze badges
add a comment
|
add a comment
|
$begingroup$
R, 101 bytes
b=0:3;a=scan()%/%c(10^b,1e3*26^b)%%rep(c(10,26),e=4);intToUtf8(c(a[8:7],-20,a[3:1]-17,-20,a[6:5])+65)
Try it online!
Just does the needed arithmetic computations. I saved 5 bytes by including in the vector a
a useless value at a[4]
, allowing me to reuse the helper vector b
.
$endgroup$
add a comment
|
$begingroup$
R, 101 bytes
b=0:3;a=scan()%/%c(10^b,1e3*26^b)%%rep(c(10,26),e=4);intToUtf8(c(a[8:7],-20,a[3:1]-17,-20,a[6:5])+65)
Try it online!
Just does the needed arithmetic computations. I saved 5 bytes by including in the vector a
a useless value at a[4]
, allowing me to reuse the helper vector b
.
$endgroup$
add a comment
|
$begingroup$
R, 101 bytes
b=0:3;a=scan()%/%c(10^b,1e3*26^b)%%rep(c(10,26),e=4);intToUtf8(c(a[8:7],-20,a[3:1]-17,-20,a[6:5])+65)
Try it online!
Just does the needed arithmetic computations. I saved 5 bytes by including in the vector a
a useless value at a[4]
, allowing me to reuse the helper vector b
.
$endgroup$
R, 101 bytes
b=0:3;a=scan()%/%c(10^b,1e3*26^b)%%rep(c(10,26),e=4);intToUtf8(c(a[8:7],-20,a[3:1]-17,-20,a[6:5])+65)
Try it online!
Just does the needed arithmetic computations. I saved 5 bytes by including in the vector a
a useless value at a[4]
, allowing me to reuse the helper vector b
.
edited 7 hours ago
answered 8 hours ago
Robin RyderRobin Ryder
4,1544 silver badges29 bronze badges
4,1544 silver badges29 bronze badges
add a comment
|
add a comment
|
$begingroup$
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!
$endgroup$
add a comment
|
$begingroup$
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!
$endgroup$
add a comment
|
$begingroup$
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!
$endgroup$
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!
edited 6 hours ago
answered 7 hours ago
GrimyGrimy
8,35719 silver badges38 bronze badges
8,35719 silver badges38 bronze badges
add a comment
|
add a comment
|
$begingroup$
Python 3, 79 78 77 bytes
lambda n:f"%c%c-{n%1000:03}-%c%c"%(*(65+n//1000//26**i%26for i in[3,2,1,0]),)
Try it online!
I somehow never realised that the f"string"
format shortcut exists until seeing Black Owl Kai's answer.
New contributor
$endgroup$
$begingroup$
78 bytes by replacingtuple
by(*...,)
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 3, 79 78 77 bytes
lambda n:f"%c%c-{n%1000:03}-%c%c"%(*(65+n//1000//26**i%26for i in[3,2,1,0]),)
Try it online!
I somehow never realised that the f"string"
format shortcut exists until seeing Black Owl Kai's answer.
New contributor
$endgroup$
$begingroup$
78 bytes by replacingtuple
by(*...,)
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 3, 79 78 77 bytes
lambda n:f"%c%c-{n%1000:03}-%c%c"%(*(65+n//1000//26**i%26for i in[3,2,1,0]),)
Try it online!
I somehow never realised that the f"string"
format shortcut exists until seeing Black Owl Kai's answer.
New contributor
$endgroup$
Python 3, 79 78 77 bytes
lambda n:f"%c%c-{n%1000:03}-%c%c"%(*(65+n//1000//26**i%26for i in[3,2,1,0]),)
Try it online!
I somehow never realised that the f"string"
format shortcut exists until seeing Black Owl Kai's answer.
New contributor
edited 4 hours ago
New contributor
answered 6 hours ago
Matthew JensenMatthew Jensen
312 bronze badges
312 bronze badges
New contributor
New contributor
$begingroup$
78 bytes by replacingtuple
by(*...,)
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
78 bytes by replacingtuple
by(*...,)
$endgroup$
– Black Owl Kai
5 hours ago
$begingroup$
78 bytes by replacing
tuple
by (*...,)
$endgroup$
– Black Owl Kai
5 hours ago
$begingroup$
78 bytes by replacing
tuple
by (*...,)
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
APL+WIN, 61 bytes
Prompts for integer:
m←⎕av[4↑66+n←((4⍴26),1E3)⊤⎕]⋄(2↑m),'-',(¯3↑'00',⍕4↓n),'-',2↓m
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment
|
$begingroup$
APL+WIN, 61 bytes
Prompts for integer:
m←⎕av[4↑66+n←((4⍴26),1E3)⊤⎕]⋄(2↑m),'-',(¯3↑'00',⍕4↓n),'-',2↓m
Try it online! Courtesy of Dyalog Classic
$endgroup$
add a comment
|
$begingroup$
APL+WIN, 61 bytes
Prompts for integer:
m←⎕av[4↑66+n←((4⍴26),1E3)⊤⎕]⋄(2↑m),'-',(¯3↑'00',⍕4↓n),'-',2↓m
Try it online! Courtesy of Dyalog Classic
$endgroup$
APL+WIN, 61 bytes
Prompts for integer:
m←⎕av[4↑66+n←((4⍴26),1E3)⊤⎕]⋄(2↑m),'-',(¯3↑'00',⍕4↓n),'-',2↓m
Try it online! Courtesy of Dyalog Classic
answered 8 hours ago
GrahamGraham
2,9067 silver badges8 bronze badges
2,9067 silver badges8 bronze badges
add a comment
|
add a comment
|
$begingroup$
PHP, 96 bytes
for($l=$r=AA;$x++<(0^$argn/1e3);)$r>ZY?++$l+$r=AA:$r++;echo"$l-".str_pad($argn%1e3,3,0,0)."-$r";
Try it online!
I take advantage of the fact that you can increment letters in PHP! So AA++
would become AB
and AZ++
would become BA
. I calculate how many times the letters have to be incremented by getting integer part of input/1000
. Then then increment right side if it is less than ZZ
, else increment left side and reset right side to AA
. At the end the middle number is calculated by input%1000
and padded with zeros in the left.
PHP, 98 bytes
for($l=$r=AA;$argn--;)$n>998?($n=0)||$r>ZY?++$l+$r=AA:$r++:$n++;echo"$l-".str_pad($n,3,0,0)."-$r";
Try it online!
This is the original idea, similar to the above solution, but the number part itself is incremented too. So basically the loop runs input
times. This isn't an optimal solution and becomes slow for large inputs, but this is code golf, so...!
$endgroup$
$begingroup$
Looks like it breaks for456975999
, it returnsYYAA999ZZ
, also you need the dashes inbetween the parts :P
$endgroup$
– Elcan
8 hours ago
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
add a comment
|
$begingroup$
PHP, 96 bytes
for($l=$r=AA;$x++<(0^$argn/1e3);)$r>ZY?++$l+$r=AA:$r++;echo"$l-".str_pad($argn%1e3,3,0,0)."-$r";
Try it online!
I take advantage of the fact that you can increment letters in PHP! So AA++
would become AB
and AZ++
would become BA
. I calculate how many times the letters have to be incremented by getting integer part of input/1000
. Then then increment right side if it is less than ZZ
, else increment left side and reset right side to AA
. At the end the middle number is calculated by input%1000
and padded with zeros in the left.
PHP, 98 bytes
for($l=$r=AA;$argn--;)$n>998?($n=0)||$r>ZY?++$l+$r=AA:$r++:$n++;echo"$l-".str_pad($n,3,0,0)."-$r";
Try it online!
This is the original idea, similar to the above solution, but the number part itself is incremented too. So basically the loop runs input
times. This isn't an optimal solution and becomes slow for large inputs, but this is code golf, so...!
$endgroup$
$begingroup$
Looks like it breaks for456975999
, it returnsYYAA999ZZ
, also you need the dashes inbetween the parts :P
$endgroup$
– Elcan
8 hours ago
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
add a comment
|
$begingroup$
PHP, 96 bytes
for($l=$r=AA;$x++<(0^$argn/1e3);)$r>ZY?++$l+$r=AA:$r++;echo"$l-".str_pad($argn%1e3,3,0,0)."-$r";
Try it online!
I take advantage of the fact that you can increment letters in PHP! So AA++
would become AB
and AZ++
would become BA
. I calculate how many times the letters have to be incremented by getting integer part of input/1000
. Then then increment right side if it is less than ZZ
, else increment left side and reset right side to AA
. At the end the middle number is calculated by input%1000
and padded with zeros in the left.
PHP, 98 bytes
for($l=$r=AA;$argn--;)$n>998?($n=0)||$r>ZY?++$l+$r=AA:$r++:$n++;echo"$l-".str_pad($n,3,0,0)."-$r";
Try it online!
This is the original idea, similar to the above solution, but the number part itself is incremented too. So basically the loop runs input
times. This isn't an optimal solution and becomes slow for large inputs, but this is code golf, so...!
$endgroup$
PHP, 96 bytes
for($l=$r=AA;$x++<(0^$argn/1e3);)$r>ZY?++$l+$r=AA:$r++;echo"$l-".str_pad($argn%1e3,3,0,0)."-$r";
Try it online!
I take advantage of the fact that you can increment letters in PHP! So AA++
would become AB
and AZ++
would become BA
. I calculate how many times the letters have to be incremented by getting integer part of input/1000
. Then then increment right side if it is less than ZZ
, else increment left side and reset right side to AA
. At the end the middle number is calculated by input%1000
and padded with zeros in the left.
PHP, 98 bytes
for($l=$r=AA;$argn--;)$n>998?($n=0)||$r>ZY?++$l+$r=AA:$r++:$n++;echo"$l-".str_pad($n,3,0,0)."-$r";
Try it online!
This is the original idea, similar to the above solution, but the number part itself is incremented too. So basically the loop runs input
times. This isn't an optimal solution and becomes slow for large inputs, but this is code golf, so...!
edited 7 hours ago
answered 8 hours ago
Night2Night2
3,2454 silver badges24 bronze badges
3,2454 silver badges24 bronze badges
$begingroup$
Looks like it breaks for456975999
, it returnsYYAA999ZZ
, also you need the dashes inbetween the parts :P
$endgroup$
– Elcan
8 hours ago
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
add a comment
|
$begingroup$
Looks like it breaks for456975999
, it returnsYYAA999ZZ
, also you need the dashes inbetween the parts :P
$endgroup$
– Elcan
8 hours ago
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
$begingroup$
Looks like it breaks for
456975999
, it returns YYAA999ZZ
, also you need the dashes inbetween the parts :P$endgroup$
– Elcan
8 hours ago
$begingroup$
Looks like it breaks for
456975999
, it returns YYAA999ZZ
, also you need the dashes inbetween the parts :P$endgroup$
– Elcan
8 hours ago
1
1
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
@Elcan Sorry, fixed the issues at a cost of 12 bytes. I have an excuse of being under attack by three cats, for my messing up :P
$endgroup$
– Night2
8 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
$begingroup$
All good, now you have a working answer :P
$endgroup$
– Elcan
7 hours ago
add a comment
|
$begingroup$
Haskell, 85 81 79 77 bytes
([h++'-':n++'-':t|h<-q"AZ",t<-q"AZ",n<-q"099"]!!)
q g=mapM(_->[g!!0..g!!1])g
Try it online!
$endgroup$
add a comment
|
$begingroup$
Haskell, 85 81 79 77 bytes
([h++'-':n++'-':t|h<-q"AZ",t<-q"AZ",n<-q"099"]!!)
q g=mapM(_->[g!!0..g!!1])g
Try it online!
$endgroup$
add a comment
|
$begingroup$
Haskell, 85 81 79 77 bytes
([h++'-':n++'-':t|h<-q"AZ",t<-q"AZ",n<-q"099"]!!)
q g=mapM(_->[g!!0..g!!1])g
Try it online!
$endgroup$
Haskell, 85 81 79 77 bytes
([h++'-':n++'-':t|h<-q"AZ",t<-q"AZ",n<-q"099"]!!)
q g=mapM(_->[g!!0..g!!1])g
Try it online!
edited 6 hours ago
answered 8 hours ago
niminimi
34k3 gold badges27 silver badges91 bronze badges
34k3 gold badges27 silver badges91 bronze badges
add a comment
|
add a comment
|
$begingroup$
Jelly, 28 bytes
ØA,ØDṗ"4,3Œp⁸ịF+2,7¦”-65œ?
A monadic Link accepting an integer (1-indexed) which yields a list of characters... Crazy-slow since it builds all the plates first!
Try it online! (wont complete)
Or try a reduced alphabet version (only "ABC" for the letters).
For code which completes in a timely manner here's a 32 byte full-program (0-indexed):
dȷ+“©L§“£ż’µḢṃØAṙ1¤ḊŒHW€jDḊ€$j”-
Try this one!
$endgroup$
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,€2,4
should be€2,5
.
$endgroup$
– Grimy
6 hours ago
|
show 1 more comment
$begingroup$
Jelly, 28 bytes
ØA,ØDṗ"4,3Œp⁸ịF+2,7¦”-65œ?
A monadic Link accepting an integer (1-indexed) which yields a list of characters... Crazy-slow since it builds all the plates first!
Try it online! (wont complete)
Or try a reduced alphabet version (only "ABC" for the letters).
For code which completes in a timely manner here's a 32 byte full-program (0-indexed):
dȷ+“©L§“£ż’µḢṃØAṙ1¤ḊŒHW€jDḊ€$j”-
Try this one!
$endgroup$
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,€2,4
should be€2,5
.
$endgroup$
– Grimy
6 hours ago
|
show 1 more comment
$begingroup$
Jelly, 28 bytes
ØA,ØDṗ"4,3Œp⁸ịF+2,7¦”-65œ?
A monadic Link accepting an integer (1-indexed) which yields a list of characters... Crazy-slow since it builds all the plates first!
Try it online! (wont complete)
Or try a reduced alphabet version (only "ABC" for the letters).
For code which completes in a timely manner here's a 32 byte full-program (0-indexed):
dȷ+“©L§“£ż’µḢṃØAṙ1¤ḊŒHW€jDḊ€$j”-
Try this one!
$endgroup$
Jelly, 28 bytes
ØA,ØDṗ"4,3Œp⁸ịF+2,7¦”-65œ?
A monadic Link accepting an integer (1-indexed) which yields a list of characters... Crazy-slow since it builds all the plates first!
Try it online! (wont complete)
Or try a reduced alphabet version (only "ABC" for the letters).
For code which completes in a timely manner here's a 32 byte full-program (0-indexed):
dȷ+“©L§“£ż’µḢṃØAṙ1¤ḊŒHW€jDḊ€$j”-
Try this one!
edited 6 hours ago
answered 7 hours ago
Jonathan AllanJonathan Allan
60.6k5 gold badges44 silver badges188 bronze badges
60.6k5 gold badges44 silver badges188 bronze badges
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,€2,4
should be€2,5
.
$endgroup$
– Grimy
6 hours ago
|
show 1 more comment
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,€2,4
should be€2,5
.
$endgroup$
– Grimy
6 hours ago
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
$begingroup$
Misses the dashes it seems, so for now it doesn't fit the challenge's rules :P
$endgroup$
– Elcan
7 hours ago
1
1
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Ah, I completely ignored them as some kind of separator! Makes quite a difference for these methods :(
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Sorry about that :c Still pretty nice to see it done in Jelly, even without !
$endgroup$
– Elcan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
Added 7 byes to add them in, pretty sure there is a shorter overall method now...
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
You got the dashes wrong,
€2,4
should be €2,5
.$endgroup$
– Grimy
6 hours ago
$begingroup$
You got the dashes wrong,
€2,4
should be €2,5
.$endgroup$
– Grimy
6 hours ago
|
show 1 more comment
$begingroup$
Pure Bash (no external utils), 66
f=({A..Z}{A..Z}-%03d-{A..Z}{A..Z})
printf ${f[$1/1000]} $[$1%1000]
Try it online! - takes about 10s to run over the 7 testcases.
- Line #1 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.
- Line #2 indexes the array to get the appropriate format string and takes the digits portion as its parameter.
$endgroup$
add a comment
|
$begingroup$
Pure Bash (no external utils), 66
f=({A..Z}{A..Z}-%03d-{A..Z}{A..Z})
printf ${f[$1/1000]} $[$1%1000]
Try it online! - takes about 10s to run over the 7 testcases.
- Line #1 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.
- Line #2 indexes the array to get the appropriate format string and takes the digits portion as its parameter.
$endgroup$
add a comment
|
$begingroup$
Pure Bash (no external utils), 66
f=({A..Z}{A..Z}-%03d-{A..Z}{A..Z})
printf ${f[$1/1000]} $[$1%1000]
Try it online! - takes about 10s to run over the 7 testcases.
- Line #1 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.
- Line #2 indexes the array to get the appropriate format string and takes the digits portion as its parameter.
$endgroup$
Pure Bash (no external utils), 66
f=({A..Z}{A..Z}-%03d-{A..Z}{A..Z})
printf ${f[$1/1000]} $[$1%1000]
Try it online! - takes about 10s to run over the 7 testcases.
- Line #1 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.
- Line #2 indexes the array to get the appropriate format string and takes the digits portion as its parameter.
edited 5 hours ago
answered 5 hours ago
Digital TraumaDigital Trauma
60.5k7 gold badges92 silver badges227 bronze badges
60.5k7 gold badges92 silver badges227 bronze badges
add a comment
|
add a comment
|
$begingroup$
Charcoal, 33 bytes
Nθ¹✂I⁺θφ±³≔⪪⍘⁺X²⁶¦⁵÷θφα²η¹⊟ηM⁹←⊟η
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the number.
¹
Print a -
.
✂I⁺θφ±³
Add 1000 to the number, then cast the result to string, and print the last three digits.
≔⪪⍘⁺X²⁶¦⁵÷θφα²η
Divide the number by 1000, then add 26⁵, so the conversion to custom base using the uppercase alphabet results in a string of length 6, which is then split into pairs of letters.
¹
Print a -
.
⊟η
Print the last pair of letters.
M⁹←
Move to the beginning of the number plate.
⊟η
Print the rest of the desired letters.
$endgroup$
add a comment
|
$begingroup$
Charcoal, 33 bytes
Nθ¹✂I⁺θφ±³≔⪪⍘⁺X²⁶¦⁵÷θφα²η¹⊟ηM⁹←⊟η
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the number.
¹
Print a -
.
✂I⁺θφ±³
Add 1000 to the number, then cast the result to string, and print the last three digits.
≔⪪⍘⁺X²⁶¦⁵÷θφα²η
Divide the number by 1000, then add 26⁵, so the conversion to custom base using the uppercase alphabet results in a string of length 6, which is then split into pairs of letters.
¹
Print a -
.
⊟η
Print the last pair of letters.
M⁹←
Move to the beginning of the number plate.
⊟η
Print the rest of the desired letters.
$endgroup$
add a comment
|
$begingroup$
Charcoal, 33 bytes
Nθ¹✂I⁺θφ±³≔⪪⍘⁺X²⁶¦⁵÷θφα²η¹⊟ηM⁹←⊟η
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the number.
¹
Print a -
.
✂I⁺θφ±³
Add 1000 to the number, then cast the result to string, and print the last three digits.
≔⪪⍘⁺X²⁶¦⁵÷θφα²η
Divide the number by 1000, then add 26⁵, so the conversion to custom base using the uppercase alphabet results in a string of length 6, which is then split into pairs of letters.
¹
Print a -
.
⊟η
Print the last pair of letters.
M⁹←
Move to the beginning of the number plate.
⊟η
Print the rest of the desired letters.
$endgroup$
Charcoal, 33 bytes
Nθ¹✂I⁺θφ±³≔⪪⍘⁺X²⁶¦⁵÷θφα²η¹⊟ηM⁹←⊟η
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the number.
¹
Print a -
.
✂I⁺θφ±³
Add 1000 to the number, then cast the result to string, and print the last three digits.
≔⪪⍘⁺X²⁶¦⁵÷θφα²η
Divide the number by 1000, then add 26⁵, so the conversion to custom base using the uppercase alphabet results in a string of length 6, which is then split into pairs of letters.
¹
Print a -
.
⊟η
Print the last pair of letters.
M⁹←
Move to the beginning of the number plate.
⊟η
Print the rest of the desired letters.
answered 8 hours ago
NeilNeil
89.3k8 gold badges46 silver badges188 bronze badges
89.3k8 gold badges46 silver badges188 bronze badges
add a comment
|
add a comment
|
$begingroup$
Python 2, 88 bytes
lambda n:g(n/676000)+'-%03d-'%(n%1000)+g(n/1000)
g=lambda n:chr(65+n/26%26)+chr(65+n%26)
Try it online!
$endgroup$
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 2, 88 bytes
lambda n:g(n/676000)+'-%03d-'%(n%1000)+g(n/1000)
g=lambda n:chr(65+n/26%26)+chr(65+n%26)
Try it online!
$endgroup$
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 2, 88 bytes
lambda n:g(n/676000)+'-%03d-'%(n%1000)+g(n/1000)
g=lambda n:chr(65+n/26%26)+chr(65+n%26)
Try it online!
$endgroup$
Python 2, 88 bytes
lambda n:g(n/676000)+'-%03d-'%(n%1000)+g(n/1000)
g=lambda n:chr(65+n/26%26)+chr(65+n%26)
Try it online!
answered 7 hours ago
Chas BrownChas Brown
6,7491 gold badge6 silver badges27 bronze badges
6,7491 gold badge6 silver badges27 bronze badges
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
$begingroup$
The save by mypetition under my answer can be applied for Python 2, too
$endgroup$
– Black Owl Kai
5 hours ago
add a comment
|
$begingroup$
Python 3, 89 bytes
lambda n:h(n//676)+f"-{n%1000:03}-"+h(n)
h=lambda x:'%c%c'%(x//26000%26+65,x//1000%26+65)
Try it online!
-1 byte thanks to mypetition
$endgroup$
$begingroup$
Changechr(x//26000%26+65)+chr(x//1000%26+65)
to'%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.
$endgroup$
– mypetlion
7 hours ago
add a comment
|
$begingroup$
Python 3, 89 bytes
lambda n:h(n//676)+f"-{n%1000:03}-"+h(n)
h=lambda x:'%c%c'%(x//26000%26+65,x//1000%26+65)
Try it online!
-1 byte thanks to mypetition
$endgroup$
$begingroup$
Changechr(x//26000%26+65)+chr(x//1000%26+65)
to'%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.
$endgroup$
– mypetlion
7 hours ago
add a comment
|
$begingroup$
Python 3, 89 bytes
lambda n:h(n//676)+f"-{n%1000:03}-"+h(n)
h=lambda x:'%c%c'%(x//26000%26+65,x//1000%26+65)
Try it online!
-1 byte thanks to mypetition
$endgroup$
Python 3, 89 bytes
lambda n:h(n//676)+f"-{n%1000:03}-"+h(n)
h=lambda x:'%c%c'%(x//26000%26+65,x//1000%26+65)
Try it online!
-1 byte thanks to mypetition
edited 5 hours ago
answered 8 hours ago
Black Owl KaiBlack Owl Kai
7301 silver badge12 bronze badges
7301 silver badge12 bronze badges
$begingroup$
Changechr(x//26000%26+65)+chr(x//1000%26+65)
to'%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.
$endgroup$
– mypetlion
7 hours ago
add a comment
|
$begingroup$
Changechr(x//26000%26+65)+chr(x//1000%26+65)
to'%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.
$endgroup$
– mypetlion
7 hours ago
$begingroup$
Change
chr(x//26000%26+65)+chr(x//1000%26+65)
to '%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.$endgroup$
– mypetlion
7 hours ago
$begingroup$
Change
chr(x//26000%26+65)+chr(x//1000%26+65)
to '%c%c'%(x//26000%26+65,x//1000%26+65)
to save 1 byte.$endgroup$
– mypetlion
7 hours ago
add a comment
|
$begingroup$
J, 56 49 bytes
226950 A.'--',7{._3|.[:,a.{~65 48+/(4 3#26 10)#:]
Try it online!
The whole thing is nothing but 8 nested trains -- if that ain't fun, what is?
┌─ 226950
├─ A.
│ ┌─ '--'
──┤ ├─ ,
│ │ ┌─ 7
└────────┤ ├─ {.
│ │ ┌─ _3
└──────┤ ├─ |.
│ │ ┌─ [:
└────┤ ├─ ,
│ │ ┌─ 'abc...'
└────┤ ├─ ~ ──────── {
│ │
└────┤ ┌─ 65 48
│ ├─ / ───── +
└──────────┤
│ ┌─ '4 3#26 10'
└───────┼─ #:
└─ ]
$endgroup$
add a comment
|
$begingroup$
J, 56 49 bytes
226950 A.'--',7{._3|.[:,a.{~65 48+/(4 3#26 10)#:]
Try it online!
The whole thing is nothing but 8 nested trains -- if that ain't fun, what is?
┌─ 226950
├─ A.
│ ┌─ '--'
──┤ ├─ ,
│ │ ┌─ 7
└────────┤ ├─ {.
│ │ ┌─ _3
└──────┤ ├─ |.
│ │ ┌─ [:
└────┤ ├─ ,
│ │ ┌─ 'abc...'
└────┤ ├─ ~ ──────── {
│ │
└────┤ ┌─ 65 48
│ ├─ / ───── +
└──────────┤
│ ┌─ '4 3#26 10'
└───────┼─ #:
└─ ]
$endgroup$
add a comment
|
$begingroup$
J, 56 49 bytes
226950 A.'--',7{._3|.[:,a.{~65 48+/(4 3#26 10)#:]
Try it online!
The whole thing is nothing but 8 nested trains -- if that ain't fun, what is?
┌─ 226950
├─ A.
│ ┌─ '--'
──┤ ├─ ,
│ │ ┌─ 7
└────────┤ ├─ {.
│ │ ┌─ _3
└──────┤ ├─ |.
│ │ ┌─ [:
└────┤ ├─ ,
│ │ ┌─ 'abc...'
└────┤ ├─ ~ ──────── {
│ │
└────┤ ┌─ 65 48
│ ├─ / ───── +
└──────────┤
│ ┌─ '4 3#26 10'
└───────┼─ #:
└─ ]
$endgroup$
J, 56 49 bytes
226950 A.'--',7{._3|.[:,a.{~65 48+/(4 3#26 10)#:]
Try it online!
The whole thing is nothing but 8 nested trains -- if that ain't fun, what is?
┌─ 226950
├─ A.
│ ┌─ '--'
──┤ ├─ ,
│ │ ┌─ 7
└────────┤ ├─ {.
│ │ ┌─ _3
└──────┤ ├─ |.
│ │ ┌─ [:
└────┤ ├─ ,
│ │ ┌─ 'abc...'
└────┤ ├─ ~ ──────── {
│ │
└────┤ ┌─ 65 48
│ ├─ / ───── +
└──────────┤
│ ┌─ '4 3#26 10'
└───────┼─ #:
└─ ]
edited 8 mins ago
answered 4 hours ago
JonahJonah
5,0972 gold badges13 silver badges23 bronze badges
5,0972 gold badges13 silver badges23 bronze badges
add a comment
|
add a comment
|
$begingroup$
Clean, 107 bytes
import StdEnv
A=['A'..'Z']
N=['0'..'9']
$n=[[a,b,'-',x,y,z,'-',c,d]\a<-A,b<-A,c<-A,d<-A,x<-N,y<-N,z<-N]!!n
Try it online!
Defines $ :: Int -> [Char]
giving the n-th zero-indexed licence plate.
$endgroup$
add a comment
|
$begingroup$
Clean, 107 bytes
import StdEnv
A=['A'..'Z']
N=['0'..'9']
$n=[[a,b,'-',x,y,z,'-',c,d]\a<-A,b<-A,c<-A,d<-A,x<-N,y<-N,z<-N]!!n
Try it online!
Defines $ :: Int -> [Char]
giving the n-th zero-indexed licence plate.
$endgroup$
add a comment
|
$begingroup$
Clean, 107 bytes
import StdEnv
A=['A'..'Z']
N=['0'..'9']
$n=[[a,b,'-',x,y,z,'-',c,d]\a<-A,b<-A,c<-A,d<-A,x<-N,y<-N,z<-N]!!n
Try it online!
Defines $ :: Int -> [Char]
giving the n-th zero-indexed licence plate.
$endgroup$
Clean, 107 bytes
import StdEnv
A=['A'..'Z']
N=['0'..'9']
$n=[[a,b,'-',x,y,z,'-',c,d]\a<-A,b<-A,c<-A,d<-A,x<-N,y<-N,z<-N]!!n
Try it online!
Defines $ :: Int -> [Char]
giving the n-th zero-indexed licence plate.
answered 4 hours ago
ΟurousΟurous
7,6061 gold badge11 silver badges36 bronze badges
7,6061 gold badge11 silver badges36 bronze badges
add a comment
|
add a comment
|
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f193432%2ffrench-license-plates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown