def mmcc(ds, xs, ys):
    """Fit a straight line

    (x, y) = (mx, my) *  d + (cx, cy)

    to ordinates x, y in xs, ys as a function of d in ds."""

    assert len(ds) == len(xs)
    assert len(ds) == len(ys)

    ds = [float(i) for i in ds]
    xs = [float(i) for i in xs]
    ys = [float(i) for i in ys]

    _d = sum(ds) / len(ds)
    _x = sum(xs) / len(xs)
    _y = sum(ys) / len(ys)

    mx = sum((d - _d) * (x - _x) for d, x in zip(ds, xs)) / sum(
        (d - _d) * (d - _d) for d in ds
    )

    my = sum((d - _d) * (y - _y) for d, y in zip(ds, ys)) / sum(
        (d - _d) * (d - _d) for d in ds
    )

    cx = _x - mx * _d
    cy = _y - my * _d

    return mx, my, cx, cy