FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Project-Euler/Problem004.js at master · ArduinoAficionado/JavaScript · GitHub
ArduinoAficionado
/
JavaScript
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Project-Euler
/
Problem004.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (41 loc) · 1.16 KB
Breadcrumbs
JavaScript
/
Project-Euler
/
Problem004.js
Copy path
File metadata and controls
44 lines (41 loc) · 1.16 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://projecteuler.net/problem=4
/* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
*/
export
const
largestPalindromic
=
(
digits
)
=>
{
let
i
let
n
let
m
let
d
let
limit
let
number
=
0
for
(
i
=
1
;
i
<
digits
;
i
++
)
{
number
=
10
*
number
+
9
}
const
inf
=
number
// highest (digits - 1) number, in this example highest 2 digit number
const
sup
=
10
*
number
+
9
// highest (digits) number, in this example highest 3 digit number
const
isPalindromic
=
(
n
)
=>
{
let
p
=
0
const
q
=
n
let
r
while
(
n
>
0
)
{
r
=
n
%
10
p
=
10
*
p
+
r
n
=
Math
.
floor
(
n
/
10
)
}
return
p
===
q
// returning whether the number is palindromic or not
}
for
(
n
=
sup
*
sup
,
m
=
inf
*
inf
;
n
>
m
;
n
--
)
{
if
(
isPalindromic
(
n
)
)
{
limit
=
Math
.
ceil
(
Math
.
sqrt
(
n
)
)
d
=
sup
while
(
d
>=
limit
)
{
if
(
n
%
d
===
0
&&
n
/
d
>
inf
)
{
return
n
}
d
-=
1
}
}
}
return
NaN
// returning not a number, if any such case arise
}
Back
|
FazBrowse Home
|
New Git URL