[Question]
  [
Until [decimalization in 1971](http://en.wikipedia.org/wiki/Decimal_Day), British money was based on dividing the [pound](http://en.wikipedia.org/wiki/Pound_sterling) into 240 pennies. A shilling was 12 pennies so 20 shillings made a pound. The smallest denomination was the farthing at one fourth of a penny. There were many other denominations and nicknames for coins, [which can get quite confusing](http://resources.woodlands-junior.kent.sch.uk/customs/questions/moneyold.htm) if you're not used to the system.
# Challenge
Write a program or function that can convert (almost) any denomination of old English money to any other. To make it easier for the user you need to support plurals and nicknames.
These are the denominations and their synonymous terms you must support. For convenience their value in farthings leads each line.
```
1: farthing, farthings
2: halfpence, halfpenny, halfpennies
4: penny, pennies, pence, copper, coppers
8: twopenny, twopennies, twopence, tuppence, half groat, half groats
12: threepence, threepenny, threepennies, threepenny bit, threepenny bits, thruppence, thrupenny, thrupennies, thrupenny bit, thrupenny bits
16: groat, groats
24: sixpence, sixpenny, sixpennies, sixpenny bit, sixpenny bits, tanner, tanners
48: shilling, shillings, bob
96: florin, florins, two bob bit, two bob bits
120: half crown, half crowns
240: crown, crowns
480: half sovereign, half sovereigns
504: half guinea, half guineas
960: pound, pounds, pounds sterling, sovereign, sovereigns, quid, quids
1008: guinea, guineas
```
(I am not British, this list is by no means authoritative but it will suffice for the challenge.)
Via stdin or function argument you should take in a string of the form
```
[value to convert] [denomination 1] in [denomination 2]
```
and return or print
```
[value to convert] [denomination 1] is [converted value] [denomination 2]
```
where `[converted value]` is `[value to convert]` units of denomination 1 converted to denomination 2.
The `[value to convert]` and `[converted value]` are positive floats. In the output both should be rounded or truncated to 4 decimal places. If desired you may assume `[value to convert]` always has a decimal point and zero when input (e.g. `1.0` instead of `1`).
Denominations 1 and 2 may be any two terms from the list above. Don't worry about whether they're plural or not, treat all denominations and synonyms the same. You may assume the input format and denominations are always valid.
# Examples
`1 pounds in shilling` → `1 pounds is 20 shilling`  
(`1.0000 pounds is 20.0000 shilling` would be fine)
`0.6 tuppence in tanner` → `0.6 tuppence is 0.2 tanner`
`24 two bob bits in pounds sterling` → `24 two bob bits is 2.4 pounds sterling`
`144 threepennies in guineas` → `144 threepennies is 1.7143 guineas`
# Scoring
The shortest code [in bytes](https://mothereff.in/byte-counter) wins.
  
[Answer]
## Ruby, ~~345~~ ~~306~~ ~~302~~ ~~288~~ ~~287~~ ~~278~~ ~~273~~ ~~253~~ ~~252~~ ~~242~~ ~~232~~ ~~221~~ ~~202~~ 190 bytes
```
f=->s{" !#+/7OďǿȗϟЏ'"[%w{fa fp ^pe|co r..p ^gr x|ta sh|^b fl|b f.c ^c f.s .gu d|v ^g .}.index{|k|s[/#{k}/]}].ord-31}
$><<gets.sub(/ (.+ i)n /){" #{r=$1}s %0.4f ".%$`.to_f/f[$']*f[r]}
```
Takes input from STDIN and prints to STDOUT.
I'm using short regular expressions to match only the desired denominations for each value. There are two arrays, one with regexes and one with values, at corresponding indices. The regex array is a space delimited array literal, and the value array is packed into a string of UTF-8 characters.
I'm selecting the index into the values by searching for a regex that matches each denomination. I'm also defaulting to the tuppence/half-groat case (value 8), because that required the longest regex. Likewise, some of the patterns assume that other values have already been matched by earlier patterns, so each regex only distinguishes the desired value only from the remaining ones. Using this, I could probably shave off another couple of bytes by rearranging the order of the denominations.
Thanks to Ventero for helping me ~~beat Pyth~~ making it shorter!
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 146 145
```
K4J24L?*y>b-5>b\t?2>b\t.5}<b2"hatw"@[1K8K12K16J48J1008*JT96*2J960)xc"fapetucothengrsishtagucrflbo"2<b2AGHcz" in"++G%" is %0.4f"*vhcGdcyjdtcGdytHH
```
More readable (newlines and indents must be removed to run):
```
K4J24
L?*y>b-5>b\t?2>b\t.5
  }<b2"hatw"
  @[1K8K12K16J48J1008*JT96*2J960)
   xc"fapetucothengrsishtagucrflbo"2<b2
AGHcz" in"
++G
  %" is %0.4f"
   *vhcGdcyjdtcGdytH
 H
```
Update: Turns out, it's 1 character shorter (no space needed) to chop up the string into a list of 2 character strings before running the string index operation. `/x"string"<b2 2` -> `xc"string"2<b2`. Nothing else needs to be changed.
How it works:
* This uses @xnor's approach of looking up the value of currency using its first two letters, as well as the trick of detecting the initial `half` or `two`, removing it and calling the function again.
* To lookup the value of the first two characters, it finds the location of the first two letters of the currency in a string, then divides by 2 and takes the value at that index in the list. This is much shorter than an dict in pyth.
* Uses the fact that `x` (find within string) returns -1 on failure to avoid putting `po` (pounds) `qu` (quid) or `so` (sovereigns) in the string, and simply return the last element of the list, 960, by default.
* By rearranging the order of currencies in the lookup system and initializing carefully, with `K4` and `J24`, all spaces that would have been needed to separate numbers in the list were removed.
* Uses pyth's dual assignment operator, `A`, on the input split on  `in` to get the beginning and end of the input in separate variables.
* Does essentially the same lookup at the end, though pyth has no `.split(_,1)`, so it is somewhat more cumbersome.
Examples:
```
$ pyth programs/currency.pyth <<< '5 florins in half guineas'
5 florins is 0.9524 half guineas
$ pyth programs/currency.pyth <<< '0.4 quid in sixpenny bits'
0.4 quid is 16.0000 sixpenny bits
```
[Answer]
## Python 3: 264 239 chars
```
f=lambda c:c[:2]in"hatw"and f(c[5-(c>'t'):])*2/4**(c<'t')or[1,4,4,4,8,12,16,24,24,48,48,96,240,1008,960]['fapecoentuthgrsitashboflcrgu'.find(c[:2])//2]
a,b=input().split(" in ")
x,c=a.split(" ",1)
print(a,"is %0.4f"%(eval(x)*f(c)/f(b)),b)
```
The function `f` gets the shilling value of the currency-string `c` by fingerprinting the first two letters using the dictionary by finding them in a string. The prefixes "half" and "two" are detected and accounted for by chopping the prefix and the space and applying a multiplier. Since "halfpenny" lacks a space after "half", this results in "enny", but that's handled with a fictional "en" entry.
Thanks to @isaacg and @grc for lots of improvement on the dictionary lookup.
[Answer]
## Python 2 - 345 ~~358~~
```
s=str.startswith
h='half'
u,v=raw_input().split(' in ')
a,b=u.split(' ',1)
C=dict(fa=1,pe=4,twop=8,tu=8,thr=12,gr=16,si=24,ta=24,sh=48,b=48,fl=96,c=240,po=960,so=960,q=960,gu=1008)
C.update({h+'p':2,h+' gr':8,'two ':96,h+' c':120,h+' s':480,h+' gu':504})
for c in iter(C):
 if s(b,c):k=C[c]
 if s(v,c):f=C[c]
print u+' is %0.4f '%(eval(a)*k/f)+v
```
Requires input number to be a float in python i.e. `144.1`
I think this could be shortened in python 3...
...Confirmed thanks to @xnor. Also confirmed that having a better algorithm matters a lot ;)
[Answer]
# Haskell - 315 bytes
```
w x=f(u x)*v(u x)
f=maybe 1 id.l"ha tw tu th si"[0.5,2,2,3,6]
v x@(_:xs)|Just w<-l"bo cr gr gu so co fa fl pe po qu sh ta"[12,60,4,252,240,1,0.25,24,1,240,240,12,6]x=w|True=v xs
l k v x=take 2 x`lookup`zip(words k)v
u=unwords
i s|(n:x,_:t)<-span(/="in")$words s=u$n:x++["is",show$read n*w x/w t]++t
main=interact i
```
[Answer]
## JavaScript (ES5), 344
```
I=prompt()
n=I.match(/[\d.]+ /)[0]
A=I.slice(n.length).split(" in ")
function m(x){return{fi:1,he:2,p:4,pe:4,cr:4,tn:8,hg:8,tp:12,te:12,g:16,gs:16,sn:24,tr:24,si:48,b:48,fn:96,to:96,hc:120,c:240,cs:240,hs:480,hgtrue:504,ps:960,se:960,q:960,ga:1008}[x[0]+(x[5]||"")+(x[10]=="a"||"")]}
alert(n+A[0]+" is "+(n*m(A[0])/m(A[1])).toFixed(4)+" "+A[1])
```
I went with a hash function approach... I think I underestimated (relatively) how complex the input processing would be (over the regex approach, that wouldn't care about the number).
[Answer]
Based on @FryAmTheEggMan's answer, with a different way of testing `str.startwith`:
# Python 2: 317
```
h='half'
C=dict(fa=1,pe=4,twop=8,tu=8,thr=12,gr=16,si=24,ta=24,sh=48,b=48,fl=96,c=240,po=960,so=960,q=960,gu=1008)
C.update({h+'p':2,h+' gr':8,'two ':96,h+' c':120,h+' s':480,h+' gu':504})
u,v=raw_input().split(' in ')
a,b=u.split(' ',1)
s=lambda x:x and C.get(x, s(x[:-1]))
print u+' is %0.4f '%(eval(a)*s(b)/s(v))+v
```
[Answer]
# JavaScript ES6, 264 273
```
f=t=>{s=t.split(x=' in')
c=d=>{'t0sh|bo0^p|co0f0fp0fl|b b0gu0d|v0wn0gr0f g|t..?p0f s0f gu0f c0x|an'.split(0).map((e,i)=>{v=s[d].match(e)?[12,48,4,1,2,96,1008,960,240,16,8,480,504,120,24][i]:v})
return v}
return s.join(' is '+~~(1e4*t.split(' ')[0]*c(0)/c(1))/1e4)}
```
```
t=prompt()
s=t.split(x=' in')
c=function(d){'t0sh|bo0^p|co0f0fp0fl|b b0gu0d|v0wn0gr0f g|t..?p0f s0f gu0f c0x|an'.split(0).map(function(e,i){v=s[d].match(e)?[12,48,4,1,2,96,1008,960,240,16,8,480,504,120,24][i]:v})
return v}
alert(s.join(' is '+~~(1e4*t.split(' ')[0]*c(0)/c(1))/1e4))
```
This gets the value of each currency by checking it against various regexes, starting with the broadest `/t/`; the value is overwritten if another match is encountered. There might be a way to shave off a couple bytes by reordering the regex string. You can test it using the snippet above (It is formatted only to use dialog boxes and remove ES6 arrow functions so everyone can test the code easily). Thanks to Alconja for the suggestions.
]