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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.