# [Baypiggies] Hi all -can anyone convert this code to python---many thanks

Bryan O'Sullivan bos at serpentine.com
Thu Dec 14 20:48:44 CET 2006

```Sharon Kazemi wrote:

> have below code that needs to be recoded into Python for use in ESRI ArcGIS
> software.
> I would greatly appreciate any assistance.

Hi, Sheri -

I see you spammed the Python.NET list with the same homework question,
and gifted them with a corresponding huge list digest attachment, too.

Not to be put off by such small matters, I've written a version of the
routine you cited in Haskell.  I trust you'll have an easier time
translating it into Python.

Regards,

<b

furthest :: [(Float, Float)] -> (Int, Float)
furthest ps | length ps < 2 = (0, -1.0)
| otherwise     = maxList \$ zip (intsFrom 1) \$
map dist \$ tail ps
where (bx, by) = head ps
(cx, cy) = last ps
bcx      = cx - bx
bcy      = cy - by
intsFrom n = n : intsFrom (n + 1)
maxList (x:xs) = foldl maxDist x xs
maxDist a1@(_, d1) a2@(_, d2) | d1 > d2   = a1
| otherwise = a2
dist (ax, ay) = let bax = ax - bx
bay = ay - by
cax = ax - cx
cay = ay - cy
d = cax * bay - cay * bax
in
if bcx * bax + bcy * bay <= 0.0
then bax * bax + bay * bay
else if bcx * cax + bcy * cay >= 0.0
then cax * cax + cay * cay
else d * d / (bcx*bcx+bcy*bcy)
```