Largest palindrome product: Difference between revisions
→{{header|Go}}: Updated in line with Wren example.
(→{{header|Wren}}: Much better approach.) |
(→{{header|Go}}: Updated in line with Wren example.) |
||
Line 9:
=={{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 30 seconds on my machine.
<lang go>package main
Line 26:
pow := uint64(10)
nextN:
for n := 2; n <
low := pow *
pow *= 10
high := pow - 1
fmt.Printf("Largest palindromic product of two %d-digit integers: ", n)
for
// all palindromic numbers are divisible by 11 and we assume here will end in 9
if p%11 != 0 || p%10 != 9 {
continue
}
for
if
break
}
if p%
continue
▲ }
}
}
Line 58 ⟶ 59:
Largest palindromic product of two 5-digit integers: 99979 x 99681 = 9966006699
Largest palindromic product of two 6-digit integers: 999999 x 999001 = 999000000999
Largest palindromic product of two 7-digit integers: 9998017 x 9997647 = 99956644665999
Largest palindromic product of two 8-digit integers: 99999999 x 99990001 = 9999000000009999
Largest palindromic product of two 9-digit integers: 999980347 x 999920317 = 999900665566009999
</pre>
|