Hot answers tagged

7

To remove duplication, // check block 1 if (row >= 0 && col >= 0 && row <= 2 && col <= 2){ if(!isBlockValid(n, row, col, board, 0, 2, 0, 2)){ return false; } } you can rewrite these nine sections as this single block final int blockRow = 3 * (row / 3); final int blockCol = 3 * (col / 3)...


5

Protocol Well, first the good news. I don't see anything particularly wrong with the algorithms or parameters used. Class design This is a badly designed class with a lot of copy / paste going on (and I've found a clear indication for that at the end, where you copy code directly from this site). I'm not a big fan of static classes, and this one doesn't lend ...


4

I realise that this isn't as much of a review as a rewrite, but I still think it's on topic as an answer on this site as sometimes the right answer to your problem is to take a completely different approach that avoids the problems in the original attempt by design rather than tweaks. I wrote a sudoku solver a long time ago. One of the things I did to reduce ...


4

public static void load_Directory_Files(File directory) { File[] fileList = directory.listFiles(); if(fileList != null && fileList.length > 0){ for (int i=0; i<fileList.length; i++){ if(fileList[i].isDirectory()){ load_Directory_Files(fileList[i]); } else { String name = ...


3

Hi Nicholas and welcome to code review. A few things that I noticed in your code: The indentation isn't consistent. The closing bracket of menu isn't where it should be. The whole setAccountLocation method is one tab to far right. The readability of the code would be better if you'd fix that. In Eclipse, you can press Ctrl + Shift + F to automatically fix ...


3

Few suggestions: The class Gate is final, therefore all its methods are implicitly final, no need to specify the modifier on each method. Docs. The name Gate is a bit confusing because that class represents an input or output. One variable per declaration: private boolean value = false, force = false, forceValue = true; is not considered good practice. You ...


2

Always use the base class / interface in the left part of the variable when possible By setting the java.util.List interface in the variable part, this could make the code more refactorable in the future, since you could easily change the list type without changing everything (inheritance). Before private static ArrayList<String> storedCardNumbers = ...


2

One approach to unify all the various validity tests is to introduce what I'd call "groups": Each row is a group. Each column is a group. Each of the 3*3 blocks is a group. Each group consists of 9 cells, and can be represented by a list of 9 coordinates. You can create the 27 groups either by manually writing down the coordinate lists (tedious ...


2

Example for an IndexColorModel. /* START */ public static final class GUI { public static final Color BLACK = new Color(0x00, 0x00, 0x00); public static final Color MAROON = new Color(0x80, 0x00, 0x00); public static final Color GREEN = new Color(0x00, 0x80, 0x00); public static final Color OLIVE = new Color(0x80, 0x80, 0x00); ...


2

You could either use the real Java console, but that would mean you have to recreate your entire application. If you really insist to use Swing, I would do it in another way. Create some custom print() methode for printing ASCII-symbols into a buffered-image, scale this image and use it as background for just a single AWT/Swing component. After that you ...


1

In addition to your specific question on the isValid() methods, a few hints on code style, as this is the CodeReview site. Your solve() method is well done regarding its recursive calls, but it mixes computation and user interface (output) when it finally found the solution. In professional development, we separate these concerns as much as possible, e.g. to ...


1

In this answer, you are told that you can precompute the list of primes. But if space is not a concern, we can go further and precalculate the sums. Assuming we have an array prime such that prime[x] tells us if x is prime or not. long[] primeSumUpTo = new long[prime.length]; // this explicit initialization is not necessary as 0 is the default value ...


Only top voted, non community-wiki answers of a minimum length are eligible