Largest palindrome product: Difference between revisions

m
→‎Stretch: changed output format
(→‎{{header|C#|CSharp}}: added stretch)
m (→‎Stretch: changed output format)
Line 190:
 
===Stretch===
Showing results for 2 through 10 digit factors.
<lang csharp>using System;
 
Line 223 ⟶ 222:
if (isPal(p)) {
if (p > bp) bp = p;
bs = string.Format(" {0,2} {1,10} x {12,-10} = {23}{4}", n, y, z - c, new string(' ', 10 - n), bp); }
p -= yy; c += 10; }
y -= ld == 7 ? 44 : 22; }
Line 229 ⟶ 228:
 
static void Main(string[] args) {
Console.WriteLine("digs factor factor palindrome");
var sw = System.Diagnostics.Stopwatch.StartNew();
for (int i = 2, h = 1; i <= 10; h = ++i >> 1) {
Line 235:
a = new string('9', h) + new string('0', (h) - 1) + "1",
c = new string('9', h) + new string('0', i) + new string('9', h);
Console.WriteLine(" {0,2} {1,10} x {12,-10} = {23}{4}", i, a, b, new string(' ', 10 - i), c); }
else doOne(i);
}
Line 243:
}</lang>
{{out|Output @ Tio.run}}
Showing results for 2 through 10 digit factors.
<pre>91 x 99 = 9009
<pre>digs factor factor palindrome
913 x 993 = 906609
2 91 x 99 = 9009
9901 x 9999 = 99000099
3 913 x 993 = 906609
99979 x 99681 = 9966006699
4 9901 x 9999 = 99000099
999001 x 999999 = 999000000999
5 99979 x 99681 = 9966006699
9997647 x 9998017 = 99956644665999
6 999001 x 999999 = 999000000999
99990001 x 99999999 = 9999000000009999
7 9997647 x 9998017 = 99956644665999
999920317 x 999980347 = 999900665566009999
8 99990001 x 99999999 = 9999000000009999
9999900001 x 9999999999 = 99999000000000099999
9 999920317 x 999980347 = 999900665566009999
2.2502339 sec</pre>Wow! how did that go so fast? The results for the even-number-of-digit factors were manufactured by string manipulation instead of calculation (since the pattern was obvious). This algorithm can easily be adapted to BigIntegers for higher n-digit factors, but the execution time is unspectacular.
10 9999900001 x 9999999999 = 99999000000000099999
2.25023391622142 sec</pre>Wow! how did that go so fast? The results for the even-number-of-digit factors were manufactured by string manipulation instead of calculation (since the pattern was obvious). This algorithm can easily be adapted to BigIntegers for higher n-digit factors, but the execution time is unspectacular.
 
=={{header|F_Sharp|F#}}==