<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Project Euler SAS solution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292669#M60803</link>
    <description>Ha. You should forward this url to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; . I bet he gonna love it .
If you want fast algorithm , I think you should pick up all the prime number in it firstly.</description>
    <pubDate>Fri, 19 Aug 2016 08:19:36 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-08-19T08:19:36Z</dc:date>
    <item>
      <title>Project Euler SAS solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292646#M60791</link>
      <description>&lt;P&gt;As many will attest, my mathematical abilities aren't great. My instincts aren't bad, but when I have to go beyond the delights of ones and zeroes, I'm prone to make mistakes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About six months ago I started hacking my way through&amp;nbsp;&lt;A href="https://projecteuler.net" target="_blank"&gt;https://projecteuler.net&lt;/A&gt;. I got stuck at about problem 30, and pretty much gave up. I was coding up the solutions in Apple's Swift - actually the reason was to teach myself to be a better Swift programmer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A couple of days ago I thought I'd have another go, and happened across problem 179 (&lt;A href="https://projecteuler.net/problem=179" target="_blank"&gt;https://projecteuler.net/problem=179&lt;/A&gt;), which reads:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Find the number of integers 1 &amp;lt; n &amp;lt; 107, for which&amp;nbsp;n&amp;nbsp;and&amp;nbsp;n&amp;nbsp;+ 1 have the same number of positive divisors. For example, 14 has the positive divisors 1, 2, 7, 14 while 15 has 1, 3, 5, 15.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I wrote a solution which was taking ages (I gave up after thirty minutes), then I thought about it, recoded it and it came down to nine seconds.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;While I was out walking the dog today, I thought about writing it in SAS. When I came home I fired up SAS Studio on my Mac (I love being able to do that!) and hacked out the following code, using a hash table and 'by - notsorted'. The hash population takes 2'31", but the analysis steams through in four seconds.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm ridiculously proud of:&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;count + not(last.divisors);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	length i 8;
	length divisors 4;
	max=1e7;
	dcl hash divhash(hashexp: log2(max), ordered: 'a');
	divhash.definekey('i');
	divhash.definedata('i', 'divisors');
	divhash.definedone();
	i=1;
	divisors=1;
	divhash.add();

	do i=2 to max;
		divisors=2;       /* All numbers &amp;gt; 1 have two divisors */
		rc=divhash.add();
	end;

	do j=2 to int(max / 2);
		do i=j * 2 to max by j;
			rc=divhash.find();
			divisors + 1;
			rc=divhash.replace();
		end;
	end;
	divhash.output(dataset: 'divisors');
	stop;
run;

data _null_;
	set divisors nobs=max end=eof;
	by divisors notsorted;
	retain count 0;
	format max count comma14.;
	count + not(last.divisors);

	if eof;
	put 'There are ' count +(-1) ' consecutive positive divisors between 1 and ' 
		max +(-1) '.';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;There are always so many ways to skin a cat. I could have done it in one step by setting up an array instead of the hash. But I wanted to take advantage of by-group processing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You know the old criticism of "some people have too much time on their hands"? Sometimes I like being "some people".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 04:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292646#M60791</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-08-19T04:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Project Euler SAS solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292652#M60793</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;.............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You know the old criticism of "some people have too much time on their hands"? Sometimes I like being "some people".&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it wasn't for that, I'd probably not be posting here &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 06:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292652#M60793</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-19T06:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Project Euler SAS solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292669#M60803</link>
      <description>Ha. You should forward this url to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; . I bet he gonna love it .
If you want fast algorithm , I think you should pick up all the prime number in it firstly.</description>
      <pubDate>Fri, 19 Aug 2016 08:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292669#M60803</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-19T08:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Project Euler SAS solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292875#M60864</link>
      <description>&lt;P&gt;The straight programming style (not SAS-specific) was much more efficient: 5.59 seconds.&lt;/P&gt;&lt;PRE&gt;%let max = 10000000;

data _null_;
	length i 8;
	max=&amp;amp;max;
	array divisors[&amp;amp;max] 4 _temporary_;
	divisors[1]=1;

	do i=2 to max;
		divisors[i]=2;
	end;

	do j=2 to int(dim(divisors) / 2);
		do i=j * 2 to max by j;
			divisors[i] + 1;
		end;
	end;
	
	count = 0;
	do i = 2 to dim(divisors) - 1;
	   count + divisors[i] = divisors[i + 1];
	   end;
	format max count comma14.;
	put 'There are ' count +(-1) ' consecutive positive divisors between 1 and ' 
		max +(-1) '.';
    stop;   
run;&lt;/PRE&gt;&lt;P&gt;But not as much fun.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2016 01:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292875#M60864</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-08-20T01:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Project Euler SAS solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292877#M60865</link>
      <description>&lt;PRE&gt;
Sorry. Forget what I said, I totally have no idea about it.
Your algorithm is amazing . I don't how it work .
I love that URL .


&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Aug 2016 02:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Project-Euler-SAS-solution/m-p/292877#M60865</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-20T02:38:06Z</dc:date>
    </item>
  </channel>
</rss>

