Crosswalk Efficiency A standard road intersection contains 4 sidewalk corners and four crosswalks connecting them. It could also have 2 diagonal walks.

    sRRRRs
    iOOOOi
    dAAAAd
    eDDDDe
side0----1walk
ROAD|\  /|ROAD
ROAD| \/ |ROAD
ROAD| /\ |ROAD
ROAD|/  \|ROAD
side2----3walk
    wRRRRw
    aOOOOa
    lAAAAl
    kDDDDk


Not all 6 crosswalks are needed to let pedestrians get from any corner to any other (assuming no jaywalking). It's better for traffic and cheaper for the highway department if there are fewer crosswalks. However, it is better for pedestrians if they can get across faster.

Let L be the total length of the crosswalks present in the intersection. Assume the intersection is a unit square, so the length of orthogonal walks is 1 and for diagonal walks it's sqrt(2).

Let W be the average distance a pedestrian needs to walk when crossing the intersection. Each corner fills up with pedestrians evenly and each pedestrian at a corner is randomly headed for one of the 3 other corners with equal chance.

When L and W are low we have an efficient intersection. Let E = 1 / (W * L) be the crosswalk efficiency of a particular set of crosswalks. Higher E means more efficient.

Goal

Write a program that takes in a list of present crosswalks and outputs the efficiency.

Input will come from stdin in the form 01 32 21 (for example), which represents an intersection with crosswalks from corners 0 to 1, 3 to 2, and 2 to 1 (in a Z). Output to stdout.

Running your program might look something like

$ crosswalk.mylanguage 01 23
0.0


Scoring

This is code golf. The submission with the fewest characters wins.

Details


Pedestrians always stay on the crosswalks and always take the shortest route.
Pedestrians can change direction where the diagonals meet (and at corners).
If all corners aren't connected take W to be infinity (and E to be 0).
The input crosswalk edges are always unique and there are only up to 6.
The input or corner order doesn't matter. 01 32 21 is the same as 23 21 10.
Python - 489

Uses all pairs shortest paths.

import re
R=re.sub
exec R("I"," in ",R("F","for ","""s,m,i=sum,map,int
r=2**.5/2
n=1e309
g=[0,1,1,n,r],[1,0,n,1,r],[1,n,0,1,r],[n,1,1,0,r],[r]*4+[0]
f="01021323"
o=lambda v:[list(v[x:x+2])FxIrange(0,len(v),2)]
v=o(f+"04142434")
q=m(sorted,R("12|21","14 24",R("03|30","04 34",raw_input())).split())
r=range(5)
u=[m(i,x)FxIv if x notIq]
l=s(g[i(y)][i(x)]Fy,xIq)
Fy,xIu:g[y][x]=n
FaIr:
 FbIr:
    FcIr:g[b][c]=min(g[b][a]+g[a][c],g[b][c])
w=s(g[i(y)][i(x)]Fy,xIo(f+"0312"))/6.
print 1/(w*l)"""))