Anonymous user
Constrained random points on a circle: Difference between revisions
Constrained random points on a circle (view source)
Revision as of 15:15, 12 November 2020
, 3 years agoUpdated to work with version 1.4 of Nim. Used standard library "sample" to get a random element from a sequence. Doubled horizontal scale.
(add lambdatalk) |
(Updated to work with version 1.4 of Nim. Used standard library "sample" to get a random element from a sequence. Doubled horizontal scale.) |
||
Line 2,134:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import tables, math
type Point = tuple[x, y: int]
Line 2,146 ⟶ 2,143:
for x in -15..15:
for y in -15..15:
if abs(complex(x.float, y.float)) in 10.0..15.0:
possiblePoints.add((x,y))
randomize()
for i in 0..100: world.inc possiblePoints.
for x in -15..15:
Line 2,156 ⟶ 2,153:
let key = (x, y)
if key in world and world[key] > 0:
stdout.write ' ' & $min(9, world[key])
else:
stdout.write
echo ""</lang>
{{out}}
<pre> 1 ▼
<pre>
1 1 1
1 1 1 1
1 2 1
1 1 1 1 1 1
1 1 1 1
1 1 1
1
1 1
1 1
1
1 1 1 1
1 2 2
1
1 1 2 1 1 2
1 1 1 1
=={{header|OCaml}}==
|