Anonymous user
Total circles area: Difference between revisions
Updated to work with Nim 1.4: added "import sequtils"; corrected ".. <". Also replaced "map" with the simpler "mapIt". Added a template "sqr".
Alextretyak (talk | contribs) (Added 11l) |
(Updated to work with Nim 1.4: added "import sequtils"; corrected ".. <". Also replaced "map" with the simpler "mapIt". Added a template "sqr".) |
||
Line 1,773:
===Grid Sampling Version===
{{trans|Python}}
<lang nim>import
type Circle = tuple[x, y, r: float]
Line 1,804:
( 0.0152957411, 0.0638919221, 0.9771215985)]
template sqr(x: SomeNumber): SomeNumber = x * x
let xMin = min circles.map((c: Circle) => c.x - c.r)▼
let xMax = max circles.map((c: Circle) => c.x + c.r)▼
let
let
const boxSide = 500
Line 1,816 ⟶ 1,818:
var count = 0
for r in 0 ..
let y = yMin + float(r) * dy
for c in 0 ..
let x = xMin + float(c) * dx
for circle in circles:
if sqr(x -
inc count
break
echo "Approximated area: ", float(count) * dx * dy</lang>
{{out}}
<pre>Approximated area:
=={{header|Perl}}==
|