+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init07ca65d

master
2.9 KiB70 linesraw
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.examples.dancing;
20
21/**
22 * Of the "normal" 12 pentominos, 6 of them have distinct shapes when flipped.
23 * This class includes both variants of the "flippable" shapes and the
24 * unflippable shapes for a total of 18 pieces. Clearly, the boards must have
25 * 18*5=90 boxes to hold all of the solutions.
26 */
27public class OneSidedPentomino extends Pentomino {
28
29  public OneSidedPentomino() {}
30
31  public OneSidedPentomino(int width, int height) {
32    super(width, height);
33  }
34
35  /**
36   * Define the one sided pieces. The flipped pieces have the same name with
37   * a capital letter.
38   */
39  protected void initializePieces() {
40    pieces.add(new Piece("x", " x /xxx/ x ", false, oneRotation));
41    pieces.add(new Piece("v", "x  /x  /xxx", false, fourRotations));
42    pieces.add(new Piece("t", "xxx/ x / x ", false, fourRotations));
43    pieces.add(new Piece("w", "  x/ xx/xx ", false, fourRotations));
44    pieces.add(new Piece("u", "x x/xxx", false, fourRotations));
45    pieces.add(new Piece("i", "xxxxx", false, twoRotations));
46    pieces.add(new Piece("f", " xx/xx / x ", false, fourRotations));
47    pieces.add(new Piece("p", "xx/xx/x ", false, fourRotations));
48    pieces.add(new Piece("z", "xx / x / xx", false, twoRotations));
49    pieces.add(new Piece("n", "xx  / xxx", false, fourRotations));
50    pieces.add(new Piece("y", "  x /xxxx", false, fourRotations));
51    pieces.add(new Piece("l", "   x/xxxx", false, fourRotations));
52    pieces.add(new Piece("F", "xx / xx/ x ", false, fourRotations));
53    pieces.add(new Piece("P", "xx/xx/ x", false, fourRotations));
54    pieces.add(new Piece("Z", " xx/ x /xx ", false, twoRotations));
55    pieces.add(new Piece("N", "  xx/xxx ", false, fourRotations));
56    pieces.add(new Piece("Y", " x  /xxxx", false, fourRotations));
57    pieces.add(new Piece("L", "x   /xxxx", false, fourRotations));
58  }
59  
60  /**
61   * Solve the 3x30 puzzle.
62   * @param args
63   */
64  public static void main(String[] args) {
65    Pentomino model = new OneSidedPentomino(3, 30);
66    int solutions = model.solve();
67    System.out.println(solutions + " solutions found.");
68  }
69
70}