<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Studiose</title>
	<atom:link href="http://studiose.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://studiose.org</link>
	<description>Well I guess that&#039;s that.</description>
	<lastBuildDate>Wed, 26 May 2010 09:44:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Project Euler #4</title>
		<link>http://studiose.org/2010/05/26/project-euler-4/</link>
		<comments>http://studiose.org/2010/05/26/project-euler-4/#comments</comments>
		<pubDate>Wed, 26 May 2010 09:43:09 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://studiose.org/?p=45</guid>
		<description><![CDATA["Find the largest palindrome made from the product of two 3-digit numbers." This one also took a bit more time than I would have liked, but after fixing the problem I understood how I missed it. Before if the left value ( left * right ) was higher it'd be considered the "largest" palindrome, which [...]]]></description>
			<content:encoded><![CDATA[<p><center><big><big>"</big></big><bold>Find the largest palindrome made from the product of two 3-digit numbers.</bold><big><big>"</big></big></center></p>
<p>This one also took a bit more time than I would have liked, but after fixing the problem I understood how I missed it. Before if the left value ( left * right ) was higher it'd be considered the "largest" palindrome, which was incorrect. I hadn't realized this until I started "debugging" my thoughts and the math behind everything, eventually I checked made the program check the next palindrome up to see if it were larger than the current "answer", if it was larger it'd replace it as the answer. This is pretty easy to understand, so I won't go into explaining it:<br /><Br /></p>
<pre>
<code><span style="color:blue">int</span> Reverse( <span style="color:blue">int</span> n )
{
	<span style="color:blue">int</span> tO = n, t1 = 0;

	<span style="color:blue">while</span>( tO &gt; 0 )
	{
		t1 *= 10;
		t1 += tO % 10;
		tO /= 10;
	}

	<span style="color:blue">return</span> t1;
}

<span style="color:blue">int</span> Problem4()
{
	<span style="color:blue">int</span> Answer = 0;
	<span style="color:blue">int</span> Maybe = 0;

	<span style="color:blue">for</span>( <span style="color:blue">int</span> i = 999; i &gt;= 100; i-- )
	{
		<span style="color:blue">for</span>( <span style="color:blue">int</span> c = 999; c &gt;= 100; c-- )
		{
			<span style="color:blue">if</span>( ( i * c ) == Reverse( i * c ) )
			{
				Maybe = ( i * c );
				<span style="color:blue">if</span>( Maybe &gt; Answer ) Answer = ( i * c );
			}
		}
	}
}</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://studiose.org/2010/05/26/project-euler-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler #3</title>
		<link>http://studiose.org/2010/05/25/project-euler-3/</link>
		<comments>http://studiose.org/2010/05/25/project-euler-3/#comments</comments>
		<pubDate>Wed, 26 May 2010 08:37:19 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://studiose.org/?p=39</guid>
		<description><![CDATA["Find the largest prime factor of a composite number." Woo, that one was harder than I would have liked. Okay, well not so much hard, but tedious. My first couple iterations of this program took more than 20 minutes to find number I eventually found out I didn't need! But I eventually optimized it and [...]]]></description>
			<content:encoded><![CDATA[<p><center><big><big>"</big></big><bold>Find the largest prime factor of a composite number.</bold><big><big>"</big></big></center></p>
<p>Woo, that one was harder than I would have liked. Okay, well not so much hard, but tedious. My first couple iterations of this program took more than 20 minutes to find number I eventually found out I didn't need! But I eventually optimized it and found the answer, and wrote it in a way so that if I ever encounter this problem somewhere else with an even bigger number I'll be ready.<br /><Br /></p>
<p>So First off, I had to write two of my own functions, with a bit of help from the internet of course. One was a function for square rooting 64bit numbers:</p>
<pre>
<code><span style="color:blue">double</span> Sqrt64( double number )
{
	<span style="color:blue">double</span> t1 = 0, t2 = 0, t3 = 0;
	<span style="color:blue">while</span>( ( t1 * t1 ) &lt;= number ) t1 += 0.1;

	t2 = t1;

	<span style="color:blue">for</span>( <span style="color:blue">double</span> c = 0; c &lt; 10; c++ )
	{
		t3 = number;
		t3 /= t2;
		t3 += t2;
		t3 /= 2;
		t2 = t3;
	}

	<span style="color:blue">return</span> t3;
}</code>
</pre>
<p></p>
<p>And the other function which would check if a number was Prime or not:</p>
<pre>
<code><span style="color:green">// Int64 is defined in my header as: #define Int64 _int64</span>
<span style="color:blue">bool</span> IsPrime( Int64 Number )
{
	<span style="color:blue">bool</span> IsPrime = <span style="color:blue">true</span>;

	<span style="color:blue">for</span>( <span style="color:blue">int</span> i = 2; i &lt; Number + 1; i++ )
	{
		<span style="color:blue">if</span>( i != Number &amp;&amp; Number != 1 )
		{
			<span style="color:blue">if</span>( Number % i == 0 ) IsPrime = <span style="color:blue">false</span>;
		}
	}
	<span style="color:blue">return</span> IsPrime;
}</code>
</pre>
<p></p>
<p>After those I could finally get to the actual solution to Problem 3, which used this C++ code written by me ( hurr ):</p>
<pre>
<code><span style="color:blue">int</span> Problem3()
{
	Int64 Answer = 0, Total = 1, Value = 600851475143;

	<span style="color:blue">for</span>( Int64 i = 1; i &lt; Sqrt64( Value ); i++ )
	{
		<span style="color:blue">if</span>( IsPrime( i ) )
		{
			<span style="color:blue">if</span>( Value % i == 0 &amp;&amp; i != Value )
			{
				Total *= i;
				<span style="color:blue">if</span>( Total == Value )
				{
					Answer = i;
					i = Sqrt64( Value );
				}
			}
		}
	}
	<span style="color:blue">return</span> Answer;
}</code>
</pre>
<p></p>
<p>Basically what I'm doing in all of that is Defining 3 variables as 64 Bit Integers: Answer, which as before is going to be our return value, and solution. Total, which is used as a container to add the product of all prime factors found during run-time. And Value, which is just so I don't have to keep typing 600851475143 into the program a bunch.</p>
<p>After defining the variables we run through a for loop with an initial value of 1 that after incrementing cannot exceed the square root of our given Value, which in this case is 600851475143. Inside this loop we check if the initialized variable: 'i', is Prime using our handy dandy IsPrime() function. Within that conditional we have another that checks to see if i is a factor of our Value and isn't actually our value. After checking that we need to multiply i to our Total and then check if our Total has met our Value, when that happens we have found all Prime Factors of our given Value. If we have met our Value we assign the last given prime factor to our Answer and then set 'i' to the square root of our Value just so we get out of the loop. And bam, you have your answer to problem 3.</p>
]]></content:encoded>
			<wfw:commentRss>http://studiose.org/2010/05/25/project-euler-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler #2</title>
		<link>http://studiose.org/2010/05/25/project-euler-2/</link>
		<comments>http://studiose.org/2010/05/25/project-euler-2/#comments</comments>
		<pubDate>Wed, 26 May 2010 06:08:13 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://studiose.org/?p=16</guid>
		<description><![CDATA["Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million." Just finished problem 2 of Project Euler. Another simple one, sadly I was set back a good 30 minutes because of an evil semi-colon hiding in the mist of my syntax. Anyways, here's my solution in C++: [...]]]></description>
			<content:encoded><![CDATA[<p><center><big><big>"</big></big><bold>Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million.</bold><big><big>"</big></big></center></p>
<p>Just finished problem 2 of Project Euler. Another simple one, sadly I was set back a good 30 minutes because of an evil semi-colon hiding in the mist of my syntax. Anyways, here's my solution in C++:</p>
<pre>
<code><span style="color:blue">int</span> Problem2()
{
	<span style="color:blue">int</span> Answer = 0, FTerm = 0, i1 = 0, i2 = 0;

	<span style="color:blue">while</span>( FTerm &lt; 4000000 )
	{
		FTerm = i1 + i2;
		i1 = i2; i2 = FTerm;

		if( !(FTerm % 2) ) Answer += FTerm;
	}
	<span style="color:blue">return</span> Answer;
}</code>
</pre>
<p></p>
<p>I'll try and explain that more than I did the last problem. I create 4 int variables: Answer, our return value. FTerm, the current number in our Fibonacci sequence. i1 and i2, the two previous numbers from our Fibonacci sequence.</p>
<p>What we do is setup a while loop that keeps pushing through our sequence until FTerm exceeds 4,000,000. Inside this loop we redefine FTerm with the sum of our two previous values. Then we use the modulo ( %) operator to find out if the current FTerm value is even by checking if there is any remainder when dividing the FTerm value by 2, if there is any remainder it is not an even number, if there isn't then it's even. If the FTerm value is even we finally add it to the Answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://studiose.org/2010/05/25/project-euler-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler #1</title>
		<link>http://studiose.org/2010/05/25/project-euler-1/</link>
		<comments>http://studiose.org/2010/05/25/project-euler-1/#comments</comments>
		<pubDate>Wed, 26 May 2010 05:09:32 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://studiose.org/?p=14</guid>
		<description><![CDATA["Add all the natural numbers below one thousand that are multiples of 3 or 5." Started working on the Project Euler problems. Just going to work my way through all of them one at a time. I'm hoping it'll be an amazing learning experience. The solution to problem #1 in C++: int Problem1() { for( int [...]]]></description>
			<content:encoded><![CDATA[<p><center><big><big>"</big></big><bold>Add all the natural numbers below one thousand that are multiples of 3 or 5.</bold><big><big>"</big></big></center></p>
<p>Started working on the Project Euler problems. Just going to work my way through all of them one at a time. I'm hoping it'll be an amazing learning experience.</p>
<p>The solution to problem #1 in C++:</p>
<pre>
<code><span style="color:blue;">int</span> Problem1()
{
	<span style="color:blue;">for</span>( <span style="color:blue;">int</span> i = 1; i &lt; 1000; i++ )
	{
		<span style="color:blue;">if</span>( i % 3 == 0 || i % 5 == 0 ) Answer += i;
	}
	<span style="color:blue;">return</span> Answer;
}</code>
</pre>
<p></p>
<p>Simple enough, had myself a bit confused at first though making a silly mistake. Instead of checking if the value was divisible for both numbers I was checking if it was divisible for one and then checking if it was divisible for the other, meaning I was adding the multiple twice if it worked for both. But I realized my mistake and fixed it, slightly proud of myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://studiose.org/2010/05/25/project-euler-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MString</title>
		<link>http://studiose.org/2010/05/25/mstring/</link>
		<comments>http://studiose.org/2010/05/25/mstring/#comments</comments>
		<pubDate>Wed, 26 May 2010 00:28:14 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Mobility]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://studiose.org/?p=12</guid>
		<description><![CDATA[Programmed my own little string class based off std::string. It's nothing special, but it's nice to have my function to edit while I need it, this way I don't need to make tons of code changes over 10 different files to do one thing, instead I can just add the function to the class or [...]]]></description>
			<content:encoded><![CDATA[<p>Programmed my own little string class based off std::string. It's nothing special, but it's nice to have my function to edit while I need it, this way I don't need to make tons of code changes over 10 different files to do one thing, instead I can just add the function to the class or edit one and bam!</p>
<p>So far the only functions I've added to the Mobility String that aren't standard in a normal string are:</p>
<ul>
<li><span style="color: #3366ff;">MString</span> MakeUpper(), which converts the string to all caps.</li>
<li><span style="color: #3366ff;">MStrin</span><span style="color: #3366ff;">g</span> MakeLower(), the exact same as MakeUpper() but to lowercase.</li>
<li><span style="color: #3366ff;">MString</span> Chunk( <span style="color: #3366ff;">int</span> begin, <span style="color: #3366ff;">int</span> end ), just a simplified substr function. Parameter "end" is optional, if it's not provided it just starts from "begin" and goes t'll the end of the string.</li>
<li><span style="color: #3366ff;">const wchar_t</span> *WStr(), returns the string in a wide character array.</li>
<li><span style="color: #3366ff;">static const char</span> *Narrow( <span style="color: #3366ff;">wchar_t</span> *str ), returns a given wide array as a simple char array. Because it's static you can use it outside a specific object.</li>
<li><span style="color: #3366ff;">static const wchar_t</span> *Widen( <span style="color: #3366ff;">char</span> *str ), the exact same as Narrow( <span style="color: #3366ff;">wchar_t</span> *str ) but widens the char array.</li>
</ul>
<p>Obviously it isn't complete, but I'll add features as I need them. Which is the beauty of this class for me. Anyways, off to copying Garry's Hot Compiling.</p>
]]></content:encoded>
			<wfw:commentRss>http://studiose.org/2010/05/25/mstring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
