letters='abcdefghijklmnopqrstuvwxyz'deffind_the_number_plate(n):# As serial numbers go from 001 to 999, we take n % 999 and convert it to a 0 padded string
ser=str(n%999+1).rjust(3,'0')# To find the letters, we need to divide by 999 and then repeatedly divide by 26 to get the 3 letters
l=n//999returnletters[l%26]+letters[(l//26)%26]+letters[(l//(26*26))%26]+ser
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
In JS with toString and a custom radix ended up being pretty damn unwieldy...
const// adding aMinusZero to a charCode converts a digit to a// lowercase letter (i.e. 0 -> 'a')aMinusZero='a'.charCodeAt(0)-'0'.charCodeAt(0),// radix26ToLatin converts the given character from// radix 26 (0-9, a-p) to a letter(a-z)radix26ToLatin=c=>String.fromCharCode(c.charCodeAt(0)+(c.charCodeAt(0)<'a'.charCodeAt(0)?aMinusZero:10)),// numberToLatin converts a number to its a-z representationnumberToLatin=i=>Number(i).toString(26).replace(/./g,radix26ToLatin),// plateNumberForCustomerId wraps things up with an// uncomfortably complicated bow 🤷♂️plateNumberForCustomerId=id=>[...numberToLatin(Math.floor(id/999)).padStart(3,'a')].reverse().join('')+String((id%999)+1).padStart(3,0);
I thought to use Elixir since it has built-in base conversion (and not just for the usual powers of two suspects like octal and hex), but theirs assumes the digit sequence is 0..9A..Z, so there is still an impedance mismatch to a..z encoding, and the need (apparently) to bludgeon one's way through the edge cases, particularly 'magic constants' based on knowledge of the ASCII character set.
defmoduleFindPlatedo@doc"""
Generate a number plate from a customer_id
"""@specfind_plate(Integer.t())::String.t()deffind_plate(customer_id)do{mst,digits}=(customer_id+26*26*26*1000)# kludge|>Integer.to_charlist|>Enum.split(-3)mst=if(mst==[],do:'0',else:mst)# kludge{_,letters}=mst|>List.to_integer|>Integer.to_charlist(26)|>Enum.map(fnc->if(c<=?9,do:c+?a-?0,else:c+42)end)|>Enum.split(-3)# counterkludgeletters++digitsendend
findPlate←{
⍝ Set 0-based indexing for ⎕D later
⎕IO←0
⍝ Mixed base decomposition for 999 numbers and
⍝ three alpha places
values←26 26 26 999⊤⍵
⍝ Extract alphabet part and number part
(alpha digit)←(3↑values)(⊢/values)
⍝ Extract three digits of number, index into
⍝ ⎕D ('0123456789'), and concatenate to
⍝ reversed alphabet part (using Unicode codepoint)
(⎕UCS 97+⌽alpha),⎕D[(3⍴10)⊤1+digit]
}
Seems to be working -
letters = 'abcdefghijklmnopqrstuvwxyz'
def find_the_number_plate(n):
# As serial numbers go from 001 to 999, we take n % 999 and convert it to a 0 padded string
ser = str(n%999 + 1).rjust(3, '0')
# To find the letters, we need to divide by 999 and then repeatedly divide by 26 to get the 3 letters
l = n//999
return letters[l%26]+letters[(l//26)%26]+letters[(l//(26*26))%26] + ser
License plate calculations are an interesting programming challenge because they involve understanding registration formats, number sequences, and regional identification systems. Different regions often follow their own plate formats and rules, so knowing how to interpret these details can be useful for vehicle owners. Exploring regional registration systems also gives a better understanding of how plate identification works in different areas.
Daily Challenge #282 – Car License Plate Calculator aligns naturally with an LTO Tracker by turning plate number logic into a practical, everyday tool for motorists. A license plate calculator can help users determine coding days, renewal schedules, or plate-based restrictions, while an LTO tracker extends this functionality by monitoring vehicle registration status, license validity, and compliance updates in one place.
The problem statement contradicts itself.
First it says that "Number Plate aaa000 is related to Customer ID 0; Number Plate aaa001 is related to Customer ID 1, and so on."
Then it says "The serial numbers start at 001, end at 999", and goes on to show lists of plates with serial numbers in the format xxx001..xxx999.
Together, they mean that number plate aaa000 both does and does not exist.
With the use UTF-8 table
Lowercase alphabet position 97-122
For the 'abz099' Result:
And add 99
Here is the simple solution with Python to create mapping letter lists to complete this challenge :).
In JS with
toStringand a custom radix ended up being pretty damn unwieldy...Testn...
seems to agree with the kata test cases
Advantage: avoids hardcoding the number of letters and digits (they could be brought out as params easily)
Disadvantages: all the other things
I thought to use Elixir since it has built-in base conversion (and not just for the usual powers of two suspects like octal and hex), but theirs assumes the digit sequence is 0..9A..Z, so there is still an impedance mismatch to a..z encoding, and the need (apparently) to bludgeon one's way through the edge cases, particularly 'magic constants' based on knowledge of the ASCII character set.
APL (using Dyalog APL):
(Use the bookmarklet on this post to see the code with APL font and syntax highlighting.)
Demo can be found here.
Explanation:
Seems to be working -
letters = 'abcdefghijklmnopqrstuvwxyz'
def find_the_number_plate(n):
# As serial numbers go from 001 to 999, we take n % 999 and convert it to a 0 padded string
ser = str(n%999 + 1).rjust(3, '0')
# To find the letters, we need to divide by 999 and then repeatedly divide by 26 to get the 3 letters
l = n//999
return letters[l%26]+letters[(l//26)%26]+letters[(l//(26*26))%26] + ser
License plate calculations are an interesting programming challenge because they involve understanding registration formats, number sequences, and regional identification systems. Different regions often follow their own plate formats and rules, so knowing how to interpret these details can be useful for vehicle owners. Exploring regional registration systems also gives a better understanding of how plate identification works in different areas.
Daily Challenge #282 – Car License Plate Calculator aligns naturally with an LTO Tracker by turning plate number logic into a practical, everyday tool for motorists. A license plate calculator can help users determine coding days, renewal schedules, or plate-based restrictions, while an LTO tracker extends this functionality by monitoring vehicle registration status, license validity, and compliance updates in one place.
hmmm