Skip to content

Commit

Permalink
test/euler.jl: slightly faster euler #4 algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jan 3, 2014
1 parent b3c70b0 commit 4463e9f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ end
#4: 906609
function euler4(n)
m = 1
for a=10^n-1:-1:10^(n-1),
b=10^n-1:-1:max(a,-fld(-m,a))
p = a*b
d = digits(p)
d == reverse(d) || continue
m = max(m,p)
for a = 10^n-1:-1:10^(n-1)
for b = 10^n-1:-1:max(a,-fld(-m,a))
p = a*b
d = digits(p)
if d == reverse(d) && p > m
m = p
b < -fld(-m,a) && break
end
end
end
return m
end
Expand Down

2 comments on commit 4463e9f

@jiahao
Copy link
Member

@jiahao jiahao commented on 4463e9f Jan 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful with issue cross-referencing in title

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah. I feel like GitHub issues should start numbering at 100 because of this.

Please sign in to comment.