all you have to use is modulo
For French plates: the letters I, O and U are not present. A special format exists also for the garages/car dealers/automotive professionals with āW Garageā format like āW-001-AAā. WW is also a special format for temporary license plate valid up to 4 months (like WW-001-AA). SS is removed also (left and right side).
Some elements here: https://plaques-immatriculation.info
I pass all the tests before submitting, but after submitting I get a fail on test case 6. I read the forums here on why that happens. But even after reading that I donāt know why my code fails. Any chance someone can view my code and give their opinion on the matter?
I know my code isnāt the cleanest yet, I am still getting acquainted with things.
Ok, solved the problem. User Last Rick said it best in his post thatās in this thread, just search his name. His hint āBest hint I can give is consider the edge case where ācarrying the 1ā trickles all the way from the middle to the right to the left side.ā, You have to cover those cases where something starts out as ZZ, or 999. Also, use modulo
AA-998-AA
1
I was able to write code that passed all the test cases and passed all the validators. As I thought about it, my code could not pass the test case above. Iād like to suggest adding the above test case to make sure the mistake I made is caught.
Both of my solutions are published.
I added a test and a validator for this case.
I apparently did the same mistake and fixed it ā¦and I tested some published solutions containing the same mistake too .
It would have been easier actually if this rule had been included in this challenge, because incrementing plate number step by step is easier (but unfortunately it causes timeout for āvery bigā testcase).
No, for me itās easier to think mathematically (ie to find a bijection between the set of licence plates and the set of integers).
There is a small mistake in the problem statement, the ordering presented is not alphabetical :
console.log('AA-001-AA' < 'AA-001-AB', 'AA-001-AB' < 'AA-002-AA'); // true true
I canāt seem to see my mathematical error, can someone help me out (for the 1,000,000 and Big test cases)[code is written in c#]:
Spoiler Alert
class Solution
{
//1 9
//10 99
//100 999
//1000 999A
//26000 999AA
//676000 999AAA
//17576000 999AAAA
static int convertToNumber(string Entry){
int Converted = 0;
//Console.Error.WriteLine("debug: converting from string: {0}", Entry);
Converted += (int)(Entry[5] - '0');
Converted += (int)(Entry[4] - '0')*10;
Converted += (int)(Entry[3] - '0')*100;
Converted += (int)(Entry[8] - 'A')*1000;
Converted += (int)(Entry[7] - 'A')*26000;
Converted += (int)(Entry[1] - 'A')*676000;
Converted += (int)(Entry[0] - 'A')*17576000;
//Console.Error.WriteLine("debug: converted to number: {0}", Converted);
return Converted;
}
static string convertToString(int Value){
List<char> Converted = new List<char>();
string Output = "";
//Console.Error.WriteLine("debug: converting from number: {0}", Value);
Converted.Add((char)((Value %10) + '0'));
Converted.Add((char)(((Value / 10) %10) + '0'));
Converted.Add((char)(((Value / 100) %10) + '0'));
Converted.Add((char)(((Value / 1000) %26) + 'A'));
Converted.Add((char)(((Value / 26000) %26) + 'A'));
Converted.Add((char)(((Value / 676000) %26) + 'A'));
Converted.Add((char)(((Value / 17576000) %26) + 'A'));
//Console.Error.Write("debug: converted to string(0): ");
foreach( char c in Converted){
// Console.Error.Write("{0} ",c);
}
//Console.Error.WriteLine("");
Output += Converted[6];
Output += Converted[5];
Output += '-';
Output += Converted[2];
Output += Converted[1];
if ( Converted[0] == '0' && Converted[1] == '0' && Converted[2] == '0' )
Output += '1';
else
Output += Converted[0];
Output += '-';
Output += Converted[4];
Output += Converted[3];
return Output;
}
static void Main(string[] args)
{
string x = Console.ReadLine();
int n = int.Parse(Console.ReadLine());
Console.Error.WriteLine("debug: starting license: {0} number to iterate: {1}", x, n );
int Converted = convertToNumber(x);
Converted = Converted + n + (n/1000);
string final = convertToString(Converted);
// Write an answer using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
Console.WriteLine(final);
}
}
Your code produces the correct answer for:
AA-001-AA
674325
but not for
AA-001-AA
674326
You may investigate from there.
By the way you may format your code properly by using the </> button on the formatting toolbar.
I guess I donāt understand. I think youāre talking about the wrap from 999 to 000 that occurs every thousand, and I account for that with the ā+ (n/1000)ā statement. Iāve been looking at out of sequence or for a triplicate that occurs and I cannot seem to locate it. I ran the numbers you suggested in my console app without a starting license and my returns are:
debug: From License: QS-456-DF To License: QT-780-DD From Number: 294141780
debug: Without Starting License: AA-324-ZY From Number: 674324
debug: From License: QS-456-DF To License: QT-781-DD From Number: 294141781
debug: Without Starting License: AA-325-ZY From Number: 674325
debug: From License: QS-456-DF To License: QT-782-DD From Number: 294141782
debug: Without Starting License: AA-326-ZY From Number: 674326
I appreciate your suggestions, and Iāll try to remember to use the ā</>ā button
Additionally Iāve written this to see if there is an easy to spot sequence issue:
Potential Spoiler
int converted = convertToNumber(x);
List<int> rows = new List<int>();
for (int i = 0; i < 1000000; i++)
{
int sequence = Convert.ToInt32(convertToString(i+converted).Substring(3, 3));
rows.Add(sequence);
//Console.WriteLine("debug: From License: {0} To License: {1} From Number: {2}", x, convertToString(i + converted), i + converted);
//Console.WriteLine("debug: Without Starting License: {1} From Number: {2}", x, convertToString(i), i);
}
for (int i = 2; i < rows.Count; i++)
{
if (rows[i] == rows[i - 1] && rows[i] == rows[i - 2])
{
Console.WriteLine("found triple at: {0} value: {1}", i, rows[i]);
}
if (rows[i] == rows[i - 1] && rows[i] != 1)
{
Console.WriteLine("found out of sequence duplicate at: {0} value: {1}", i, rows[i]);
}
if (rows[i] != (rows[i - 1] + 1) && rows[i - 1] != 1 && rows[i - 1] != 999)
{
Console.WriteLine("found out of sequence at: {0} value: {1}", i, rows[i]);
}
//Console.WriteLine("Value: {0} at Row: {1}", rows[i], i);
}
Your code produces the same output to the two cases in my last comment, doesnāt it?
No it doesnāt I can pass all the tests and validators, but Iām doing something hacky; my value is off somewhere around every 984880 licensesā¦ I donāt know if itās a boundary issue (with my math) or missing some detail. So I added the line to my code to simply pass; but Iād like to know what I did wrong that the math didnāt work with simply accounting for the 1/1000 records. 2nd question, is there no one else anymore that does these puzzles but me (am I on my own internet with bots or something)?
Potential Spoiler
Converted + n + (n/1000) + (n/984880);
Either you misread/misunderstand something or youāve changed your code; Iāve no idea why you say your code doesnāt produce the same output for the two cases. See the screenshots below:
Look more closely to how the description examples wrap..
AB-000-AA is not in the example listing as it is not a valid plate
[Editted]
I didnāt understand that you tested by inputting specific test cases, Iāve never done that or thought of doing that. I was testing using my console app with specific input looking for specific output. I didnāt see that you had an expected value for the output either of AA-001-ZZ. Thank you for clarifying by using screen shots 5DN1L!
[Also, Iām not allowed to write custom test cases or at least thereās no visible option for me to do it]
Thank you for looking at this
Indeed, you seemingly compensate for a wrong internal value during the toString process.
My point is that your numbers donāt wrap every 1000 values; they wrap every 999 values. So Iām wondering whether your mathematical compensation isnāt off because youāre using an off-by-one value for wrapping compensation.