Shoelace formula for polygonal area: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 3 users not shown)
Line 608:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
proc shoelace . p[][] res .
sum = 0
for i = 1 to len p[][] - 1
sum += p[i][1] * p[i + 1][2]
sum -= p[i + 1][1] * p[i][2]
.
sum += p[i][1] * p[1][2]
sum -= p[1][1] * p[i][2]
res = abs sum / 2
.
data[][] = [ [ 3 4 ] [ 5 11 ] [ 12 8 ] [ 9 5 ] [ 5 6 ] ]
shoelace data[][] res
print res
</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
def shoelace(points) do
points
|> Enum.reduce({0, List.last(points)}, fn {x1, y1}, {sum, {x0, y0}} ->
{sum + (y0 * x1 - x0 * y1), {x1, y1}}
end)
|> elem(0)
|> div(2)
end
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 783 ⟶ 812:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Shoelace_formula_for_polygonal_area}}
 
'''Solution'''
 
[[File:Fōrmulæ - Shoelace formula 01.png]]
 
'''Test case'''
 
[[File:Fōrmulæ - Shoelace formula 02.png]]
 
[[File:Fōrmulæ - Shoelace formula 03.png]]
 
=={{header|Go}}==
Line 2,080 ⟶ 2,119:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var shoelace = Fn.new { |pts|
var area = 0
for (i in 0...pts.count-1) {
9,476

edits