Pages

23/01/2026

[Source code] Determine to which subsquare does a cell belong to in a sudoku grid

Given a valid sudoku grid of size NxN, we might need to determine (for example for validation purposes), in which subsquare a specific cell belongs:

int squareIndex = (i / subsquareSize) * subsquareSize + (j / subsquareSize);

where subsquareSize = Math.sqrt(N);

[Maven] Replace backslashes in property

Using Maven to build code on both Windows and Unix systems, you might end up with some quirky situations especially related to file path handling.

It is possible to generate altered Maven properties so that for example backslashes are converted to forward slashes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>normalize-property</id>
      <phase>initialize</phase>
      <goals>
        <goal>regex-property</goal>
      </goals>
      <configuration>
        <name>normalized.property</name>
        <value>${property}</value>
        <regex>\\</regex>
        <replacement>/</replacement>
      </configuration>
    </execution>
  </executions>
</plugin>

This can be used to alter properties that are not directly controlled by the developer, such as ${project.baseDir}, and then you can use the result as a property itself: ${normalized.property}