FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ProjectEuler-Java/Sol55.java at master · JoshP/ProjectEuler-Java · GitHub
JoshP
ProjectEuler-Java
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ProjectEuler-Java
/
Sol55.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (27 loc) · 854 Bytes
Breadcrumbs
ProjectEuler-Java
/
Sol55.java
Copy path
File metadata and controls
31 lines (27 loc) · 854 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.*;
import
java
.
math
.*;
public
class
Sol55
extends
BaseSolution
{
public
void
runSolution
() {
int
count
=
0
;
for
(
int
i
=
1
;
i
<
10000
;
i
++) {
if
(
isLychrel
(
i
)) {
count
++;
System
.
out
.
println
(
i
+
" was lychrel"
);
}
}
System
.
out
.
println
(
count
);
}
public
boolean
isLychrel
(
int
num
) {
BigInteger
bigNum
=
BigInteger
.
valueOf
(
num
);
for
(
int
i
=
0
;
i
<
50
;
i
++) {
bigNum
=
bigNum
.
add
(
reverse
(
bigNum
));
if
(
Util
.
isPalindrome
(
bigNum
.
toString
()))
return
false
;
}
return
true
;
}
public
BigInteger
reverse
(
BigInteger
num
) {
StringBuilder
builder
=
new
StringBuilder
(
num
.
toString
());
return
new
BigInteger
(
builder
.
reverse
().
toString
());
}
}
Back
|
FazBrowse Home
|
New Git URL