Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Closest-pair-problem/Zkl/closest-pair-problem-1.zkl
Normal file
15
Task/Closest-pair-problem/Zkl/closest-pair-problem-1.zkl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class Point{
|
||||
fcn init(_x,_y){ var[const] x=_x, y=_y; }
|
||||
fcn distance(p){ (p.x-x).hypot(p.y-y) }
|
||||
fcn toString { String("Point(",x,",",y,")") }
|
||||
}
|
||||
|
||||
// find closest two points using brute ugly force:
|
||||
// find all combinations of two points, measure distance, pick smallest
|
||||
fcn closestPoints(points){
|
||||
pairs:=Utils.Helpers.pickNFrom(2,points);
|
||||
triples:=pairs.apply(fcn([(p1,p2)]){ T(p1,p2,p1.distance(p2)) });
|
||||
triples.reduce(fcn([(_,_,d1)]p1,[(_,_,d2)]p2){
|
||||
if(d1 < d2) p1 else p2
|
||||
});
|
||||
}
|
||||
15
Task/Closest-pair-problem/Zkl/closest-pair-problem-2.zkl
Normal file
15
Task/Closest-pair-problem/Zkl/closest-pair-problem-2.zkl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
points:=T( 5.0, 9.0, 9.0, 3.0,
|
||||
2.0, 0.0, 8.0, 4.0,
|
||||
7.0, 4.0, 9.0, 10.0,
|
||||
1.0, 9.0, 8.0, 2.0,
|
||||
0.0, 10.0, 9.0, 6.0 ).pump(List,Void.Read,Point);
|
||||
|
||||
closestPoints(points).println(); //-->L(Point(8,4),Point(7,4),1)
|
||||
|
||||
points:=T( 0.654682, 0.925557, 0.409382, 0.619391,
|
||||
0.891663, 0.888594, 0.716629, 0.9962,
|
||||
0.477721, 0.946355, 0.925092, 0.81822,
|
||||
0.624291, 0.142924, 0.211332, 0.221507,
|
||||
0.293786, 0.691701, 0.839186, 0.72826)
|
||||
.pump(List,Void.Read,Point);
|
||||
closestPoints(points).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue