Skyscraper puzzle solver in JavaMax heap in JavaSudoku Week-End Challenge - Brute-Force Recursive...
Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?
What to do if authors don't respond to my serious concerns about their paper?
How to tag distinct options/entities without giving any an implicit priority or suggested order?
Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?
Jumping Numbers
What is better: yes / no radio, or simple checkbox?
Explain the objections to these measures against human trafficking
Why did other German political parties disband so fast when Hitler was appointed chancellor?
Would these multi-classing house rules cause unintended problems?
What to do when being responsible for data protection in your lab, yet advice is ignored?
Why is "points exist" not an axiom in geometry?
How to convert a ListContourPlot into primitive usable with Graphics3D?
How to prevent users from executing commands through browser URL
Compress command output by piping to bzip2
Isn't using the Extrusion Multiplier like cheating?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
What flying insects could re-enter the Earth's atmosphere from space without burning up?
Citing paywalled articles accessed via illegal web sharing
insert EOF statement before the last line of file
How would an AI self awareness kill switch work?
Eww, those bytes are gross
Every character has a name - does this lead to too many named characters?
How should I handle players who ignore the session zero agreement?
Why do neural networks need so many training examples to perform?
Skyscraper puzzle solver in Java
Max heap in JavaSudoku Week-End Challenge - Brute-Force Recursive solverSymmetric SquareLocker Puzzle in JavaSums of some array elementsFill 2D array recursivelyJava OOP HomeWorkImplementation of a Generic Singly Linked List in JavaSudoku puzzle solving algorithm that uses a rule-based approach to narrow the depth searchBinary Puzzle Solver - 10000 questions
$begingroup$
For an assignment, I have created a solver for the Skyscraper Puzzle:
Each puzzle consists of an N×N grid with some clues along its sides. The object is to place a skyscraper in each square, with a height between 1 and N, so that no two skyscrapers in a row or column have the same number of floors. In addition, the number of visible skyscrapers, as viewed from the direction of each clue, is equal to the value of the clue. Note that higher skyscrapers block the view of lower skyscrapers located behind them.
The puzzle and the ordinances are hard coded into the program. I would like feedback on efficiency and readability. Any and all suggestions are welcome!
SkyscraperPuzzle.java
package Skyscraper;
/**
* Write a description of class SkyscraperPuzzle here.
*
* @author David White
* @version (a version number or a date)
*/
public class SkyscraperPuzzle {
private int[][] puzzle = {
{1, 4, 3, 2},
{2, 3, 4, 1},
{4, 2, 1, 3},
{3, 1, 2, 4}
};
private Ordinance[][] ords = {
{new Ordinance(3, Direction.NORTH), new Ordinance(1, Direction.NORTH), new Ordinance(2, Direction.NORTH), new Ordinance(3, Direction.NORTH)}, //NORTH
{new Ordinance(2, Direction.SOUTH), new Ordinance(4, Direction.SOUTH), new Ordinance(2, Direction.SOUTH), new Ordinance(1, Direction.SOUTH)}, //SOUTH
{new Ordinance(3, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(1, Direction.EAST)}, //EAST
{new Ordinance(2, Direction.WEST), new Ordinance(3, Direction.WEST), new Ordinance(1, Direction.WEST), new Ordinance(2, Direction.WEST)} //WEST
};
/**
* Write a constructor to initialize and populate the puzzle and list of ordinances
* so that the puzzle may be checked to see if it is (correctly) solved.
*/
public SkyscraperPuzzle() {
//Puzzle is populated above
//Ords is populated above
}
/**
* returns the puzzle
*/
public int[][] getPuzzle() {
return this.puzzle;
}
/**
* Retuns a 1D array that respresents row r of puzzle
*/
public int[] getRow(int row) {
return puzzle[row];
}
/**
* Write a method that returns a 1D array that represents column c of puzzle
*/
public int[] getColumn(int column) { // row by column
int[] arr = new int[this.puzzle.length];
for(int i = 0; i < this.puzzle.length; i++) {
arr[i] = this.puzzle[i][column];
}
return arr;
}
/**
* Write a method that returns true if the 1D array parameter does not contain duplicates
*/
public boolean noDuplicates(int[] arr) {
for(int i = 0; i < arr.length - 1; i++) {
for(int j = i + 1; j < arr.length - 1; j++) {
if(arr[i] == arr[j]) {
return false;
}
}
}
return true;
}
/**
* Write a method that returns true if each value from 1 to the number of rows (or columns, they
* are the same), is contained in the 1D array
*
* if 5x5
* then 1 2 3 4 5 should all be in array
*/
public boolean containsOneToN(int[] arr) {
int[] array = new int[arr.length];
int count = 0;
for(int i = 0; i < array.length; i++) {
array[i] = i + 1;
}
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < array.length; j++) {
if(arr[i] == array[j]) {
count += 1;
array[j] = 0;
}
}
}
return count == arr.length;
}
/**
* Write a method that traverses the 2D array, ords, and returns true if each and
* every Ordinance requirement is met
*/
public boolean meetsOrdinances() {
for(int i = 0; i < this.puzzle.length; i++) {
/* Yet to be implemented */
}
return false; //used to allow compile
}
/**
* Write a method that returns true if the puzzle is a correctly solved Skyscraper puzzle
*/
public boolean isSolved() {
/* Each row and column */
for(int i = 0; i < this.puzzle.length; i++) {
if(!noDuplicates(this.puzzle[i]) || !noDuplicates(getColumn(i))) {
return false;
}
if(!containsOneToN(this.puzzle[i]) || !containsOneToN(getColumn(i))) {
return false;
}
if(!meetsOrdinances()) {
return false;
}
}
return true;
}
}
Direction.java
package Skyscraper;
/**
* Enumeration class Direction - write a description of the enum class here
*
* @author David White
* @version (version number or date here)
*/
public enum Direction {
NORTH, /* Above the 2D array */
SOUTH, /* Below the 2D array */
EAST, /* Right of the 2D array */
WEST /* Left of the 2D array */
}
Ordinance.java
package Skyscraper;
/**
* Write a description of class Ordinance here.
*
* @author David White
* @version (a version number or a date)
*/
public class Ordinance {
private int num;
private Direction direction;
public Ordinance(int num, Direction direction) {
this.num = num;
this.direction = direction;
}
public int getNum() {
return this.num;
}
public Direction getDirection() {
return this.direction;
}
}
The PuzzleTest.java
is used to make sure the methods I've written work in the way they're intended to.
PuzzleTest.java
package Skyscraper;
/**
* Write a description of class PuzzleTest here.
*
* @author David White
* @version (a version number or a date)
*/
public class PuzzleTest {
public static void main(String[] args) {
SkyscraperPuzzle p = new SkyscraperPuzzle();
int[][] puzzle = p.getPuzzle();
/*
* Outputs entire puzzle
*/
for(int[] row : puzzle) {
for(int item : row) {
System.out.print(item + " ");
}
System.out.println();
}
System.out.println();
/*
* Test getColumn method
* Output should be
* 1
* 4
* 7
* Status: Successful
*/
int[] col = p.getColumn(0);
for(int i = 0; i < col.length; i++) {
System.out.println(col[i]);
}
System.out.println();
/*
* Test noDuplicates method
* Output should be
* true
* Status: Successful
*/
int[] arr = {1, 2, 3, 4, 5};
System.out.println(p.noDuplicates(arr));
System.out.println();
/*
* Test containsOneToN method
* Output should be
* true
* Status: Successful
*/
int[] arr2 = {1, 2, 3, 4, 5};
System.out.println(p.containsOneToN(arr2));
/*
* Test meetsOrdinances method
* Output should be
* true
* Status: To be tested
*/
}
}
java homework sudoku
$endgroup$
add a comment |
$begingroup$
For an assignment, I have created a solver for the Skyscraper Puzzle:
Each puzzle consists of an N×N grid with some clues along its sides. The object is to place a skyscraper in each square, with a height between 1 and N, so that no two skyscrapers in a row or column have the same number of floors. In addition, the number of visible skyscrapers, as viewed from the direction of each clue, is equal to the value of the clue. Note that higher skyscrapers block the view of lower skyscrapers located behind them.
The puzzle and the ordinances are hard coded into the program. I would like feedback on efficiency and readability. Any and all suggestions are welcome!
SkyscraperPuzzle.java
package Skyscraper;
/**
* Write a description of class SkyscraperPuzzle here.
*
* @author David White
* @version (a version number or a date)
*/
public class SkyscraperPuzzle {
private int[][] puzzle = {
{1, 4, 3, 2},
{2, 3, 4, 1},
{4, 2, 1, 3},
{3, 1, 2, 4}
};
private Ordinance[][] ords = {
{new Ordinance(3, Direction.NORTH), new Ordinance(1, Direction.NORTH), new Ordinance(2, Direction.NORTH), new Ordinance(3, Direction.NORTH)}, //NORTH
{new Ordinance(2, Direction.SOUTH), new Ordinance(4, Direction.SOUTH), new Ordinance(2, Direction.SOUTH), new Ordinance(1, Direction.SOUTH)}, //SOUTH
{new Ordinance(3, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(1, Direction.EAST)}, //EAST
{new Ordinance(2, Direction.WEST), new Ordinance(3, Direction.WEST), new Ordinance(1, Direction.WEST), new Ordinance(2, Direction.WEST)} //WEST
};
/**
* Write a constructor to initialize and populate the puzzle and list of ordinances
* so that the puzzle may be checked to see if it is (correctly) solved.
*/
public SkyscraperPuzzle() {
//Puzzle is populated above
//Ords is populated above
}
/**
* returns the puzzle
*/
public int[][] getPuzzle() {
return this.puzzle;
}
/**
* Retuns a 1D array that respresents row r of puzzle
*/
public int[] getRow(int row) {
return puzzle[row];
}
/**
* Write a method that returns a 1D array that represents column c of puzzle
*/
public int[] getColumn(int column) { // row by column
int[] arr = new int[this.puzzle.length];
for(int i = 0; i < this.puzzle.length; i++) {
arr[i] = this.puzzle[i][column];
}
return arr;
}
/**
* Write a method that returns true if the 1D array parameter does not contain duplicates
*/
public boolean noDuplicates(int[] arr) {
for(int i = 0; i < arr.length - 1; i++) {
for(int j = i + 1; j < arr.length - 1; j++) {
if(arr[i] == arr[j]) {
return false;
}
}
}
return true;
}
/**
* Write a method that returns true if each value from 1 to the number of rows (or columns, they
* are the same), is contained in the 1D array
*
* if 5x5
* then 1 2 3 4 5 should all be in array
*/
public boolean containsOneToN(int[] arr) {
int[] array = new int[arr.length];
int count = 0;
for(int i = 0; i < array.length; i++) {
array[i] = i + 1;
}
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < array.length; j++) {
if(arr[i] == array[j]) {
count += 1;
array[j] = 0;
}
}
}
return count == arr.length;
}
/**
* Write a method that traverses the 2D array, ords, and returns true if each and
* every Ordinance requirement is met
*/
public boolean meetsOrdinances() {
for(int i = 0; i < this.puzzle.length; i++) {
/* Yet to be implemented */
}
return false; //used to allow compile
}
/**
* Write a method that returns true if the puzzle is a correctly solved Skyscraper puzzle
*/
public boolean isSolved() {
/* Each row and column */
for(int i = 0; i < this.puzzle.length; i++) {
if(!noDuplicates(this.puzzle[i]) || !noDuplicates(getColumn(i))) {
return false;
}
if(!containsOneToN(this.puzzle[i]) || !containsOneToN(getColumn(i))) {
return false;
}
if(!meetsOrdinances()) {
return false;
}
}
return true;
}
}
Direction.java
package Skyscraper;
/**
* Enumeration class Direction - write a description of the enum class here
*
* @author David White
* @version (version number or date here)
*/
public enum Direction {
NORTH, /* Above the 2D array */
SOUTH, /* Below the 2D array */
EAST, /* Right of the 2D array */
WEST /* Left of the 2D array */
}
Ordinance.java
package Skyscraper;
/**
* Write a description of class Ordinance here.
*
* @author David White
* @version (a version number or a date)
*/
public class Ordinance {
private int num;
private Direction direction;
public Ordinance(int num, Direction direction) {
this.num = num;
this.direction = direction;
}
public int getNum() {
return this.num;
}
public Direction getDirection() {
return this.direction;
}
}
The PuzzleTest.java
is used to make sure the methods I've written work in the way they're intended to.
PuzzleTest.java
package Skyscraper;
/**
* Write a description of class PuzzleTest here.
*
* @author David White
* @version (a version number or a date)
*/
public class PuzzleTest {
public static void main(String[] args) {
SkyscraperPuzzle p = new SkyscraperPuzzle();
int[][] puzzle = p.getPuzzle();
/*
* Outputs entire puzzle
*/
for(int[] row : puzzle) {
for(int item : row) {
System.out.print(item + " ");
}
System.out.println();
}
System.out.println();
/*
* Test getColumn method
* Output should be
* 1
* 4
* 7
* Status: Successful
*/
int[] col = p.getColumn(0);
for(int i = 0; i < col.length; i++) {
System.out.println(col[i]);
}
System.out.println();
/*
* Test noDuplicates method
* Output should be
* true
* Status: Successful
*/
int[] arr = {1, 2, 3, 4, 5};
System.out.println(p.noDuplicates(arr));
System.out.println();
/*
* Test containsOneToN method
* Output should be
* true
* Status: Successful
*/
int[] arr2 = {1, 2, 3, 4, 5};
System.out.println(p.containsOneToN(arr2));
/*
* Test meetsOrdinances method
* Output should be
* true
* Status: To be tested
*/
}
}
java homework sudoku
$endgroup$
1
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
How can this code ever work ifmeetsOrdinances
saysYet to be implemented
?
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming thatmeetOrdinances
works as expected.
$endgroup$
– David White
1 hour ago
add a comment |
$begingroup$
For an assignment, I have created a solver for the Skyscraper Puzzle:
Each puzzle consists of an N×N grid with some clues along its sides. The object is to place a skyscraper in each square, with a height between 1 and N, so that no two skyscrapers in a row or column have the same number of floors. In addition, the number of visible skyscrapers, as viewed from the direction of each clue, is equal to the value of the clue. Note that higher skyscrapers block the view of lower skyscrapers located behind them.
The puzzle and the ordinances are hard coded into the program. I would like feedback on efficiency and readability. Any and all suggestions are welcome!
SkyscraperPuzzle.java
package Skyscraper;
/**
* Write a description of class SkyscraperPuzzle here.
*
* @author David White
* @version (a version number or a date)
*/
public class SkyscraperPuzzle {
private int[][] puzzle = {
{1, 4, 3, 2},
{2, 3, 4, 1},
{4, 2, 1, 3},
{3, 1, 2, 4}
};
private Ordinance[][] ords = {
{new Ordinance(3, Direction.NORTH), new Ordinance(1, Direction.NORTH), new Ordinance(2, Direction.NORTH), new Ordinance(3, Direction.NORTH)}, //NORTH
{new Ordinance(2, Direction.SOUTH), new Ordinance(4, Direction.SOUTH), new Ordinance(2, Direction.SOUTH), new Ordinance(1, Direction.SOUTH)}, //SOUTH
{new Ordinance(3, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(1, Direction.EAST)}, //EAST
{new Ordinance(2, Direction.WEST), new Ordinance(3, Direction.WEST), new Ordinance(1, Direction.WEST), new Ordinance(2, Direction.WEST)} //WEST
};
/**
* Write a constructor to initialize and populate the puzzle and list of ordinances
* so that the puzzle may be checked to see if it is (correctly) solved.
*/
public SkyscraperPuzzle() {
//Puzzle is populated above
//Ords is populated above
}
/**
* returns the puzzle
*/
public int[][] getPuzzle() {
return this.puzzle;
}
/**
* Retuns a 1D array that respresents row r of puzzle
*/
public int[] getRow(int row) {
return puzzle[row];
}
/**
* Write a method that returns a 1D array that represents column c of puzzle
*/
public int[] getColumn(int column) { // row by column
int[] arr = new int[this.puzzle.length];
for(int i = 0; i < this.puzzle.length; i++) {
arr[i] = this.puzzle[i][column];
}
return arr;
}
/**
* Write a method that returns true if the 1D array parameter does not contain duplicates
*/
public boolean noDuplicates(int[] arr) {
for(int i = 0; i < arr.length - 1; i++) {
for(int j = i + 1; j < arr.length - 1; j++) {
if(arr[i] == arr[j]) {
return false;
}
}
}
return true;
}
/**
* Write a method that returns true if each value from 1 to the number of rows (or columns, they
* are the same), is contained in the 1D array
*
* if 5x5
* then 1 2 3 4 5 should all be in array
*/
public boolean containsOneToN(int[] arr) {
int[] array = new int[arr.length];
int count = 0;
for(int i = 0; i < array.length; i++) {
array[i] = i + 1;
}
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < array.length; j++) {
if(arr[i] == array[j]) {
count += 1;
array[j] = 0;
}
}
}
return count == arr.length;
}
/**
* Write a method that traverses the 2D array, ords, and returns true if each and
* every Ordinance requirement is met
*/
public boolean meetsOrdinances() {
for(int i = 0; i < this.puzzle.length; i++) {
/* Yet to be implemented */
}
return false; //used to allow compile
}
/**
* Write a method that returns true if the puzzle is a correctly solved Skyscraper puzzle
*/
public boolean isSolved() {
/* Each row and column */
for(int i = 0; i < this.puzzle.length; i++) {
if(!noDuplicates(this.puzzle[i]) || !noDuplicates(getColumn(i))) {
return false;
}
if(!containsOneToN(this.puzzle[i]) || !containsOneToN(getColumn(i))) {
return false;
}
if(!meetsOrdinances()) {
return false;
}
}
return true;
}
}
Direction.java
package Skyscraper;
/**
* Enumeration class Direction - write a description of the enum class here
*
* @author David White
* @version (version number or date here)
*/
public enum Direction {
NORTH, /* Above the 2D array */
SOUTH, /* Below the 2D array */
EAST, /* Right of the 2D array */
WEST /* Left of the 2D array */
}
Ordinance.java
package Skyscraper;
/**
* Write a description of class Ordinance here.
*
* @author David White
* @version (a version number or a date)
*/
public class Ordinance {
private int num;
private Direction direction;
public Ordinance(int num, Direction direction) {
this.num = num;
this.direction = direction;
}
public int getNum() {
return this.num;
}
public Direction getDirection() {
return this.direction;
}
}
The PuzzleTest.java
is used to make sure the methods I've written work in the way they're intended to.
PuzzleTest.java
package Skyscraper;
/**
* Write a description of class PuzzleTest here.
*
* @author David White
* @version (a version number or a date)
*/
public class PuzzleTest {
public static void main(String[] args) {
SkyscraperPuzzle p = new SkyscraperPuzzle();
int[][] puzzle = p.getPuzzle();
/*
* Outputs entire puzzle
*/
for(int[] row : puzzle) {
for(int item : row) {
System.out.print(item + " ");
}
System.out.println();
}
System.out.println();
/*
* Test getColumn method
* Output should be
* 1
* 4
* 7
* Status: Successful
*/
int[] col = p.getColumn(0);
for(int i = 0; i < col.length; i++) {
System.out.println(col[i]);
}
System.out.println();
/*
* Test noDuplicates method
* Output should be
* true
* Status: Successful
*/
int[] arr = {1, 2, 3, 4, 5};
System.out.println(p.noDuplicates(arr));
System.out.println();
/*
* Test containsOneToN method
* Output should be
* true
* Status: Successful
*/
int[] arr2 = {1, 2, 3, 4, 5};
System.out.println(p.containsOneToN(arr2));
/*
* Test meetsOrdinances method
* Output should be
* true
* Status: To be tested
*/
}
}
java homework sudoku
$endgroup$
For an assignment, I have created a solver for the Skyscraper Puzzle:
Each puzzle consists of an N×N grid with some clues along its sides. The object is to place a skyscraper in each square, with a height between 1 and N, so that no two skyscrapers in a row or column have the same number of floors. In addition, the number of visible skyscrapers, as viewed from the direction of each clue, is equal to the value of the clue. Note that higher skyscrapers block the view of lower skyscrapers located behind them.
The puzzle and the ordinances are hard coded into the program. I would like feedback on efficiency and readability. Any and all suggestions are welcome!
SkyscraperPuzzle.java
package Skyscraper;
/**
* Write a description of class SkyscraperPuzzle here.
*
* @author David White
* @version (a version number or a date)
*/
public class SkyscraperPuzzle {
private int[][] puzzle = {
{1, 4, 3, 2},
{2, 3, 4, 1},
{4, 2, 1, 3},
{3, 1, 2, 4}
};
private Ordinance[][] ords = {
{new Ordinance(3, Direction.NORTH), new Ordinance(1, Direction.NORTH), new Ordinance(2, Direction.NORTH), new Ordinance(3, Direction.NORTH)}, //NORTH
{new Ordinance(2, Direction.SOUTH), new Ordinance(4, Direction.SOUTH), new Ordinance(2, Direction.SOUTH), new Ordinance(1, Direction.SOUTH)}, //SOUTH
{new Ordinance(3, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(2, Direction.EAST), new Ordinance(1, Direction.EAST)}, //EAST
{new Ordinance(2, Direction.WEST), new Ordinance(3, Direction.WEST), new Ordinance(1, Direction.WEST), new Ordinance(2, Direction.WEST)} //WEST
};
/**
* Write a constructor to initialize and populate the puzzle and list of ordinances
* so that the puzzle may be checked to see if it is (correctly) solved.
*/
public SkyscraperPuzzle() {
//Puzzle is populated above
//Ords is populated above
}
/**
* returns the puzzle
*/
public int[][] getPuzzle() {
return this.puzzle;
}
/**
* Retuns a 1D array that respresents row r of puzzle
*/
public int[] getRow(int row) {
return puzzle[row];
}
/**
* Write a method that returns a 1D array that represents column c of puzzle
*/
public int[] getColumn(int column) { // row by column
int[] arr = new int[this.puzzle.length];
for(int i = 0; i < this.puzzle.length; i++) {
arr[i] = this.puzzle[i][column];
}
return arr;
}
/**
* Write a method that returns true if the 1D array parameter does not contain duplicates
*/
public boolean noDuplicates(int[] arr) {
for(int i = 0; i < arr.length - 1; i++) {
for(int j = i + 1; j < arr.length - 1; j++) {
if(arr[i] == arr[j]) {
return false;
}
}
}
return true;
}
/**
* Write a method that returns true if each value from 1 to the number of rows (or columns, they
* are the same), is contained in the 1D array
*
* if 5x5
* then 1 2 3 4 5 should all be in array
*/
public boolean containsOneToN(int[] arr) {
int[] array = new int[arr.length];
int count = 0;
for(int i = 0; i < array.length; i++) {
array[i] = i + 1;
}
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < array.length; j++) {
if(arr[i] == array[j]) {
count += 1;
array[j] = 0;
}
}
}
return count == arr.length;
}
/**
* Write a method that traverses the 2D array, ords, and returns true if each and
* every Ordinance requirement is met
*/
public boolean meetsOrdinances() {
for(int i = 0; i < this.puzzle.length; i++) {
/* Yet to be implemented */
}
return false; //used to allow compile
}
/**
* Write a method that returns true if the puzzle is a correctly solved Skyscraper puzzle
*/
public boolean isSolved() {
/* Each row and column */
for(int i = 0; i < this.puzzle.length; i++) {
if(!noDuplicates(this.puzzle[i]) || !noDuplicates(getColumn(i))) {
return false;
}
if(!containsOneToN(this.puzzle[i]) || !containsOneToN(getColumn(i))) {
return false;
}
if(!meetsOrdinances()) {
return false;
}
}
return true;
}
}
Direction.java
package Skyscraper;
/**
* Enumeration class Direction - write a description of the enum class here
*
* @author David White
* @version (version number or date here)
*/
public enum Direction {
NORTH, /* Above the 2D array */
SOUTH, /* Below the 2D array */
EAST, /* Right of the 2D array */
WEST /* Left of the 2D array */
}
Ordinance.java
package Skyscraper;
/**
* Write a description of class Ordinance here.
*
* @author David White
* @version (a version number or a date)
*/
public class Ordinance {
private int num;
private Direction direction;
public Ordinance(int num, Direction direction) {
this.num = num;
this.direction = direction;
}
public int getNum() {
return this.num;
}
public Direction getDirection() {
return this.direction;
}
}
The PuzzleTest.java
is used to make sure the methods I've written work in the way they're intended to.
PuzzleTest.java
package Skyscraper;
/**
* Write a description of class PuzzleTest here.
*
* @author David White
* @version (a version number or a date)
*/
public class PuzzleTest {
public static void main(String[] args) {
SkyscraperPuzzle p = new SkyscraperPuzzle();
int[][] puzzle = p.getPuzzle();
/*
* Outputs entire puzzle
*/
for(int[] row : puzzle) {
for(int item : row) {
System.out.print(item + " ");
}
System.out.println();
}
System.out.println();
/*
* Test getColumn method
* Output should be
* 1
* 4
* 7
* Status: Successful
*/
int[] col = p.getColumn(0);
for(int i = 0; i < col.length; i++) {
System.out.println(col[i]);
}
System.out.println();
/*
* Test noDuplicates method
* Output should be
* true
* Status: Successful
*/
int[] arr = {1, 2, 3, 4, 5};
System.out.println(p.noDuplicates(arr));
System.out.println();
/*
* Test containsOneToN method
* Output should be
* true
* Status: Successful
*/
int[] arr2 = {1, 2, 3, 4, 5};
System.out.println(p.containsOneToN(arr2));
/*
* Test meetsOrdinances method
* Output should be
* true
* Status: To be tested
*/
}
}
java homework sudoku
java homework sudoku
edited 2 hours ago
200_success
130k16153417
130k16153417
asked 10 hours ago
David WhiteDavid White
277413
277413
1
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
How can this code ever work ifmeetsOrdinances
saysYet to be implemented
?
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming thatmeetOrdinances
works as expected.
$endgroup$
– David White
1 hour ago
add a comment |
1
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
How can this code ever work ifmeetsOrdinances
saysYet to be implemented
?
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming thatmeetOrdinances
works as expected.
$endgroup$
– David White
1 hour ago
1
1
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
How can this code ever work if
meetsOrdinances
says Yet to be implemented
?$endgroup$
– Roland Illig
2 hours ago
$begingroup$
How can this code ever work if
meetsOrdinances
says Yet to be implemented
?$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming that
meetOrdinances
works as expected.$endgroup$
– David White
1 hour ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming that
meetOrdinances
works as expected.$endgroup$
– David White
1 hour ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214569%2fskyscraper-puzzle-solver-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214569%2fskyscraper-puzzle-solver-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
@200_success Yes, just edited the post to add the description.
$endgroup$
– David White
2 hours ago
$begingroup$
How can this code ever work if
meetsOrdinances
saysYet to be implemented
?$endgroup$
– Roland Illig
2 hours ago
$begingroup$
A puzzle solver by definition gets only the clues and then figures out the arrangement of the skyscrapers. I cannot find any code that does this.
$endgroup$
– Roland Illig
2 hours ago
$begingroup$
@RolandIllig This assignment in particular has both the skyscrapers and ordinances hardcoded, and just checks if the ordinances match the skyscraper. No user input is involved. And I'm just inquiring about the state of the code now, assuming that
meetOrdinances
works as expected.$endgroup$
– David White
1 hour ago