DEV Community

Discussion on: Daily Challenge #282 - Car License Plate Calculator

Collapse
 
bubbler4 profile image
Bubbler

APL (using Dyalog APL):

findPlate←{
  ⎕IO←0
  values←26 26 26 999⊤⍵
  (alpha digit)←(3↑values)(⊢/values)
  (⎕UCS 97+⌽alpha),⎕D[(3⍴10)⊤1+digit]
}

(Use the bookmarklet on this post to see the code with APL font and syntax highlighting.)

Demo can be found here.

Explanation:

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]
}