-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp090.java
More file actions
54 lines (45 loc) · 1.56 KB
/
p090.java
File metadata and controls
54 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package level04;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import lib.EulerTest;
public class p090 extends EulerTest {
final int N = 6;
final int B = 10;
/**
* Find the number of arrangements of two N-sided cubes with the numbers from 0 to B-1 such that
* all two-digit perfect squares can be displayed, where 6 and 9 are interchangeable.
*/
@Test
public void test() {
combinations(range(B), N).generate(cube1 -> {
combinations(range(B), N).generateUntil(cube2 -> {
if (good(cube1, cube2))
ans++;
return cube1.equals(cube2);
});
});
check(1217);
}
boolean good(List<Integer> cube1, List<Integer> cube2) {
Set<Integer> possibleDigits1 = getPossibleDigits(cube1);
Set<Integer> possibleDigits2 = getPossibleDigits(cube2);
for (int i : range(1, B)) {
int digit1 = isq(i) / B, digit2 = isq(i) % B;
if (possibleDigits1.contains(digit1) && possibleDigits2.contains(digit2))
continue;
if (possibleDigits1.contains(digit2) && possibleDigits2.contains(digit1))
continue;
return false;
}
return true;
}
Set<Integer> getPossibleDigits(List<Integer> cube) {
Set<Integer> possibleDigits = set(cube);
if (possibleDigits.contains(6))
possibleDigits.add(9);
else if (possibleDigits.contains(9))
possibleDigits.add(6);
return possibleDigits;
}
}