mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Format code with prettier (#3375)
This commit is contained in:
@@ -35,23 +35,34 @@ public class Verhoeff {
|
||||
* Dihedral group</a>
|
||||
*/
|
||||
private static final byte[][] MULTIPLICATION_TABLE = {
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
{1, 2, 3, 4, 0, 6, 7, 8, 9, 5},
|
||||
{2, 3, 4, 0, 1, 7, 8, 9, 5, 6},
|
||||
{3, 4, 0, 1, 2, 8, 9, 5, 6, 7},
|
||||
{4, 0, 1, 2, 3, 9, 5, 6, 7, 8},
|
||||
{5, 9, 8, 7, 6, 0, 4, 3, 2, 1},
|
||||
{6, 5, 9, 8, 7, 1, 0, 4, 3, 2},
|
||||
{7, 6, 5, 9, 8, 2, 1, 0, 4, 3},
|
||||
{8, 7, 6, 5, 9, 3, 2, 1, 0, 4},
|
||||
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
||||
{ 1, 2, 3, 4, 0, 6, 7, 8, 9, 5 },
|
||||
{ 2, 3, 4, 0, 1, 7, 8, 9, 5, 6 },
|
||||
{ 3, 4, 0, 1, 2, 8, 9, 5, 6, 7 },
|
||||
{ 4, 0, 1, 2, 3, 9, 5, 6, 7, 8 },
|
||||
{ 5, 9, 8, 7, 6, 0, 4, 3, 2, 1 },
|
||||
{ 6, 5, 9, 8, 7, 1, 0, 4, 3, 2 },
|
||||
{ 7, 6, 5, 9, 8, 2, 1, 0, 4, 3 },
|
||||
{ 8, 7, 6, 5, 9, 3, 2, 1, 0, 4 },
|
||||
{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* The inverse table {@code inv}. Represents the multiplicative inverse of a
|
||||
* digit, that is, the value that satisfies {@code d(j, inv(j)) = 0}.
|
||||
*/
|
||||
private static final byte[] MULTIPLICATIVE_INVERSE = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};
|
||||
private static final byte[] MULTIPLICATIVE_INVERSE = {
|
||||
0,
|
||||
4,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
};
|
||||
|
||||
/**
|
||||
* The permutation table {@code p}. Applies a permutation to each digit
|
||||
@@ -60,14 +71,14 @@ public class Verhoeff {
|
||||
* {@code p(i+j,n) = p(i, p(j,n))}.
|
||||
*/
|
||||
private static final byte[][] PERMUTATION_TABLE = {
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
{1, 5, 7, 6, 2, 8, 3, 0, 9, 4},
|
||||
{5, 8, 0, 3, 7, 9, 6, 1, 4, 2},
|
||||
{8, 9, 1, 6, 0, 4, 3, 5, 2, 7},
|
||||
{9, 4, 5, 3, 1, 2, 6, 8, 7, 0},
|
||||
{4, 2, 8, 6, 5, 7, 3, 9, 0, 1},
|
||||
{2, 7, 9, 3, 8, 0, 6, 4, 1, 5},
|
||||
{7, 0, 4, 6, 9, 1, 3, 2, 5, 8}
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
||||
{ 1, 5, 7, 6, 2, 8, 3, 0, 9, 4 },
|
||||
{ 5, 8, 0, 3, 7, 9, 6, 1, 4, 2 },
|
||||
{ 8, 9, 1, 6, 0, 4, 3, 5, 2, 7 },
|
||||
{ 9, 4, 5, 3, 1, 2, 6, 8, 7, 0 },
|
||||
{ 4, 2, 8, 6, 5, 7, 3, 9, 0, 1 },
|
||||
{ 2, 7, 9, 3, 8, 0, 6, 4, 1, 5 },
|
||||
{ 7, 0, 4, 6, 9, 1, 3, 2, 5, 8 },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -137,26 +148,32 @@ public class Verhoeff {
|
||||
|
||||
private static void checkAndPrint(String input) {
|
||||
String validationResult = Verhoeff.verhoeffCheck(input)
|
||||
? "valid"
|
||||
: "not valid";
|
||||
? "valid"
|
||||
: "not valid";
|
||||
System.out.println("Input '" + input + "' is " + validationResult);
|
||||
}
|
||||
|
||||
private static void generateAndPrint(String input) {
|
||||
String result = addVerhoeffChecksum(input);
|
||||
System.out.println("Generate and add checksum to initial value '" + input + "'. Result: '" + result + "'");
|
||||
System.out.println(
|
||||
"Generate and add checksum to initial value '" +
|
||||
input +
|
||||
"'. Result: '" +
|
||||
result +
|
||||
"'"
|
||||
);
|
||||
}
|
||||
|
||||
private static void checkInput(String input) {
|
||||
Objects.requireNonNull(input);
|
||||
if (!input.matches("\\d+")) {
|
||||
throw new IllegalArgumentException("Input '" + input + "' contains not only digits");
|
||||
throw new IllegalArgumentException(
|
||||
"Input '" + input + "' contains not only digits"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] toIntArray(String string) {
|
||||
return string.chars()
|
||||
.map(i -> Character.digit(i, 10))
|
||||
.toArray();
|
||||
return string.chars().map(i -> Character.digit(i, 10)).toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user