Anaprimes: Difference between revisions
Content deleted Content added
→{{header|Go}}: Tweak. |
m →{{header|Phix}}: use faster sig method |
||
Line 348: | Line 348: | ||
<span style="color: #004080;">integer</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e2</span><span style="color: #0000FF;">))+</span><span style="color: #000000;">1</span> |
<span style="color: #004080;">integer</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e2</span><span style="color: #0000FF;">))+</span><span style="color: #000000;">1</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;">"Largest anagram groups:\n"</span><span style="color: #0000FF;">)</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;">"Largest anagram groups:\n"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">for</span> <span style="color: #000000;">pow10</span><span style="color: #0000FF;">=</span><span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">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;"> |
<span style="color: #008080;">for</span> <span style="color: #000000;">pow10</span><span style="color: #0000FF;">=</span><span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">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;">8</span><span style="color: #0000FF;">:</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> |
||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"getting_primes...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">--(~ |
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"getting_primes...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (~15s in total)</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">primes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pow10</span><span style="color: #0000FF;">)),</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">primes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pow10</span><span style="color: #0000FF;">)),</span> |
||
<span style="color: #000000;">anap</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">primes</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..$]</span> |
<span style="color: #000000;">anap</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">primes</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..$]</span> |
||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span> <span style="color: #008080;">in</span> <span style="color: #000000;">anap</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (~ |
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span> <span style="color: #008080;">in</span> <span style="color: #000000;">anap</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (~4M/s, 16s in total)</span> |
||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()></span><span style="color: #000000;">t1</span> <span style="color: #008080;">then</span> |
<span style="color: #008080;">if</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()></span><span style="color: #000000;">t1</span> <span style="color: #008080;">then</span> |
||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"converting %d/%d...\r"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anap</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"converting %d/%d...\r"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anap</span><span style="color: #0000FF;">)})</span> |
||
<span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()+</span><span style="color: #000000;">1</span> |
<span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</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: # |
<span style="color: #004080;">integer</span> <span style="color: #000000;">sig</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> |
||
<span style="color: #008080;">while</span> <span style="color: #000000;">a</span> <span style="color: #008080;">do</span> |
|||
<span style="color: #000000;">sig</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">primes</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> |
|||
<span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
|||
<span style="color: #000000;">anap</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">sig</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: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"sorting...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- ( |
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"sorting...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (~16s in total)</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">anasorted</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anap</span><span style="color: #0000FF;">))</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">anasorted</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anap</span><span style="color: #0000FF;">))</span> |
||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"scanning...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (pretty fast)</span> |
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"scanning...\r"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (pretty fast)</span> |
||
Line 382: | Line 387: | ||
<pre> |
<pre> |
||
Largest anagram groups: |
Largest anagram groups: |
||
3-digits: [ |
3-digits: [101..997], size 143 (0s) |
||
4-digits: [ |
4-digits: [1009..9973], size 1061 (0s) |
||
5-digits: [ |
5-digits: [10007..99991], size 8363 (0s) |
||
6-digits: [ |
6-digits: [100003..999983], size 68906 (0s) |
||
7-digits: [ |
7-digits: [1000003..9999991], size 586081 (0s) |
||
8-digits: [ |
8-digits: [10000019..99999989], size 5096876 (4s) |
||
9-digits: [ |
9-digits: [100000007..999999937], size 45086079 (47s) |
||
"2 minutes and 53s" |
|||
</pre> |
</pre> |
||
For comparison, on the same (ten year old 16GB) box the Julia entry took 38s (2nd run) to complete to 9 digits.<br> |
For comparison, on the same (ten year old 16GB) box the Julia entry took 38s (2nd run) to complete to 9 digits.<br> |
||
I simply don't have enough memory to attempt 10 digits, and in fact trying to run the Julia entry as-is forced a hard reboot.<br> |
I simply don't have enough memory to attempt 10 digits, and in fact trying to run the Julia entry as-is forced a hard reboot.<br> |
||
When transpiled to JavaScript, 8 digits took |
When transpiled to JavaScript and run n a web browser, 8 digits took 18secs, so I capped it at that. |
||
=={{header|Raku}}== |
=={{header|Raku}}== |