Shoelace formula for polygonal area: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Sidef}}: Fix link: Perl 6 --> Raku) |
No edit summary |
||
Line 705: | Line 705: | ||
its area is 30.0 |
its area is 30.0 |
||
</pre> |
</pre> |
||
=={{header|Lambdatalk}}== |
|||
<lang scheme> |
|||
{def shoelace |
|||
{lambda {:pol} |
|||
{abs |
|||
{/ |
|||
{- |
|||
{+ {S.map {{lambda {:pol :i} {* {car {A.get :i :pol}} |
|||
{cdr {A.get {+ :i 1} :pol}}}} :pol} |
|||
{S.serie 0 {- {A.length :pol} 2}}} |
|||
{* {car {A.get {- {A.length :pol} 1} :pol}} |
|||
{cdr {A.get 0 :pol}}}} |
|||
{+ {S.map {{lambda {:pol :i} {* {car {A.get {+ :i 1} :pol}} |
|||
{cdr {A.get :i :pol}}}} :pol} |
|||
{S.serie 0 {- {A.length :pol} 2}}} |
|||
{* {car {A.get 0 :pol}} |
|||
{cdr {A.get {- {A.length :pol} 1} :pol}}}}} 2}}}} |
|||
-> shoelace |
|||
{def pol |
|||
{A.new {cons 3 4} |
|||
{cons 5 11} |
|||
{cons 12 8} |
|||
{cons 9 5} |
|||
{cons 5 6}}} |
|||
-> pol = [(3 4),(5 11),(12 8),(9 5),(5 6)] |
|||
{shoelace {pol}} |
|||
-> 30 |
|||
</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |