Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@@ -27,23 +27,39 @@ public final class LinearDiophantineEquationsSolver {
return toReturn;
}
private static GcdSolutionWrapper gcd(final int a, final int b, final GcdSolutionWrapper previous) {
private static GcdSolutionWrapper gcd(
final int a,
final int b,
final GcdSolutionWrapper previous
) {
if (b == 0) {
return new GcdSolutionWrapper(a, new Solution(1, 0));
}
// stub wrapper becomes the `previous` of the next recursive call
final var stubWrapper = new GcdSolutionWrapper(0, new Solution(0, 0));
final var next = /* recursive call */ gcd(b, a % b, stubWrapper);
final var next = /* recursive call */gcd(b, a % b, stubWrapper);
previous.getSolution().setX(next.getSolution().getY());
previous.getSolution().setY(next.getSolution().getX() - (a / b) * (next.getSolution().getY()));
previous
.getSolution()
.setY(
next.getSolution().getX() -
(a / b) *
(next.getSolution().getY())
);
previous.setGcd(next.getGcd());
return new GcdSolutionWrapper(next.getGcd(), previous.getSolution());
}
public static final class Solution {
public static final Solution NO_SOLUTION = new Solution(Integer.MAX_VALUE, Integer.MAX_VALUE);
public static final Solution INFINITE_SOLUTIONS = new Solution(Integer.MIN_VALUE, Integer.MIN_VALUE);
public static final Solution NO_SOLUTION = new Solution(
Integer.MAX_VALUE,
Integer.MAX_VALUE
);
public static final Solution INFINITE_SOLUTIONS = new Solution(
Integer.MIN_VALUE,
Integer.MIN_VALUE
);
private int x;
private int y;
@@ -77,8 +93,7 @@ public final class LinearDiophantineEquationsSolver {
return false;
}
var that = (Solution) obj;
return this.x == that.x
&& this.y == that.y;
return this.x == that.x && this.y == that.y;
}
@Override
@@ -88,16 +103,11 @@ public final class LinearDiophantineEquationsSolver {
@Override
public String toString() {
return "Solution["
+ "x=" + x + ", "
+ "y=" + y + ']';
return "Solution[" + "x=" + x + ", " + "y=" + y + ']';
}
}
public record Equation(int a, int b, int c) {
}
public record Equation(int a, int b, int c) {}
public static final class GcdSolutionWrapper {
@@ -118,8 +128,10 @@ public final class LinearDiophantineEquationsSolver {
return false;
}
var that = (GcdSolutionWrapper) obj;
return this.gcd == that.gcd
&& Objects.equals(this.solution, that.solution);
return (
this.gcd == that.gcd &&
Objects.equals(this.solution, that.solution)
);
}
public int getGcd() {
@@ -145,10 +157,15 @@ public final class LinearDiophantineEquationsSolver {
@Override
public String toString() {
return "GcdSolutionWrapper["
+ "gcd=" + gcd + ", "
+ "solution=" + solution + ']';
return (
"GcdSolutionWrapper[" +
"gcd=" +
gcd +
", " +
"solution=" +
solution +
']'
);
}
}
}