Skip to content

Commit bba9bc1

Browse files
committed
Remove U.shortestPathAllKeys(grid).
1 parent 7e3fb81 commit bba9bc1

File tree

3 files changed

+24
-111
lines changed

3 files changed

+24
-111
lines changed

pom-pack.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36-
<java.home.openjdk11>../../programs/jdk-10</java.home.openjdk11>
36+
<java.home.openjdk11>../../programs/jdk-10.0.2</java.home.openjdk11>
3737
</properties>
3838

3939
<ciManagement>

src/main/java/com/github/underscore/lodash/U.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,100 +1925,6 @@ public static <T> List<List<T>> createPermutationWithRepetition(final List<T> li
19251925
return result;
19261926
}
19271927

1928-
public static class Status {
1929-
private final int key;
1930-
private final int x;
1931-
private final int y;
1932-
public Status(int key, int x, int y) {
1933-
this.key = key;
1934-
this.x = x;
1935-
this.y = y;
1936-
}
1937-
public int getKey() {
1938-
return key;
1939-
}
1940-
public int getX() {
1941-
return x;
1942-
}
1943-
public int getY() {
1944-
return y;
1945-
}
1946-
}
1947-
1948-
public static List<Status> shortestPathAllKeys(String[] grid) {
1949-
int success = 0;
1950-
int startI = 0;
1951-
int startJ = 0;
1952-
int rows = grid.length;
1953-
int cols = grid[0].length();
1954-
List<Status> result = newArrayList();
1955-
for (int i = 0; i < rows; i++) {
1956-
for (int j = 0; j < cols; j++) {
1957-
char c = grid[i].charAt(j);
1958-
if (c >= 'A' && c <= 'F') {
1959-
success |= 1 << (c - 'A');
1960-
}
1961-
if (c == '@') {
1962-
startI = i;
1963-
startJ = j;
1964-
}
1965-
}
1966-
}
1967-
int[][][] dist = new int[1 << 6][rows][cols];
1968-
for (int i = 0; i < dist.length; i++) {
1969-
for (int j = 0; j < dist[0].length; j++) {
1970-
for (int k = 0; k < dist[0][0].length; k++) {
1971-
dist[i][j][k] = Integer.MAX_VALUE;
1972-
}
1973-
}
1974-
}
1975-
Queue<Status> queue = new LinkedList<Status>();
1976-
queue.offer(new Status(0, startI, startJ));
1977-
dist[0][startI][startJ] = 0;
1978-
return scanDirs(queue, success, result, rows, cols, grid, dist);
1979-
}
1980-
1981-
private static List<Status> scanDirs(Queue<Status> queue, int success, List<Status> result,
1982-
int rows, int cols, String[] grid, int[][][] dist) {
1983-
int path = 0;
1984-
int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
1985-
while (!queue.isEmpty()) {
1986-
int size = queue.size();
1987-
while (size-- > 0) {
1988-
Status status = queue.poll();
1989-
int key = status.getKey();
1990-
int x = status.getX();
1991-
int y = status.getY();
1992-
if (key == success) {
1993-
return result;
1994-
}
1995-
for (int[] dir : dirs) {
1996-
int xx = x + dir[0];
1997-
int yy = y + dir[1];
1998-
if (xx >= 0 && xx < rows && yy >= 0 && yy < cols && grid[xx].charAt(yy) != '#') {
1999-
int nextKey = key;
2000-
char c = grid[xx].charAt(yy);
2001-
if (c >= 'a' && c <= 'f') {
2002-
nextKey = key | (1 << (c - 'a'));
2003-
}
2004-
if (c >= 'A' && c <= 'F' && (nextKey & (1 << (c - 'A'))) == 0) {
2005-
continue;
2006-
}
2007-
if (path + 1 < dist[nextKey][xx][yy]) {
2008-
dist[nextKey][xx][yy] = path + 1;
2009-
queue.offer(new Status(nextKey, xx, yy));
2010-
}
2011-
}
2012-
}
2013-
}
2014-
path++;
2015-
if (!queue.isEmpty()) {
2016-
result.add(queue.element());
2017-
}
2018-
}
2019-
return result;
2020-
}
2021-
20221928
public List<List<T>> createPermutationWithRepetition(final int permutationLength) {
20231929
return createPermutationWithRepetition((List<T>) value(), permutationLength);
20241930
}

src/test/java/com/github/underscore/lodash/MathTest.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public Byte apply(final Byte item) {
5757
});
5858
assertNull(resultFunc2);
5959
assertEquals("2.0", result.toString());
60+
}
61+
62+
@Test
63+
public void average2() {
6064
final Double result2 = U.average(asList((double) 1, (double) 2, (double) 3));
6165
assertEquals("2.0", result2.toString());
6266
final Double result3 = U.average(asList((float) 1, (float) 2, (float) 3));
@@ -73,6 +77,10 @@ public Byte apply(final Byte item) {
7377
assertEquals("2.0", result8.toString());
7478
final Double result9 = U.average(asList((Integer) null));
7579
assertNull(result9);
80+
}
81+
82+
@Test
83+
public void average3() {
7684
final Double result10 = U.average(asList(1, (Integer) null));
7785
assertEquals("0.5", result10.toString());
7886
final Double result11 = U.average(asList((double) 0.2, (double) 0.1, Math.PI));
@@ -94,6 +102,10 @@ public Byte apply(final Byte item) {
94102
final Double result19 = U.average(new BigInteger[] {BigInteger.valueOf(1), BigInteger.valueOf(2),
95103
BigInteger.valueOf(3)});
96104
assertEquals("2.0", result19.toString());
105+
}
106+
107+
@Test
108+
public void average4() {
97109
final Double result20 = U.average(new BigDecimal[] {BigDecimal.valueOf(1), BigDecimal.valueOf(2),
98110
BigDecimal.valueOf(3)});
99111
assertEquals("2.0", result20.toString());
@@ -113,6 +125,10 @@ public Byte apply(final Byte item) {
113125
assertNull(result27);
114126
final Double result28 = U.average(null, (byte) 1);
115127
assertNull(result28);
128+
}
129+
130+
@Test
131+
public void average5() {
116132
final Double result29 = U.average((byte) 2, (byte) 4);
117133
assertEquals("3.0", result29.toString());
118134
final Double result30 = U.average(Double.valueOf(2), null);
@@ -129,6 +145,10 @@ public Byte apply(final Byte item) {
129145
assertEquals("3.0", result35.toString());
130146
final Double result36 = U.average(Integer.valueOf(2), null);
131147
assertNull(result36);
148+
}
149+
150+
@Test
151+
public void average6() {
132152
final Double result37 = U.average(null, Integer.valueOf(2));
133153
assertNull(result37);
134154
final Double result38 = U.average(Integer.valueOf(2), Integer.valueOf(4));
@@ -140,7 +160,7 @@ public Byte apply(final Byte item) {
140160
final Double result41 = U.average(Long.valueOf(2), Long.valueOf(4));
141161
assertEquals("3.0", result41.toString());
142162
final Double result42 = U.average(Long.valueOf(2), Long.valueOf(4));
143-
assertEquals("3.0", result41.toString());
163+
assertEquals("3.0", result42.toString());
144164
final Double result43 = U.average(new Integer[] {(Integer) null});
145165
assertNull(result43);
146166
}
@@ -269,8 +289,8 @@ public void subtract() {
269289
assertEquals("-1", U.subtract(Long.valueOf(1), Long.valueOf(2)).toString());
270290
assertEquals("-1.0", U.subtract(Float.valueOf(1), Float.valueOf(2)).toString());
271291
assertEquals("-1.0", U.subtract(Double.valueOf(1), Double.valueOf(2)).toString());
272-
assertEquals("-1", U.subtract(java.math.BigDecimal.valueOf(1), java.math.BigDecimal.valueOf(2)).toString());
273-
assertEquals("-1", U.subtract(java.math.BigInteger.valueOf(1), java.math.BigInteger.valueOf(2)).toString());
292+
assertEquals("-1", U.subtract(BigDecimal.valueOf(1), BigDecimal.valueOf(2)).toString());
293+
assertEquals("-1", U.subtract(BigInteger.valueOf(1), BigInteger.valueOf(2)).toString());
274294
assertEquals("-1", U.subtract((Number) 1, (Number) 2).toString());
275295
assertEquals("-4", U.subtract((int) 1, (int) 2, (int) 3).toString());
276296
assertEquals("1", U.subtract((int) 1).toString());
@@ -416,19 +436,6 @@ public void createPermutationWithRepetition() {
416436
+ " [orange, orange, orange]]", resultChain.toString());
417437
}
418438

419-
@Test
420-
public void shortestPathAllKeys() {
421-
List<U.Status> statuses = U.shortestPathAllKeys(new String[] {"@.a.#", "###.#", "b.A.B"});
422-
assertEquals(8, statuses.size());
423-
assertEquals(0, statuses.get(0).getX());
424-
assertEquals(1, statuses.get(0).getY());
425-
assertEquals(2, statuses.get(7).getX());
426-
assertEquals(0, statuses.get(7).getY());
427-
assertEquals(6, U.shortestPathAllKeys(new String[] {"@..aA", "..B#.", "....b"}).size());
428-
assertEquals(5, U.shortestPathAllKeys(new String[] {"g...#", "###.#", "..A.B"}).size());
429-
assertEquals(0, U.shortestPathAllKeys(new String[] {"#####", "#####", "#####"}).size());
430-
}
431-
432439
@SuppressWarnings("unchecked")
433440
@Test
434441
public void main() {

0 commit comments

Comments
 (0)