Free polyominoes enumeration: Difference between revisions
Content added Content deleted
m (→{{header|Java}}: add parallel) |
m (→{{header|Java}}: small changes) |
||
Line 707: | Line 707: | ||
<lang java>import java.awt.Point; |
<lang java>import java.awt.Point; |
||
import java.util.*; |
import java.util.*; |
||
import static java.util.Arrays.asList; |
|||
import java.util.function.Function; |
import java.util.function.Function; |
||
import static java.util.Comparator.comparing; |
import static java.util.Comparator.comparing; |
||
Line 712: | Line 713: | ||
public class FreePolyominoesEnum { |
public class FreePolyominoesEnum { |
||
static final List<Function<Point, Point>> transforms = new ArrayList<>(); |
static final List<Function<Point, Point>> transforms = new ArrayList<>(); |
||
Line 733: | Line 733: | ||
static List<Point> translateToOrigin(List<Point> poly) { |
static List<Point> translateToOrigin(List<Point> poly) { |
||
final Point min = findMinima(poly); |
final Point min = findMinima(poly); |
||
poly.replaceAll(p -> new Point(p.x - min.x, p.y - min.y)); |
|||
return poly; |
|||
} |
} |
||
Line 757: | Line 757: | ||
static List<Point> neighborhoods(Point p) { |
static List<Point> neighborhoods(Point p) { |
||
return |
return asList(new Point(p.x - 1, p.y), new Point(p.x + 1, p.y), |
||
new Point(p.x |
new Point(p.x, p.y - 1), new Point(p.x, p.y + 1)); |
||
new Point(p.x, p.y + 1)}); |
|||
} |
} |
||
static List<Point> concat(List<Point> lst, Point |
static List<Point> concat(List<Point> lst, Point pt) { |
||
List<Point> r = |
List<Point> r = new ArrayList<>(); |
||
r. |
r.addAll(lst); |
||
r.add(pt); |
|||
return r; |
return r; |
||
} |
} |
||
Line 790: | Line 790: | ||
List<List<Point>> r = new ArrayList<>(); |
List<List<Point>> r = new ArrayList<>(); |
||
if (n == 1) |
if (n == 1) |
||
r.add( |
r.add(asList(new Point(0, 0))); |
||
return r; |
return r; |
||
} |
} |