I want to build a ladder. For this, I have scavenged from the junkyard two long boards with holes in them, and I want to place the steps into these holes. However, the holes are not evenly placed, so the steps will be a little wonky, and I find it hard to estimate the amount of rod I need for them. Your job is to do the calculations for me.
Your input is two bit vectors, given as arrays of integers, which represent the two boards.
0 represents a segment of one aud (arbitrary unit of distance) without a hole, and a
1 represents a segment of one aud with a single hole.
The arrays may be of different lengths and contain a different number of
1s, but they will not be empty.
I will construct my ladder as follows.
First, I place the two boards exactly one aud apart, and align their left ends.
For each index
i, I measure the distance between the
ith hole of the first board with the
ith hole of the second board, cut a piece of rod, and attach it between the two holes.
I stop once I run out of holes in one of the boards.
Your output is the total amount of rod I'll need for the steps, measured in auds. The output should be correct to at least six significant digits.
Consider the inputs
The resulting ladder looks like this:
The total length of the rod in this ladder is
You can write either a function or a full program. The lowest byte count wins, and standard loopholes are disallowed.
  -> 0.0  [1,0] -> 0.0 [1,0,0] [1,1,1,1,1] -> 1.0 [0,1,0,1] [1,0,0,1] -> 2.414213562373095 [0,1,1,0,1,1,1,1,0,0] [1,0,0,1,1,1,0,0,1] -> 7.06449510224598 [1,1,1,1,1] [0,0,1,1,0,1,0,0,1] -> 12.733433128760744 [0,0,0,1,0,1,1,0,0,0,1,1,1,0,0,1,0,1,1,0,0,0,1,0] [0,0,1,1,0,1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,0,1] -> 20.38177416534678