forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp055.java
More file actions
39 lines (30 loc) · 821 Bytes
/
p055.java
File metadata and controls
39 lines (30 loc) · 821 Bytes
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
/*
* Solution to Project Euler problem 55
* Copyright (c) Project Nayuki. All rights reserved.
*
* https://www.nayuki.io/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
import java.math.BigInteger;
public final class p055 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p055().run());
}
public String run() {
int count = 0;
for (int i = 0; i < 10000; i++) {
if (isLychrel(i))
count++;
}
return Integer.toString(count);
}
private static boolean isLychrel(int n) {
BigInteger temp = BigInteger.valueOf(n);
for (int i = 0; i < 49; i++) {
temp = temp.add(new BigInteger(Library.reverse(temp.toString())));
if (Library.isPalindrome(temp.toString()))
return false;
}
return true;
}
}