Largest palindrome product: Difference between revisions

→‎{{header|Go}}: Optimized as per Wren - cuts run time in half.
(→‎{{header|Wren}}: Optimized inner loop - run time now less than 0.7 seconds.)
(→‎{{header|Go}}: Optimized as per Wren - cuts run time in half.)
Line 19:
=={{header|Go}}==
{{trans|Wren}}
18 digit integers are within the range of Go's uint64 type though finding the result for 9-digit number products takes a while - around 3015 seconds on my machine.
<lang go>package main
 
Line 44:
j := reverse(i)
p := i*pow + j
// allwe palindromicassume numbershere withthe anpalindromes evenwill numberend of digits are divisible by 11in 9
//if andp%10 we!= assume9 here will end in 9{
if p%11 != 0 || p%10 != 9 {
continue
}
for// k :=can't high;be keven >=nor low+1;end k--in 5 to produce a product ending in {9
for k := high; k > low; k -= 2 {
if p%11 != 0 ||if k p% 10 !== 95 {
continue
}
l := p / k
if l > high {
9,479

edits