<?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/"
	>

<channel>
	<title>Daniel Pedigo</title>
	<atom:link href="http://www.danielpedigo.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danielpedigo.com</link>
	<description></description>
	<pubDate>Sat, 03 Jan 2009 01:09:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Challenging Websites</title>
		<link>http://www.danielpedigo.com/2009/01/02/challenging-websites/</link>
		<comments>http://www.danielpedigo.com/2009/01/02/challenging-websites/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 01:09:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=114</guid>
		<description><![CDATA[As most of you can tell, I&#8217;ve been pretty fascinated with Project Euler for quite some time (I have a lot more challenges done than I&#8217;ve actually posted).  However, these last few weeks I&#8217;ve been neglecting Project Euler and keeping myself busy with a few other &#8220;challenge&#8221;-type websites that I&#8217;ve found.   If any of you [...]]]></description>
			<content:encoded><![CDATA[<p>As most of you can tell, I&#8217;ve been pretty fascinated with <a title="Project Euler" href="http://www.projecteuler.net">Project Euler</a> for quite some time (I have a lot more challenges done than I&#8217;ve actually posted).  However, these last few weeks I&#8217;ve been neglecting Project Euler and keeping myself busy with a few other &#8220;challenge&#8221;-type websites that I&#8217;ve found.   If any of you are interested in having hours and hours disappear in the blink of an eye, keep reading.  Seriously, I&#8217;m not joking.</p>
<p>First up is an amazingly clever riddle website titled <a title="Notpron" href="http://www.deathball.net/notpron/">Notpron</a>.  Think of this as a no holds barred, anything goes type of riddle.  The first few levels are quite easy, as to give you a grasp on how it works, but they become much harder as you progress. I&#8217;ve spent countless hours on Notpron over the last few weeks only to progress to level 18.  There are 140 levels available.  According to the website, only 3 people have been &#8220;certified&#8221; as having completed all of the levels.  I definitely recommend everyone gives this website a try.</p>
<p>My next recommendation is a website called <a title="Bright Shadows" href="http://bright-shadows.net/">Bright Shadows</a>.  Bright shadows has many different categories of challenges available in hopes that there will be a category suitable to you.  As most of these challenges require programming experience, I would not recommend this website to anyone that is not at least a little bit familiar with programming concepts.  Some of the categories include: programming, Cryptography, Steganography, logic, and my favorite, cracking.  Regardless, I still give this website an A+ for finally convincing me to whip out a disassembler and &#8220;go at it&#8221;.</p>
<p>My last recommendation (not because the others are any better) for challenge websites is <a title="Project Euler" href="http://www.projecteuler.net">Project Euler</a>.  This website is based around challenging mathematical/computer programming problems.  Even someone like me, who would rather be doing things that are not math related, should still find this website to be a lot of fun.</p>
<p>Even though I&#8217;ve recommended a few websites to check out, there are still many more out there that are a lot of fun.  A few runner-ups include:</p>
<ul>
<li><a title="Electrica" href="http://www.caesum.com/game/">Electrica</a></li>
<li><a title="+Ma's Reversing" href="http://3564020356.org/">+Ma&#8217;s Reversing</a></li>
<li><a title="Hack This Site" href="http://www.hackthissite.org/">Hack This Site</a></li>
</ul>
<p>If any one knows of any other websites similar to these worth mentioning, leave a comment and I&#8217;ll add it to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2009/01/02/challenging-websites/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #11</title>
		<link>http://www.danielpedigo.com/2008/11/28/project-euler-problem-11/</link>
		<comments>http://www.danielpedigo.com/2008/11/28/project-euler-problem-11/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 23:05:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=112</guid>
		<description><![CDATA[I&#8217;ve been so preoccupied as of late that I&#8217;ve completely neglected the website!  I&#8217;ll try to be a little better in the future.  So anyways, I&#8217;ve finally got around to posting the answer to Problem 11.  It&#8217;s not at all a hard problem, in fact, I think the hardest part was filling [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been so preoccupied as of late that I&#8217;ve completely neglected the website!  I&#8217;ll try to be a little better in the future.  So anyways, I&#8217;ve finally got around to posting the answer to Problem 11.  It&#8217;s not at all a hard problem, in fact, I think the hardest part was filling that pesky multi-dimensional array with the values!</p>
<p><strong>Problem #11:</strong><br />Description: What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20&#215;20 grid?<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #339900;">#define LENGTH 20</span>
<span style="color: #339900;">#define HEIGHT 20</span>
&nbsp;
<span style="color: #0000ff;">int</span> ProblemEleven<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> result <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
  <span style="color: #0000ff;">int</span> g<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>LENGTH<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#123;</span><span style="color:#800080;">08</span>,<span style="color: #208080;">02</span>,<span style="color: #0000dd;">22</span>,<span style="color: #0000dd;">97</span>,<span style="color: #0000dd;">38</span>,<span style="color: #0000dd;">15</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">40</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">75</span>,<span style="color: #208080;">04</span>,<span style="color: #208080;">05</span>,<span style="color: #208080;">07</span>,<span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">52</span>,<span style="color: #0000dd;">12</span>,<span style="color: #0000dd;">50</span>,<span style="color: #0000dd;">77</span>,<span style="color: #0000dd;">91</span>,<span style="color:#800080;">08</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">99</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">81</span>,<span style="color: #0000dd;">18</span>,<span style="color: #0000dd;">57</span>,<span style="color: #0000dd;">60</span>,<span style="color: #0000dd;">87</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">98</span>,<span style="color: #0000dd;">43</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">48</span>,<span style="color: #208080;">04</span>,<span style="color: #0000dd;">56</span>,<span style="color: #0000dd;">62</span>,<span style="color: #208080;">00</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">81</span>,<span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">73</span>,<span style="color: #0000dd;">55</span>,<span style="color: #0000dd;">79</span>,<span style="color: #0000dd;">14</span>,<span style="color: #0000dd;">29</span>,<span style="color: #0000dd;">93</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">53</span>,<span style="color: #0000dd;">88</span>,<span style="color: #0000dd;">30</span>,<span style="color: #208080;">03</span>,<span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">13</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">65</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">52</span>,<span style="color: #0000dd;">70</span>,<span style="color: #0000dd;">95</span>,<span style="color: #0000dd;">23</span>,<span style="color: #208080;">04</span>,<span style="color: #0000dd;">60</span>,<span style="color: #0000dd;">11</span>,<span style="color: #0000dd;">42</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">68</span>,<span style="color: #0000dd;">56</span>,<span style="color: #208080;">01</span>,<span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">56</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">37</span>,<span style="color: #208080;">02</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">91</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">22</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">51</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">63</span>,<span style="color: #0000dd;">89</span>,<span style="color: #0000dd;">41</span>,<span style="color: #0000dd;">92</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">22</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">28</span>,<span style="color: #0000dd;">66</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">13</span>,<span style="color: #0000dd;">80</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">47</span>,<span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">60</span>,<span style="color: #0000dd;">99</span>,<span style="color: #208080;">03</span>,<span style="color: #0000dd;">45</span>,<span style="color: #208080;">02</span>,<span style="color: #0000dd;">44</span>,<span style="color: #0000dd;">75</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">53</span>,<span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">84</span>,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">12</span>,<span style="color: #0000dd;">50</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">98</span>,<span style="color: #0000dd;">81</span>,<span style="color: #0000dd;">28</span>,<span style="color: #0000dd;">64</span>,<span style="color: #0000dd;">23</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">10</span>,<span style="color: #0000dd;">26</span>,<span style="color: #0000dd;">38</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">59</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">70</span>,<span style="color: #0000dd;">66</span>,<span style="color: #0000dd;">18</span>,<span style="color: #0000dd;">38</span>,<span style="color: #0000dd;">64</span>,<span style="color: #0000dd;">70</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">26</span>,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">68</span>,<span style="color: #208080;">02</span>,<span style="color: #0000dd;">62</span>,<span style="color: #0000dd;">12</span>,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">95</span>,<span style="color: #0000dd;">63</span>,<span style="color: #0000dd;">94</span>,<span style="color: #0000dd;">39</span>,<span style="color: #0000dd;">63</span>,<span style="color:#800080;">08</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">91</span>,<span style="color: #0000dd;">66</span>,<span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">94</span>,<span style="color: #0000dd;">21</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">55</span>,<span style="color: #0000dd;">58</span>,<span style="color: #208080;">05</span>,<span style="color: #0000dd;">66</span>,<span style="color: #0000dd;">73</span>,<span style="color: #0000dd;">99</span>,<span style="color: #0000dd;">26</span>,<span style="color: #0000dd;">97</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">96</span>,<span style="color: #0000dd;">83</span>,<span style="color: #0000dd;">14</span>,<span style="color: #0000dd;">88</span>,<span style="color: #0000dd;">34</span>,<span style="color: #0000dd;">89</span>,<span style="color: #0000dd;">63</span>,<span style="color: #0000dd;">72</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">21</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">23</span>,<span style="color:#800080;">09</span>,<span style="color: #0000dd;">75</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">76</span>,<span style="color: #0000dd;">44</span>,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">45</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">14</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">61</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">97</span>,<span style="color: #0000dd;">34</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">95</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">53</span>,<span style="color: #0000dd;">28</span>,<span style="color: #0000dd;">22</span>,<span style="color: #0000dd;">75</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">15</span>,<span style="color: #0000dd;">94</span>,<span style="color: #208080;">03</span>,<span style="color: #0000dd;">80</span>,<span style="color: #208080;">04</span>,<span style="color: #0000dd;">62</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">14</span>,<span style="color:#800080;">09</span>,<span style="color: #0000dd;">53</span>,<span style="color: #0000dd;">56</span>,<span style="color: #0000dd;">92</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">39</span>,<span style="color: #208080;">05</span>,<span style="color: #0000dd;">42</span>,<span style="color: #0000dd;">96</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">47</span>,<span style="color: #0000dd;">55</span>,<span style="color: #0000dd;">58</span>,<span style="color: #0000dd;">88</span>,<span style="color: #0000dd;">24</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">29</span>,<span style="color: #0000dd;">85</span>,<span style="color: #0000dd;">57</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">86</span>,<span style="color: #0000dd;">56</span>,<span style="color: #208080;">00</span>,<span style="color: #0000dd;">48</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">89</span>,<span style="color: #208080;">07</span>,<span style="color: #208080;">05</span>,<span style="color: #0000dd;">44</span>,<span style="color: #0000dd;">44</span>,<span style="color: #0000dd;">37</span>,<span style="color: #0000dd;">44</span>,<span style="color: #0000dd;">60</span>,<span style="color: #0000dd;">21</span>,<span style="color: #0000dd;">58</span>,<span style="color: #0000dd;">51</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">58</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">19</span>,<span style="color: #0000dd;">80</span>,<span style="color: #0000dd;">81</span>,<span style="color: #0000dd;">68</span>,<span style="color: #208080;">05</span>,<span style="color: #0000dd;">94</span>,<span style="color: #0000dd;">47</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">28</span>,<span style="color: #0000dd;">73</span>,<span style="color: #0000dd;">92</span>,<span style="color: #0000dd;">13</span>,<span style="color: #0000dd;">86</span>,<span style="color: #0000dd;">52</span>,<span style="color: #0000dd;">17</span>,<span style="color: #0000dd;">77</span>,<span style="color: #208080;">04</span>,<span style="color: #0000dd;">89</span>,<span style="color: #0000dd;">55</span>,<span style="color: #0000dd;">40</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #208080;">04</span>,<span style="color: #0000dd;">52</span>,<span style="color:#800080;">08</span>,<span style="color: #0000dd;">83</span>,<span style="color: #0000dd;">97</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">99</span>,<span style="color: #0000dd;">16</span>,<span style="color: #208080;">07</span>,<span style="color: #0000dd;">97</span>,<span style="color: #0000dd;">57</span>,<span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">26</span>,<span style="color: #0000dd;">26</span>,<span style="color: #0000dd;">79</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">27</span>,<span style="color: #0000dd;">98</span>,<span style="color: #0000dd;">66</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">88</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">68</span>,<span style="color: #0000dd;">87</span>,<span style="color: #0000dd;">57</span>,<span style="color: #0000dd;">62</span>,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">72</span>,<span style="color: #208080;">03</span>,<span style="color: #0000dd;">46</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">46</span>,<span style="color: #0000dd;">55</span>,<span style="color: #0000dd;">12</span>,<span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">63</span>,<span style="color: #0000dd;">93</span>,<span style="color: #0000dd;">53</span>,<span style="color: #0000dd;">69</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #208080;">04</span>,<span style="color: #0000dd;">42</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">73</span>,<span style="color: #0000dd;">38</span>,<span style="color: #0000dd;">25</span>,<span style="color: #0000dd;">39</span>,<span style="color: #0000dd;">11</span>,<span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">94</span>,<span style="color: #0000dd;">72</span>,<span style="color: #0000dd;">18</span>,<span style="color:#800080;">08</span>,<span style="color: #0000dd;">46</span>,<span style="color: #0000dd;">29</span>,<span style="color: #0000dd;">32</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">62</span>,<span style="color: #0000dd;">76</span>,<span style="color: #0000dd;">36</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">41</span>,<span style="color: #0000dd;">72</span>,<span style="color: #0000dd;">30</span>,<span style="color: #0000dd;">23</span>,<span style="color: #0000dd;">88</span>,<span style="color: #0000dd;">34</span>,<span style="color: #0000dd;">62</span>,<span style="color: #0000dd;">99</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">82</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">59</span>,<span style="color: #0000dd;">85</span>,<span style="color: #0000dd;">74</span>,<span style="color: #0000dd;">40</span>,<span style="color: #0000dd;">36</span>,<span style="color: #0000dd;">16</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">73</span>,<span style="color: #0000dd;">35</span>,<span style="color: #0000dd;">29</span>,<span style="color: #0000dd;">78</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">90</span>,<span style="color: #208080;">01</span>,<span style="color: #0000dd;">74</span>,<span style="color: #0000dd;">31</span>,<span style="color: #0000dd;">49</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">48</span>,<span style="color: #0000dd;">86</span>,<span style="color: #0000dd;">81</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">23</span>,<span style="color: #0000dd;">57</span>,<span style="color: #208080;">05</span>,<span style="color: #0000dd;">54</span><span style="color: #008000;">&#125;</span>,
    <span style="color: #008000;">&#123;</span><span style="color: #208080;">01</span>,<span style="color: #0000dd;">70</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">71</span>,<span style="color: #0000dd;">83</span>,<span style="color: #0000dd;">51</span>,<span style="color: #0000dd;">54</span>,<span style="color: #0000dd;">69</span>,<span style="color: #0000dd;">16</span>,<span style="color: #0000dd;">92</span>,<span style="color: #0000dd;">33</span>,<span style="color: #0000dd;">48</span>,<span style="color: #0000dd;">61</span>,<span style="color: #0000dd;">43</span>,<span style="color: #0000dd;">52</span>,<span style="color: #208080;">01</span>,<span style="color: #0000dd;">89</span>,<span style="color: #0000dd;">19</span>,<span style="color: #0000dd;">67</span>,<span style="color: #0000dd;">48</span><span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>;
&nbsp;
  <span style="color: #666666;">// first case : left &lt;-&gt; right</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;</span> HEIGHT; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; j <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span>LENGTH <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> g<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> temp <span style="color: #000080;">&gt;</span> result <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        result <span style="color: #000080;">=</span> temp;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// second case : up &lt;-&gt; down</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;</span> LENGTH; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; j <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span>HEIGHT <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> temp <span style="color: #000080;">&gt;</span> result <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        result <span style="color: #000080;">=</span> temp;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// third case : diagonal -&gt; right</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span>LENGTH <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; j <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span>HEIGHT <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> temp <span style="color: #000080;">&gt;</span> result <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        result <span style="color: #000080;">=</span> temp;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// fourth case : diagonal -&gt; left</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> LENGTH; i <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">3</span>; i<span style="color: #000040;">--</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; j <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span>HEIGHT <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span>; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">-</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> g<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>i<span style="color: #000040;">-</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> temp <span style="color: #000080;">&gt;</span> result <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        result <span style="color: #000080;">=</span> temp;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> result;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/28/project-euler-problem-11/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #10</title>
		<link>http://www.danielpedigo.com/2008/11/19/project-euler-problem-10/</link>
		<comments>http://www.danielpedigo.com/2008/11/19/project-euler-problem-10/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 06:53:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=110</guid>
		<description><![CDATA[Okay, slightly off topic, but I&#8217;ve got to throw this out there.  Never, ever, ever write something that people will see when it&#8217;s late at night and you&#8217;re tired.  If you&#8217;re me, you will not only incorrectly express your feelings due to your terrible writing skills, but you&#8217;ll also make numerous mistakes misrepresenting [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, slightly off topic, but I&#8217;ve got to throw this out there.  Never, ever, <i>ever</i> write something that people will see when it&#8217;s late at night and you&#8217;re tired.  If you&#8217;re me, you will not only incorrectly express your feelings due to your terrible writing skills, but you&#8217;ll also make numerous mistakes misrepresenting the facts.  That&#8217;s what happened bashing on the LC-3 assembly language the other night.  To be honest, I&#8217;m not sure why I picked on LC-3.  I&#8217;m going to avoid late night writing altogether.  Oh, and Stephen, I wasn&#8217;t complaining about the number registers&#8211;that&#8217;s just silly.</p>
<p>There&#8217;s something about Project Euler and prime numbers that just go hand in hand it seems.  If you&#8217;re ever in doubt in regards with how to solve a problem you&#8217;ll probably need to generate some prime numbers.  No, seriously. So I&#8217;ve been talking about the day I would need to create a prime number sieve and that day has finally come.  I decided to go ahead and implement a version of the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a> for this and all future problems requiring me to calculate a list of prime numbers.  This thing is insanely fast compared to my previous code examples for generating prime numbers; you can generate the first two million primes in under 2 seconds.  If you were feeling (slightly) more adventurous, you could combine this sieve with <a href="http://en.wikipedia.org/wiki/Wheel_factorization">Wheel Factorization</a> to further optimize the code.</p>
<p><strong>Problem #9:</strong><br />Description: Find the sum of all the primes below two million.<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;math.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span><span style="color: #000040;">*</span> SieveOfEratosthenes<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> size <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span> primes <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span>size<span style="color: #008000;">&#93;</span>;
&nbsp;
  <span style="color: #666666;">// populate the array with numbers</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;=</span> size; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    primes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> i;
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// one isn't prime... sorry.</span>
  primes<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span>; i <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span>size<span style="color: #008000;">&#41;</span>; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> primes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">*</span> i<span style="color: #008000;">&#41;</span>; j <span style="color: #000080;">&lt;=</span> size; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> primes<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>primes<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">%</span> primes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
          <span style="color: #008000;">&#123;</span>
            primes<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
          <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> primes;
<span style="color: #008000;">&#125;</span>
&nbsp;
INT64 ProblemTen<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  INT64 result <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span> primes <span style="color: #000080;">=</span> SieveOfEratosthenes<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2000000</span><span style="color: #008000;">&#41;</span>;
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">2000000</span>; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> primes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      result <span style="color: #000040;">+</span><span style="color: #000080;">=</span> primes<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>;
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> result;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/19/project-euler-problem-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #9</title>
		<link>http://www.danielpedigo.com/2008/11/17/project-euler-problem-9/</link>
		<comments>http://www.danielpedigo.com/2008/11/17/project-euler-problem-9/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 20:12:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=89</guid>
		<description><![CDATA[Ahh, one of the most well-known theorems in math it seems: The Pythagorean theorem.  This is a nice and easy problem to solve using a good ol&#8217; brute force algorithm.
Problem #9
Description: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.&#160;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int ProblemNine&#40;&#41;
&#123;
  for &#40; int a [...]]]></description>
			<content:encoded><![CDATA[<p>Ahh, one of the most well-known theorems in math it seems: The Pythagorean theorem.  This is a nice and easy problem to solve using a good ol&#8217; brute force algorithm.</p>
<p><strong>Problem #9</strong><br />
Description: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> ProblemNine<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> a <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>; a <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">1000</span>; a<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> b <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>; b <span style="color: #000080;">&lt;=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> a<span style="color: #008000;">&#41;</span>; b<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> c <span style="color: #000080;">=</span> <span style="color: #0000dd;">1000</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span>a <span style="color: #000040;">+</span> b<span style="color: #008000;">&#41;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>a <span style="color: #000040;">*</span> a<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span>b <span style="color: #000040;">*</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #008000;">&#40;</span>c <span style="color: #000040;">*</span> c<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>a <span style="color: #000040;">*</span> b <span style="color: #000040;">*</span> c<span style="color: #008000;">&#41;</span>;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/17/project-euler-problem-9/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #8</title>
		<link>http://www.danielpedigo.com/2008/11/14/project-euler-problem-8/</link>
		<comments>http://www.danielpedigo.com/2008/11/14/project-euler-problem-8/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 18:39:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=87</guid>
		<description><![CDATA[Due to the size of the number provided in the problem, and the fact that I&#8217;ve yet to find a decent big integer library to use, I ended up treating this number as a character array and just converting groups of five into numbers as I need them.  Not really an efficient method of [...]]]></description>
			<content:encoded><![CDATA[<p>Due to the size of the number provided in the problem, and the fact that I&#8217;ve yet to find a decent big integer library to use, I ended up treating this number as a character array and just converting groups of five into numbers as I need them.  Not really an efficient method of doing this, but it still completes extremely quickly.</p>
<p>If one wanted to speed up the algorithm some, they could create temporary integer variables to hold the four values that will be used again in the next iteration of the for loop, thus saving some time by not needing to recalculate those values.</p>
<p><strong>Problem #8</strong><br />
Description: Find the greatest product of five consecutive digits in the 1000-digit number.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339900;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> ProblemEight<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> n <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;73167176531330624919225119674426574742355349194934 <span style="color: #666666; font-weight: bold;">\</span>
             96983520312774506326239578318016984801869478851843 <span style="color: #666666; font-weight: bold;">\</span>
             85861560789112949495459501737958331952853208805511 <span style="color: #666666; font-weight: bold;">\</span>
             12540698747158523863050715693290963295227443043557 <span style="color: #666666; font-weight: bold;">\</span>
             66896648950445244523161731856403098711121722383113 <span style="color: #666666; font-weight: bold;">\</span>
             62229893423380308135336276614282806444486645238749 <span style="color: #666666; font-weight: bold;">\</span>
             30358907296290491560440772390713810515859307960866 <span style="color: #666666; font-weight: bold;">\</span>
             70172427121883998797908792274921901699720888093776 <span style="color: #666666; font-weight: bold;">\</span>
             65727333001053367881220235421809751254540594752243 <span style="color: #666666; font-weight: bold;">\</span>
             52584907711670556013604839586446706324415722155397 <span style="color: #666666; font-weight: bold;">\</span>
             53697817977846174064955149290862569321978468622482 <span style="color: #666666; font-weight: bold;">\</span>
             83972241375657056057490261407972968652414535100474 <span style="color: #666666; font-weight: bold;">\</span>
             82166370484403199890008895243450658541227588666881 <span style="color: #666666; font-weight: bold;">\</span>
             16427171479924442928230863465674813919123162824586 <span style="color: #666666; font-weight: bold;">\</span>
             17866458359124566529476545682848912883142607690042 <span style="color: #666666; font-weight: bold;">\</span>
             24219022671055626321111109370544217506941658960408 <span style="color: #666666; font-weight: bold;">\</span>
             07198403850962455444362981230987879927244284909188 <span style="color: #666666; font-weight: bold;">\</span>
             84580156166097919133875499200524063689912560717606 <span style="color: #666666; font-weight: bold;">\</span>
             05886116467109405077541002256983155200055935729725 <span style="color: #666666; font-weight: bold;">\</span>
             71636269561882670428252483600823257530420752963450&quot;</span>;
&nbsp;
  <span style="color: #0000ff;">int</span> product <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #000080;">&lt;=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>n<span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span>; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">char</span> n1 <span style="color: #000080;">=</span> n<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>;
    <span style="color: #0000ff;">char</span> n2 <span style="color: #000080;">=</span> n<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>;
    <span style="color: #0000ff;">char</span> n3 <span style="color: #000080;">=</span> n<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span>;
    <span style="color: #0000ff;">char</span> n4 <span style="color: #000080;">=</span> n<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span>;
    <span style="color: #0000ff;">char</span> n5 <span style="color: #000080;">=</span> n<span style="color: #008000;">&#91;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span>;
&nbsp;
    <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>n1<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>n2<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>n3<span style="color: #008000;">&#41;</span>
                         <span style="color: #000040;">*</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>n4<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">atoi</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>n5<span style="color: #008000;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> temp <span style="color: #000080;">&gt;</span> product <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      product <span style="color: #000080;">=</span> temp;
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> product;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/14/project-euler-problem-8/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Website Updates</title>
		<link>http://www.danielpedigo.com/2008/11/13/website-updates/</link>
		<comments>http://www.danielpedigo.com/2008/11/13/website-updates/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 02:50:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=91</guid>
		<description><![CDATA[I decided that instead of solving and posting a Euler Project problem tonight, I would spend some time updating a few areas of my blog that have been neglected as of late.   I have re-posted my game of Tic Tac Toe and updated the project page that links to it.  I have also begun the [...]]]></description>
			<content:encoded><![CDATA[<p>I decided that instead of solving and posting a <a title="Project Euler" href="http://www.projecteuler.net">Euler Project</a> problem tonight, I would spend some time updating a few areas of my blog that have been neglected as of late.   I have re-posted my <a title="Tic Tac Toe" href="http://www.danielpedigo.com/tic-tac-toe">game of Tic Tac Toe</a> and updated the project page that links to it.  I have also begun the lengthy process of adding metadata and optimizing the web pages for search engines. I&#8217;ll hopefully have that completed by this weekend.</p>
<p>One other thing I&#8217;ve done tonight is recreate my PAD file for the <a title="MHTML Converter" href="http://www.danielpedigo.com/mhtml-converter">MHTML Converter</a>, which in turn should start driving a lot of traffic to this website again.  Believe it or not, it is quite the popular little utility.  I&#8217;m sure I&#8217;ll begin to see the website traffic increase again very shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/13/website-updates/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #7</title>
		<link>http://www.danielpedigo.com/2008/11/12/project-euler-problem-7/</link>
		<comments>http://www.danielpedigo.com/2008/11/12/project-euler-problem-7/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 05:06:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=79</guid>
		<description><![CDATA[Work has been rather busy as of late and as a result my lunch breaks have been shorter than normal, which means that I don&#8217;t have as much free time to do these little problems.  Luckily, I had enough time to complete this problem during lunch and some time tonight to post the problem [...]]]></description>
			<content:encoded><![CDATA[<p>Work has been rather busy as of late and as a result my lunch breaks have been shorter than normal, which means that I don&#8217;t have as much free time to do these little problems.  Luckily, I had enough time to complete this problem during lunch and some time tonight to post the problem to my blog.  So, to avoid further delay, here is problem 7 in all of it&#8217;s glory.  Oh, and I&#8217;ll get around to make a prime number generator later&#8230;</p>
<p><strong>Problem #7</strong><br />
Description: Find the 10001st prime.<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> ProblemSeven<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> total <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #0000ff;">int</span> prime <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #0000ff;">int</span> curr <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span>;
&nbsp;
  <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> total <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">10001</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">bool</span> isPrime <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span>;
&nbsp;
    <span style="color: #666666;">// check to see if it's really prime</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span>; j <span style="color: #000080;">&lt;=</span> <span style="color: #008000;">&#40;</span>curr <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>; j<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> curr <span style="color: #000040;">%</span> j <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        isPrime <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span>;
        <span style="color: #0000ff;">break</span>;
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> isPrime <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      total++;
      prime <span style="color: #000080;">=</span> curr;
    <span style="color: #008000;">&#125;</span>
&nbsp;
    curr++;
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> prime;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/12/project-euler-problem-7/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #6</title>
		<link>http://www.danielpedigo.com/2008/11/11/project-euler-problem-6/</link>
		<comments>http://www.danielpedigo.com/2008/11/11/project-euler-problem-6/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 17:05:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=69</guid>
		<description><![CDATA[Not really much to say about this problem as it was very straightforward.  Reading the code should be more than enough to figure it out.  I guess we&#8217;ll just have to wait for a more exciting problem.
Problem #6
Description: Find the difference between the sum of the squares of the first one hundred natural [...]]]></description>
			<content:encoded><![CDATA[<p>Not really much to say about this problem as it was very straightforward.  Reading the code should be more than enough to figure it out.  I guess we&#8217;ll just have to wait for a more exciting problem.</p>
<p><strong>Problem #6</strong><br />
Description: Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> ProblemSix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> sumSquares <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #0000ff;">int</span> sumNumbers <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>; i <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">100</span>; i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    sumSquares <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">*</span> i<span style="color: #008000;">&#41;</span>;
    sumNumbers <span style="color: #000040;">+</span><span style="color: #000080;">=</span> i;
  <span style="color: #008000;">&#125;</span>
&nbsp;
  sumNumbers <span style="color: #000040;">*</span><span style="color: #000080;">=</span> sumNumbers;
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>sumNumbers <span style="color: #000040;">-</span> sumSquares<span style="color: #008000;">&#41;</span>;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/11/project-euler-problem-6/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #5</title>
		<link>http://www.danielpedigo.com/2008/11/07/project-euler-problem-5/</link>
		<comments>http://www.danielpedigo.com/2008/11/07/project-euler-problem-5/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 15:01:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=67</guid>
		<description><![CDATA[Here is actually the problem that originally turned me onto Project Euler.  The idea here is to find the smallest number that can be divided evenly by the numbers one through twenty.  Now, the beginner might think to check each number against the numbers one through twenty until they found the smallest number. [...]]]></description>
			<content:encoded><![CDATA[<p>Here is actually the problem that originally turned me onto <a href="http://projecteuler.net/">Project Euler</a>.  The idea here is to find the smallest number that can be divided evenly by the numbers one through twenty.  Now, the beginner might think to check each number against the numbers one through twenty until they found the smallest number.  While this works, it&#8217;s not quite as efficient as it could be.  For instance, what do the numbers four, eight and sixteen have in common?  What about seven and fourteen?  They all have common factors.</p>
<p><b>Problem #5</b><br />Description: What is the smallest number divisible by each of the numbers 1 to 20?<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> ProblemFive<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> n <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>;
&nbsp;
  <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">true</span> <span style="color: #008000;">&#41;</span> 
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">19</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">18</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span>
         n <span style="color: #000040;">%</span> <span style="color: #0000dd;">17</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">16</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span>
         n <span style="color: #000040;">%</span> <span style="color: #0000dd;">15</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">14</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span>
         n <span style="color: #000040;">%</span> <span style="color: #0000dd;">13</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #000040;">&amp;&amp;</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">11</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">return</span> n;
    <span style="color: #008000;">&#125;</span>
&nbsp;
    n++;
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/07/project-euler-problem-5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Project Euler: Problem #4</title>
		<link>http://www.danielpedigo.com/2008/11/06/project-euler-problem-4/</link>
		<comments>http://www.danielpedigo.com/2008/11/06/project-euler-problem-4/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 22:38:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[Project Euler Problems]]></category>

		<guid isPermaLink="false">http://www.danielpedigo.com/?p=65</guid>
		<description><![CDATA[While the code below is not the most elegant, it&#8217;s definitely functional and to be fair, was written in maybe 10 minutes.  Regardless, I&#8217;m really looking forward to some of these upcoming problems!  Some of them are looking HARD.
Problem #4Description: Find the largest palindrome made from the product of two 3-digit numbers.&#160;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include &#60;stdlib.h&#62;
#include [...]]]></description>
			<content:encoded><![CDATA[<p>While the code below is not the most elegant, it&#8217;s definitely functional and to be fair, was written in maybe 10 minutes.  Regardless, I&#8217;m really looking forward to some of these upcoming problems!  Some of them are looking HARD.</p>
<p><b>Problem #4</b><br />Description: Find the largest palindrome made from the product of two 3-digit numbers.<br />&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339900;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> ProblemFour<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> result <span style="color: #000080;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> palindrome <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #008000;">&#93;</span>;
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">999</span>; i <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">100</span>; i<span style="color: #000040;">--</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> j <span style="color: #000080;">=</span> <span style="color: #0000dd;">999</span>; i <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">100</span>; j<span style="color: #000040;">--</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">int</span> temp <span style="color: #000080;">=</span> i <span style="color: #000040;">*</span> j;
      itoa<span style="color: #008000;">&#40;</span>temp, palindrome, <span style="color: #0000dd;">10</span><span style="color: #008000;">&#41;</span>;
&nbsp;
      <span style="color: #666666;">// Our palindrome will be of the even variety...</span>
      <span style="color: #0000ff;">int</span> length <span style="color: #000080;">=</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>palindrome<span style="color: #008000;">&#41;</span>;
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> length <span style="color: #000040;">%</span> <span style="color: #0000dd;">2</span> <span style="color: #000080;">==</span> <span style="color:#800080;">0</span> <span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> pFront <span style="color: #000080;">=</span> palindrome;
        <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> pEnd <span style="color: #000080;">=</span> palindrome <span style="color: #000040;">+</span> length <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span>;
&nbsp;
        <span style="color: #666666;">// check to see if it is a palindrome</span>
        <span style="color: #0000ff;">bool</span> isPalindrome <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span>;
        <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> pEnd <span style="color: #000080;">&gt;</span> pFront <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #000040;">*</span>pFront <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">*</span>pEnd <span style="color: #008000;">&#41;</span>
          <span style="color: #008000;">&#123;</span>
            isPalindrome <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span>;
            <span style="color: #0000ff;">break</span>;
          <span style="color: #008000;">&#125;</span>
&nbsp;
          pFront++;
          pEnd--;
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> isPalindrome <span style="color: #000040;">&amp;&amp;</span> temp <span style="color: #000080;">&gt;</span> result <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          result <span style="color: #000080;">=</span> temp;
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000dd;">delete</span> palindrome;
  <span style="color: #0000ff;">return</span> result;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielpedigo.com/2008/11/06/project-euler-problem-4/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
