Permuted multiples: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed some comments.) |
(→{{header|Phix}}: added final steps and extended output) |
||
Line 378: | Line 378: | ||
<!--<lang Phix>(phixonline)--> |
<!--<lang Phix>(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span> |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n10</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">steps</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> |
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n10</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">steps</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">fmt</span><span style="color: #0000FF;">=</span><span style="color: #008000;">""" |
|||
%s positive integer n for which (2..6)*n contain the same digits: |
|||
n = %,d (%,d steps, hmmm...) |
|||
2 x n = %,d |
|||
3 x n = %,d |
|||
4 x n = %,d |
|||
5 x n = %,d |
|||
6 x n = %,d |
|||
"""</span><span style="color: #0000FF;">,</span> |
|||
<span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">?</span><span style="color: #000000;">1e7</span><span style="color: #0000FF;">:</span><span style="color: #000000;">1e9</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">nowtelse</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Nothing"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">smother</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Smallest"</span> |
|||
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> |
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> |
||
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">*</span><span style="color: #000000;">6</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">n10</span> <span style="color: #008080;">then</span> |
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">*</span><span style="color: #000000;">6</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">n10</span> <span style="color: #008080;">then</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s less than %,d (%,d steps)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">nowtelse</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">steps</span><span style="color: #0000FF;">})</span> |
||
<span style="color: #008080;">if</span> <span style="color: #000000;">n10</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">limit</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span> |
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span> |
||
<span style="color: #000000;">n10</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span> |
<span style="color: #000000;">n10</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span> |
||
Line 392: | Line 405: | ||
<span style="color: #008080;">if</span> <span style="color: #000000;">ins</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">ns</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">if</span> <span style="color: #000000;">ins</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">ns</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">7</span> <span style="color: #008080;">then |
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">7</span> <span style="color: #008080;">then</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">smother</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">steps</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">&</span> <span style="color: #7060A8;">sq_mul</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)))</span> |
|||
<span style="color: #000000;">nowtelse</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Nothing else"</span> |
|||
<span style="color: #000000;">smother</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Another"</span> |
|||
<span style="color: #008080;">exit</span> <span style="color: #000080;font-style:italic;">-- (see below)</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">3</span> |
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">3</span> |
||
<span style="color: #000000;">steps</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
<span style="color: #000000;">steps</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
||
<span style="color: # |
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span> |
||
Smallest positive integer n for which (2..6)*n contain the same digits: |
|||
n = %d |
|||
2 x n = %d |
|||
3 x n = %d |
|||
4 x n = %d |
|||
5 x n = %d |
|||
6 x n = %d |
|||
"""</span> |
|||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sq_mul</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)))</span> |
|||
<!--</lang>--> |
<!--</lang>--> |
||
{{out}} |
{{out}} |
||
Line 416: | Line 425: | ||
Nothing less than 100,000 (2,222 steps) |
Nothing less than 100,000 (2,222 steps) |
||
Smallest positive integer n for which (2..6)*n contain the same digits: |
Smallest positive integer n for which (2..6)*n contain the same digits: |
||
n = |
n = 142,857 (14,285 steps, hmmm...) |
||
2 x n = |
2 x n = 285,714 |
||
3 x n = |
3 x n = 428,571 |
||
4 x n = |
4 x n = 571,428 |
||
5 x n = |
5 x n = 714,285 |
||
6 x n = |
6 x n = 857,142 |
||
"0.1s" |
|||
</pre> |
|||
=== extended output === |
|||
If we comment out that "exit -- (see below)", as per the AppleScript comments and the Pascal output, |
|||
some patterns start to emerge in the values and number of steps: *10 is a bit of a given, whereas |
|||
"insert 9s before the 8" is (for me) a bit more unexpected. Be warned: on the desktop, 1e8 takes |
|||
about 9s, 1e9 about 90s, so I'll predict 1e10 would take 15mins (and need 64bit) and I'll not try |
|||
to compete with Pascal in terms of performance, though I am getting very different results above 1e7. |
|||
Under pwa/p2js 1e8 takes about 30s (meh) so I've limited it to 1e7 (2.3s). |
|||
<pre> |
|||
Nothing else less than 1,000,000 (22,222 steps) |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 1,428,570 (142,856 steps, hmmm...) |
|||
2 x n = 2,857,140 |
|||
3 x n = 4,285,710 |
|||
4 x n = 5,714,280 |
|||
5 x n = 7,142,850 |
|||
6 x n = 8,571,420 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 1,429,857 (143,285 steps, hmmm...) |
|||
2 x n = 2,859,714 |
|||
3 x n = 4,289,571 |
|||
4 x n = 5,719,428 |
|||
5 x n = 7,149,285 |
|||
6 x n = 8,579,142 |
|||
Nothing else less than 10,000,000 (222,222 steps) |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 14,285,700 (1,428,566 steps, hmmm...) |
|||
2 x n = 28,571,400 |
|||
3 x n = 42,857,100 |
|||
4 x n = 57,142,800 |
|||
5 x n = 71,428,500 |
|||
6 x n = 85,714,200 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 14,298,570 (1,432,856 steps, hmmm...) |
|||
2 x n = 28,597,140 |
|||
3 x n = 42,895,710 |
|||
4 x n = 57,194,280 |
|||
5 x n = 71,492,850 |
|||
6 x n = 85,791,420 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 14,299,857 (1,433,285 steps, hmmm...) |
|||
2 x n = 28,599,714 |
|||
3 x n = 42,899,571 |
|||
4 x n = 57,199,428 |
|||
5 x n = 71,499,285 |
|||
6 x n = 85,799,142 |
|||
Nothing else less than 100,000,000 (2,222,222 steps) |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 142,857,000 (14,285,666 steps, hmmm...) |
|||
2 x n = 285,714,000 |
|||
3 x n = 428,571,000 |
|||
4 x n = 571,428,000 |
|||
5 x n = 714,285,000 |
|||
6 x n = 857,142,000 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 142,985,700 (14,328,566 steps, hmmm...) |
|||
2 x n = 285,971,400 |
|||
3 x n = 428,957,100 |
|||
4 x n = 571,942,800 |
|||
5 x n = 714,928,500 |
|||
6 x n = 857,914,200 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 142,998,570 (14,332,856 steps, hmmm...) |
|||
2 x n = 285,997,140 |
|||
3 x n = 428,995,710 |
|||
4 x n = 571,994,280 |
|||
5 x n = 714,992,850 |
|||
6 x n = 857,991,420 |
|||
Another positive integer n for which (2..6)*n contain the same digits: |
|||
n = 142,999,857 (14,333,285 steps, hmmm...) |
|||
2 x n = 285,999,714 |
|||
3 x n = 428,999,571 |
|||
4 x n = 571,999,428 |
|||
5 x n = 714,999,285 |
|||
6 x n = 857,999,142 |
|||
Nothing else less than 1,000,000,000 (22,222,222 steps) |
|||
</pre> |
</pre> |
||