I don’t get it, ZO-OOO-OO isn’t valid (the middle part are numbers, not letters), but it goes above ZO-001-AA.
However the number comfortably fits in a 32bit signed int, so it is far away from JavaScript rounding errors.
I have some trouble with this puzzle. Passing all tests except the big one:
my code answers : JQ-027-YY instead of JQ-027-XY… I don’t understand how an error can appear just for 1 letter and not for others
[SOLVED]
Hi
For info, letter I and O are not present on FR plates… (too much confusing with 1 and Q)
Could be an optional challenge…
O, I and U are excluded of the french plates, they can be confused with 0, 1 and V. Moreover, SS is removed too because of the nazi organisation.
All my tests validate and works. however only get 85% completed as 1.000.000 mill I rejected
Same for me, stuck at 85% because of it. My guess is the validator lands on an edge case that none of the tests do not, e.g. ZZ->AA transition or 999->001. But it’s always tough to debug those, naturally.
*Edited: Solved it by iterating plate by plate. 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.
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?