------art_29446_4187177.1208952852932
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Sat, Apr 19, 2008 at 10:39 AM, Matthew Moss <matthew.moss / gmail.com> wrote:

>  Quiz #160
>  Triangle Area

 Here's my solution.  Nothing fancy.  Good old Heron's formula.  I had
 actually started with the cross product of the vectors describing two
 sides of a triangle, but since Vector doesn't have an outer_product
 method and implementing that for N dimentions got kind of ugly, I
 switched to the alternative that's also dimension-independent, which is
 still four lines of code :-)

 Marcelo

------art_29446_4187177.1208952852932
Content-Type: application/octet-stream; name=triangle_area
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ffdvao9l0
Content-Disposition: attachment; filename=triangle_area

IyEvdXNyL2Jpbi9lbnYgcnVieQoKcmVxdWlyZSAnbWF0cml4JwoKUkFORE9NX1BUID0gbGFtYmRh
IHsgVmVjdG9yW3JhbmQoMTAxKS01MCwgcmFuZCgxMDEpLTUwXSB9CgpjbGFzcyBUcmlhbmdsZQog
ICAgZGVmIGluaXRpYWxpemUoYSwgYiwgYykKICAgICAgICBAYSwgQGIsIEBjID0gYSwgYiwgYwog
ICAgZW5kCgogICAgZGVmIFRyaWFuZ2xlLnJhbmRvbShmb28gPSBSQU5ET01fUFQpCiAgICAgICAg
VHJpYW5nbGUubmV3KGZvby5jYWxsLCBmb28uY2FsbCwgZm9vLmNhbGwpCiAgICBlbmQKCiAgICBk
ZWYgW10oaSkKICAgICAgICBbQGEsIEBiLCBAY11baV0KICAgIGVuZAoKICAgIGRlZiBhcmVhCiAg
ICAgICAgYSA9IChAYi1AYSkucgogICAgICAgIGIgPSAoQGMtQGEpLnIKICAgICAgICBjID0gKEBi
LUBjKS5yCiAgICAgICAgcyA9IDAuNSooYStiK2MpCiAgICAgICAgcmV0dXJuIE1hdGg6OnNxcnQo
cyoocy1hKSoocy1iKSoocy1jKSkKICAgIGVuZAoKICAgIGRlZiBpbnNwZWN0CiAgICAgICAgIlRy
aWFuZ2xlWyN7QGF9LC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FZlY3Rv
clsgMjksICA0Nl0sIFZlY3RvclsgIDUsIC0zNF1dID0+CiAgICAgICAgICAgIDMxMjAuMAogICAg
fQoKICAgIGRlZiB0ZXN0X3NhbXBsZXMKICAgICAgICBTQU1QTEVTLmVhY2ggZG8gfHQsIGF8CiAg
ICAgICAgICAgIGFzc2VydF9pbl9kZWx0YShhLCB0LmFyZWEsIFRPTCkKICAgICAgICBlbmQKICAg
IGVuZAplbmQK
------art_29446_4187177.1208952852932--