Largest palindrome product: Difference between revisions
Content added Content deleted
(→{{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: | Line 19: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{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 |
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 15 seconds on my machine. |
||
<lang go>package main |
<lang go>package main |
||
Line 44: | Line 44: | ||
j := reverse(i) |
j := reverse(i) |
||
p := i*pow + j |
p := i*pow + j |
||
// |
// we assume here the palindromes will end in 9 |
||
if p%10 != 9 { |
|||
⚫ | |||
continue |
continue |
||
} |
} |
||
// k can't be even nor end in 5 to produce a product ending in 9 |
|||
for k := high; k > low; k -= 2 { |
|||
⚫ | |||
continue |
|||
} |
|||
l := p / k |
l := p / k |
||
if l > high { |
if l > high { |