Skip to content

Commit 82828cd

Browse files
committed
Slightly rearrange methods n VampireNumber moving important bits closer to the beginning
1 parent bdaf869 commit 82828cd

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/main/java/com/thealgorithms/maths/VampireNumber.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,10 @@
1313
* @see <a href='https://en.wikipedia.org/wiki/Vampire_number'>Vampire number on Wikipedia</a>
1414
*/
1515
public final class VampireNumber {
16+
// Forbid instantiation.
1617
private VampireNumber() {
1718
}
1819

19-
public static void main(String[] args) {
20-
printVampireNumbers(10, 1000, true);
21-
}
22-
23-
static void printVampireNumbers(int startValue, int stopValue, boolean ignorePseudoVampireNumbers) {
24-
int resultCounter = 0;
25-
26-
for (int i = startValue; i <= stopValue; i++) {
27-
for (int j = i; j <= stopValue; j++) {
28-
if (isVampireNumber(i, j, ignorePseudoVampireNumbers)) {
29-
resultCounter++;
30-
System.out.printf("%d: %d = %d * %d%n", resultCounter, i * j, i, j);
31-
}
32-
}
33-
}
34-
}
35-
3620
static boolean isVampireNumber(int a, int b, boolean ignorePseudoVampireNumbers) {
3721
// Pseudo vampire numbers don't have to be of n/2 digits. E.g., 126 = 6 x 21 is such a number.
3822
if (ignorePseudoVampireNumbers && String.valueOf(a).length() != String.valueOf(b).length()) {
@@ -61,4 +45,21 @@ static String splitIntoSortedDigits(int... nums) {
6145
digits.stream().sorted().forEach(res::append);
6246
return res.toString();
6347
}
48+
49+
static void printVampireNumbers(int startValue, int stopValue, boolean ignorePseudoVampireNumbers) {
50+
int resultCounter = 0;
51+
52+
for (int i = startValue; i <= stopValue; i++) {
53+
for (int j = i; j <= stopValue; j++) {
54+
if (isVampireNumber(i, j, ignorePseudoVampireNumbers)) {
55+
resultCounter++;
56+
System.out.printf("%d: %d = %d * %d%n", resultCounter, i * j, i, j);
57+
}
58+
}
59+
}
60+
}
61+
62+
public static void main(String[] args) {
63+
printVampireNumbers(10, 1000, true);
64+
}
6465
}

0 commit comments

Comments
 (0)