PHP, 1044 800 757 bytes
The script is added to a PHAR (PHP archive) and compressed with gzip to shrink it from 1044 to 800 bytes. Further optimization took the original code down to 994 bytes, which then as a Phar is 757 bytes. Takes the license plate string as the first argument like php u.phar BD51 SMR
(actually the latter part is read as "second argument", but useless garbage anyway for this challenge).
Download the uklic.phar file for this answer
This is the script before compression:
<?$o=[X=>'Personal export',B=>Birmingham,E=>Chelmsford,M=>Manchester,O=>Oxford,R=>Reading,V=>Worcester,A=>['A-N'=>Peterborough,'O-U'=>Norwich,'V-Y'=>Ipswich],C=>['A-O'=>Cardiff,'P-V'=>Swansea,WXY=>Bangor],D=>['A-K'=>Chester,'L-Y'=>Shrewsbury],F=>['A-P'=>Nottingham,'R-Y'=>Lincoln],G=>['A-O'=>Maidstone,'P-Y'=>Brighton],H=>['A-J'=>Bournemouth,'K-Y'=>Portsmouth,W=>'Isle of Wight'],K=>['A-L'=>Borehamwood,'M-Y'=>Northampton],L=>['A-J'=>Wimbledon,'K-T'=>Borehamwood,'U-Y'=>Sidcup],N=>['A-O'=>Newcastle,'P-Y'=>Stockton],P=>['A-T'=>Preston,'U-Y'=>Carlisle],S=>['A-J'=>Glasgow,'K-O'=>Edinburgh,'P-T'=>Dundee,UVW=>Aberdeen,XY=>Inverness],W=>['A-J'=>Exeter,KL=>Truro,'M-Y'=>Bristol],Y=>['A-K'=>Leeds,'L-U'=>Sheffield,'V-Y'=>Beverley]];$p=$argv[1];$a=$o[$p{0}];$z=$a;if(count($a)>1){foreach($a as$r=>$d){if(preg_match("/[$r]/",$p{1})){$z=$d;}}}$n=$p{2}.$p{3};$y=$n+($n==Y);if($y==0)$y=50;$h=$y&&$n<51;$y%=50;$x=$y+1;printf('%s, 1/%s/20%02d to %s/20%02d',$z,$h?3:9,$y,$h?'31/8':28+!($x%4).'/2',$h?$y:$x);
The DVLA Office lookup is a simple map with a string if the first character of the license plate is enough to identify the office and an array if we need the second character. The character range is then matched with a simple regexp.
The code for the date range is quite easy except for the two edge cases "Y" and "00", which can't be calculated. Y is cast to integer and added a 1, in case the input is an integer. That's how we get 2001 for Y. 00 is accounted for by modulo arithmetic.
This is the slightly better readable version:
<?
$o = [
X => 'Personal export',
B => Birmingham,
E => Chelmsford,
M => Manchester,
O => Oxford,
R => Reading,
V => Worcester,
A => ['A-N' => Peterborough, 'O-U' => Norwich, 'V-Y' => Ipswich],
C => ['A-O' => Cardiff, 'P-V' => Swansea, WXY => Bangor],
D => ['A-K' => Chester, 'L-Y' => Shrewsbury],
F => ['A-P' => Nottingham, 'R-Y' => Lincoln],
G => ['A-O' => Maidstone, 'P-Y' => Brighton],
H => ['A-J' => Bournemouth, 'K-Y' => Portsmouth, W => 'Isle of Wight'],
K => ['A-L' => Borehamwood, 'M-Y' => Northampton],
L => ['A-J' => Wimbledon, 'K-T' => Borehamwood, 'U-Y' => Sidcup],
N => ['A-O' => Newcastle, 'P-Y' => Stockton],
P => ['A-T' => Preston, 'U-Y' => Carlisle],
S => ['A-J' => Glasgow, 'K-O' => Edinburgh, 'P-T' => Dundee, UVW => Aberdeen, XY => Inverness],
W => ['A-J' => Exeter, 'KL' => Truro, 'M-Y' => Bristol],
Y => ['A-K' => Leeds, 'L-U' => Sheffield, 'V-Y' => Beverley]
];
$p=$argv[1];
$a=$o[$p{0}];
$z=$a;
if (count($a)-1) {
foreach($a as $r => $d) {
if (preg_match('/['.$r.']/', $p{1})) {$z=$d; }
}
}
$n=$p{2}.$p{3};
$y=$n+($n==Y);
if ($y==0) {
$y=50;
}
$h=$y&&$n<51;
$y%=50;
$x=$y+1;
printf('%s, 1/%s/20%02d to %s/20%02d',$z,$h?3:9,$y,$h?'31/8':28+!($x%4).'/2',$h?$y:$x);
Updates:
- Seriously trimmed down the date calculation section and made use of printf, replaced
is_array($a)
with `count($a)>1
- Optimized the Phar bootstrapping
Are we allowed to fetch online data? – R. Kap – 2016-08-19T23:15:25.600
@R.Kap No, you should not – Beta Decay – 2016-08-19T23:31:58.127
The output for BD51 ANY should read
Birmingham, 1/9/2001 to 28/2/2002
, I think you meant BD61 for leap year demo purposes? – YetiCGN – 2016-08-26T15:31:08.783Not quite Area 51... – mbomb007 – 2016-08-26T15:51:53.633
1One side effect of this challenge: Every time I see a car or motorcycle with GB plates, I try to decode them in my head. :-) – YetiCGN – 2016-08-29T15:46:33.680