<?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>JOEZACK.COM &#187; code</title>
	<atom:link href="http://joezack.com/index.php" rel="self" type="application/rss+xml" />
	<link>http://joezack.com</link>
	<description>Code Musings and Such</description>
	<lastBuildDate>Sat, 02 Jul 2011 04:43:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Project Euler : Problem 39 in Ruby</title>
		<link>http://joezack.com/index.php/2011/07/02/project-euler-problem-39-in-ruby/</link>
		<comments>http://joezack.com/index.php/2011/07/02/project-euler-problem-39-in-ruby/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 04:43:42 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1638</guid>
		<description><![CDATA[I had an easy time with this one, which makes me feel a lot better about all the ones I had problems with! No fancy-pants recursion or math short-cuts here, just a straight forward logic problem. The only "trick" here is to realize that since a &lte; b &#60; c, we only need to check [...]]]></description>
			<content:encoded><![CDATA[<p>I had an easy time with this one, which makes me feel a lot better about all the ones I had problems with!</p>
<p>No fancy-pants recursion or math short-cuts here, just a straight forward logic problem. The only "trick" here is to realize that since  a &lte; b &lt; c, we only need to check values of a and b up to 499.</p>
<p>I'm sure you could whittle that number down by crunching the numbers, but it's good enough for me!</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=39" target="_blank" title="Project Euler : Problem 39">Problem 39</a></p>
<blockquote><p>For which value of p  1000, is the number of solutions maximised?</p></blockquote>
<pre name="code" class="ruby">counts = {}
counts.default = 0

(1..499).each do |a|
  (a..499).each do |b|
    break if a + b > 500
    c = Math.sqrt(a**2 + b**2)
    next unless c.denominator == 1
    counts[a + b + c] += 1
  end
end

sorted = counts.sort { |a, b| a[1] <=> b[1] }

puts sorted.last[0]</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+39+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+39+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+39+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F&amp;headline=Project+Euler+%3A+Problem+39+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler+%3A+Problem+39+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler+%3A+Problem+39+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler+%3A+Problem+39+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler+%3A+Problem+39+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler+%3A+Problem+39+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+39+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F07%2F02%2Fproject-euler-problem-39-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2011/07/02/project-euler-problem-39-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler : Problem 38 in Ruby</title>
		<link>http://joezack.com/index.php/2011/06/27/project-euler-problem-38-in-rub/</link>
		<comments>http://joezack.com/index.php/2011/06/27/project-euler-problem-38-in-rub/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 01:19:33 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1614</guid>
		<description><![CDATA[40 problems down, 10 more till level 2! The real trick here is to cut down on the numbers you check. Since the problem gives you 918273645 as an example we know the answer must be greater than or equal to it...meaning we only need to check digits that start with 9! I don't actually [...]]]></description>
			<content:encoded><![CDATA[<p>40 problems down, 10 more till <a href="http://projecteuler.net/index.php?section=scores&level=2" title="Project Euler : Level 2" target="_blank">level 2</a>!</p>
<p>The real trick here is to cut down on the numbers you check. Since the problem gives you 918273645 as an example we know the answer must be greater than or equal to it...meaning we only need to check digits that start with 9!</p>
<p>I don't actually do it because I couldn't figure out an elegant way to do, but it runs in just a few milliseconds so it's fast enough in my book.</p>
<p>Another important factor to note is that you only need to check numbers up to 9_876 since this is the first 'half' of the largest pandigital possible.</p>
<p>Those two tricks will cut down the calculations you need to run to just a few thousand.</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=38" title="Problem 38" title="_blank">Problem 38</a></p>
<blockquote><p>What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n  1?</p></blockquote>
<pre name="code" class="ruby">def get_pandigital? n
  nums = []
  (1..9).each do |digit|
    nums += (n * digit).to_s.split ''
    return 0 if nums.size != nums.uniq.size || nums.include?('0')
    return nums.join('').to_i if nums.size == 9
  end
end

solution = 0

(9..9_876).each do |n|
  # could do better by only looking at 9's!
  result = get_pandigital? n
  if result > solution
    solution = result
  end
end

puts solution</pre>
<p>Check out <a href="https://bitbucket.org/thejoezack/project-euler/src" target="_blank" title="Project Euler Solutions">all of my solutions</a> on bitbucket!</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F&amp;title=Project+Euler+%3A+Problem+38+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F&amp;title=Project+Euler+%3A+Problem+38+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F&amp;title=Project+Euler+%3A+Problem+38+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F&amp;headline=Project+Euler+%3A+Problem+38+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler+%3A+Problem+38+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler+%3A+Problem+38+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler+%3A+Problem+38+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler+%3A+Problem+38+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler+%3A+Problem+38+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F&amp;title=Project+Euler+%3A+Problem+38+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F06%2F27%2Fproject-euler-problem-38-in-rub%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2011/06/27/project-euler-problem-38-in-rub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler: Problem 37 in Ruby</title>
		<link>http://joezack.com/index.php/2011/05/17/project-euler-problem-37-in-ruby/</link>
		<comments>http://joezack.com/index.php/2011/05/17/project-euler-problem-37-in-ruby/#comments</comments>
		<pubDate>Wed, 18 May 2011 03:37:54 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1602</guid>
		<description><![CDATA[It's been a while since I've done one of these, so I was afraid of being rusty but it worked out alright. I used the generator I made a while back to create the primes (pre-filled to the example given in the project) and used procs to take care of the truncation. BAM! Problem 37 [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a while since I've done one of these, so I was afraid of being rusty but it worked out alright. I used <a href="https://bitbucket.org/thejoezack/project-euler/src/bd1f266e8cc0/prime_generator.rb" target="_blank" title="Prime Number Generator">the generator</a> I made a while back to create the primes (pre-filled to the example given in the project) and used procs to take care of the truncation.</p>
<p><strong>BAM!</strong></p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=37" title="Problem 37" target="_blank">Problem 37</a></p>
<blockquote><p>The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.</p>
<p>Find the sum of the only eleven primes that are both truncatable from left to right and right to left.
</p></blockquote>
<pre name="code" class="ruby">load 'prime_generator.rb'

def prime? n, truncate
  return false if !$primer.is_prime?(n)
  return true if n < 10
  prime? truncate.call(n), truncate
end

left = Proc.new { |n| n / 10 }
right = Proc.new { |n| n % 10**Math.log10(n).to_i }

$primer = Prime_Generator.new 3_797
n, sum, found = 0, 0, 0

while found < 11 do
  if (n += 1) > 10 && prime?(n, left) && prime?(n, right)
    found += 1
    sum += n
  end
end

puts sum</pre>
<p>Also, I've finally moved my project euler solutions over to <a href="https://bitbucket.org/thejoezack/project-euler/src" title="Project Euler Solutions on Bitbucket" target="_blank">bitbucket</a>. Long live Mercurial!</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F&amp;title=Project+Euler%3A+Problem+37+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F&amp;title=Project+Euler%3A+Problem+37+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F&amp;title=Project+Euler%3A+Problem+37+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F&amp;headline=Project+Euler%3A+Problem+37+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler%3A+Problem+37+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler%3A+Problem+37+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler%3A+Problem+37+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler%3A+Problem+37+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler%3A+Problem+37+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F&amp;title=Project+Euler%3A+Problem+37+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F05%2F17%2Fproject-euler-problem-37-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2011/05/17/project-euler-problem-37-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To uint, or not to uint</title>
		<link>http://joezack.com/index.php/2011/03/07/to-uint-or-not-to-uint/</link>
		<comments>http://joezack.com/index.php/2011/03/07/to-uint-or-not-to-uint/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 03:14:34 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1528</guid>
		<description><![CDATA[I like unsigned integers, always have. It's more correct, concise and expressive, you get more (positive) space out of it and you're preventing bugs by design. What's not to love? Well... I've been nooking CLR via C# and it's a fantastic read for anyone who wants to 'get serious' about .Net. The book's so crammed [...]]]></description>
			<content:encoded><![CDATA[<p>I like unsigned integers, always have. It's more correct, concise and expressive, you get more (positive) space out of it and you're preventing bugs by design. What's not to love?</p>
<p>Well...</p>
<p>I've been <a href="http://www.barnesandnoble.com/nook">nooking</a> <a href="http://oreilly.com/catalog/9780735627048/">CLR via C#</a> and it's a fantastic read for anyone who wants to 'get serious' about .Net. The book's so crammed full of good information it's hard not to gush, but I digress.</p>
<p>I was nooking, you see, and I came across this recommendation:</p>
<blockquote><p>"Use signed data types (such as Int32 and Int64 instead of unsigned numeric types such as UInt32 and UInt64) wherever possible."</p></blockquote>
<div align="center">
<h2>Say it aint so!</h2>
<p><iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/ENXvZ9YRjbo" frameborder="0" allowfullscreen></iframe>
</div>
<p>Jeffrey Richter continues:</p>
<blockquote><p>"This allows the compiler to detect more overflow/underflow errors. In addition, various parts of the class library (such as Array's and String's Length properties) are hard-coded to return signed values, and less casting is required as you move these values around in your code."</p></blockquote>
<p>Casting is ugly, no argument there but I don't care much about the overflow/underflow errors. I generally don't enable overflow checking, there's no political statement here, it's just never come up.</p>
<p>And it still feels wrong for me to declare a value signed when I know that it shouldn't be.</p>
<p>(Richter recommends enabling checking for debug builds, and disabling for release. Sound advice!)</p>
<p>But here's real the kicker for me:</p>
<blockquote><p>In addition, unsigned numeric types are not CLS-compliant.</p></blockquote>
<p>Doh. I did a bit of searching to try and track down why it's not part of the CLS, and I found that <a href="http://blogs.msdn.com/b/brada/archive/2003/09/02/50285.aspx">Brad Abrams expresses it best in this post</a>:</p>
<blockquote><p>"The general feeling among many of us is that the vast majority of programming is done with signed types.  Whenever you switch to unsigned types you force a mental model switch (and an ugly cast).  In the worst cast you build up a whole parallel world of APIs that take unsigned types.  The value of avoiding the '< 0' check is not worth the inclusion of generics in the CLS"</p></blockquote>
<p>Alright, I give in. I'm apparently in the minority, these guys are way smarter than I am, and it is easier, if not more concise. So it goes.</p>
<p>Goodbye for now uint, you'll always hold a positive place in my heart.</p>
<p>Just like <a href="http://www.amazon.com/Pinkerton-Weezer/dp/B000000OVP/ref=sr_1_1?ie=UTF8&qid=1299554017&sr=8-1">Weezer</a>:</p>
<div align="center"><iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/okthJIVbi6g" frameborder="0" allowfullscreen></iframe></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F&amp;title=To+uint%2C+or+not+to+uint" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F&amp;title=To+uint%2C+or+not+to+uint" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F&amp;title=To+uint%2C+or+not+to+uint" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F&amp;headline=To+uint%2C+or+not+to+uint" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=To+uint%2C+or+not+to+uint&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=To+uint%2C+or+not+to+uint&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=To+uint%2C+or+not+to+uint&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=To+uint%2C+or+not+to+uint&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=To+uint%2C+or+not+to+uint&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F&amp;title=To+uint%2C+or+not+to+uint&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2011%2F03%2F07%2Fto-uint-or-not-to-uint%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2011/03/07/to-uint-or-not-to-uint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler: Problem 35 in Ruby</title>
		<link>http://joezack.com/index.php/2010/10/23/project-euler-problem-35-in-ruby/</link>
		<comments>http://joezack.com/index.php/2010/10/23/project-euler-problem-35-in-ruby/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 01:51:02 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1503</guid>
		<description><![CDATA[I used my prime generator from Problem 27 for this one. It would have been faster to build the rotation into my generator, but it ran fine without it. Problem 35 How many circular primes are there below one million? require 'prime_generator' primer = Prime_Generator.new 1_000_000 def is_rot_prime? primer, chars chars.size.times do &#124;i&#124; chars = [...]]]></description>
			<content:encoded><![CDATA[<p>I used my prime generator from Problem 27 for this one. It would have been faster to build the rotation into my generator, but it ran fine without it.</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=35">Problem 35</a></p>
<blockquote><p>How many circular primes are there below one million?</p></blockquote>
<pre name="code" class="ruby">require 'prime_generator'

primer = Prime_Generator.new 1_000_000

def is_rot_prime? primer, chars
	chars.size.times do |i|
		chars = Array.new(chars.size) { |i| chars[i - 1] }
		return false if !primer.is_prime?(chars.join("").to_i)
	end
	true
end

count = 0
primer.stack.each do |n|
	count += 1 if is_rot_prime? primer, n.to_s.split("")
end

# subtract 1 because "1" doesn't count
puts count - 1</pre>
<p>Speaking of the rotation, the ruby array initialize methods and negative indexers make it a cinch to rotate. How cool is this?</p>
<pre name="code" class="ruby">chars = Array.new(chars.size) { |i| chars[i - 1] }</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F&amp;title=Project+Euler%3A+Problem+35+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F&amp;title=Project+Euler%3A+Problem+35+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F&amp;title=Project+Euler%3A+Problem+35+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F&amp;headline=Project+Euler%3A+Problem+35+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler%3A+Problem+35+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler%3A+Problem+35+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler%3A+Problem+35+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler%3A+Problem+35+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler%3A+Problem+35+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F&amp;title=Project+Euler%3A+Problem+35+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-35-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/23/project-euler-problem-35-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler: Problem 34 in Ruby</title>
		<link>http://joezack.com/index.php/2010/10/23/project-euler-problem-34-in-ruby/</link>
		<comments>http://joezack.com/index.php/2010/10/23/project-euler-problem-34-in-ruby/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 00:10:49 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1500</guid>
		<description><![CDATA[Practically every Project Euler problem benefits from memoization, however the issues I ran into with #34 had nothing to do with my algorithm. The first hurdle was figuring out the upper bound. After scratching around in my notebook, I figured any number I would be looking for would have 7 digits or less. That gives [...]]]></description>
			<content:encoded><![CDATA[<p>Practically every Project Euler problem benefits from <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a>, however the issues I ran into with #34 had nothing to do with my algorithm.</p>
<p>The first hurdle was figuring out the upper bound. After scratching around in my notebook, I figured any number I would be looking for would have 7 digits or less. That gives us an upper bound of 9! * 7.  </p>
<p>The second hurde took me much, much longer to figure out.</p>
<p>Here's the secret: <strong>0! = 1</strong></p>
<p>I had taken it for granted that 0! would (of course!) be 0, and I had pre-filled my cache with the number 0. I went round, and round, and round, and round, and round, and round before figuring out (quite accidentally) my error.</p>
<p>It doesn't make any sense to me, but you can't argue with math!</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=34">Problem 34</a></p>
<blockquote><p>Find the sum of all numbers which are equal to the sum of the factorial of their digits.</p></blockquote>
<pre name="code" class="ruby"># cache the digit factorials
factorials = [1]
(1..9).each do |i|
	factorials.push(i * factorials.last)
end

result = 0
(3..2_540_160).each do |n|
	sum = n.to_s.split("").inject(0) do |sum,n|
		sum + factorials[n.to_i]
	end
	result += n if n == sum
end
puts result</pre>
<p>Runs in just under a minute <img src='http://joezack.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F&amp;title=Project+Euler%3A+Problem+34+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F&amp;title=Project+Euler%3A+Problem+34+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F&amp;title=Project+Euler%3A+Problem+34+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F&amp;headline=Project+Euler%3A+Problem+34+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler%3A+Problem+34+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler%3A+Problem+34+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler%3A+Problem+34+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler%3A+Problem+34+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler%3A+Problem+34+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F&amp;title=Project+Euler%3A+Problem+34+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-34-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/23/project-euler-problem-34-in-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Project Euler : Problem 36 in Ruby</title>
		<link>http://joezack.com/index.php/2010/10/23/project-euler-problem-36-in-ruby/</link>
		<comments>http://joezack.com/index.php/2010/10/23/project-euler-problem-36-in-ruby/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 22:59:41 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1492</guid>
		<description><![CDATA[I've been ill today, but there's no better medicine than an easy Project Euler problem! I tried doing some bitwise magic, but in the end my simplest solution proved the fastest as well. Problem 36 Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. def [...]]]></description>
			<content:encoded><![CDATA[<p>I've been ill today, but there's no better medicine than an easy Project Euler problem! I tried doing some bitwise magic, but in the end my simplest solution proved the fastest as well.</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=36">Problem 36</a></p>
<blockquote><p>Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.</p></blockquote>
<pre name="code" class="ruby">def palindrome? s
	s == s.reverse
end

sum = (1..1_000_000).inject(0) do |sum, n|
	sum += palindrome?(n.to_s) && palindrome?(n.to_s 2) ? n : 0
end

puts sum</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+36+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+36+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+36+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F&amp;headline=Project+Euler+%3A+Problem+36+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler+%3A+Problem+36+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler+%3A+Problem+36+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler+%3A+Problem+36+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler+%3A+Problem+36+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler+%3A+Problem+36+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F&amp;title=Project+Euler+%3A+Problem+36+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F23%2Fproject-euler-problem-36-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/23/project-euler-problem-36-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Project Euler: Problem 33 in Ruby</title>
		<link>http://joezack.com/index.php/2010/10/22/project-euler-problem-33-in-ruby/</link>
		<comments>http://joezack.com/index.php/2010/10/22/project-euler-problem-33-in-ruby/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 01:34:16 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1496</guid>
		<description><![CDATA[It's fugly, but it works. The hardest part was understanding the question. If the longer description didn't say that there were exactly 4 fractions, I might have gone crazy. For reals. Problem 33 Discover all the fractions with an unorthodox cancelling method. top, bottom = 1, 1 (10..98).each do &#124;i&#124; ((i/10)..9).each do &#124;jt&#124; jt *= [...]]]></description>
			<content:encoded><![CDATA[<p>It's fugly, but it works. The hardest part was understanding the question. If the longer description didn't say that there were exactly 4 fractions, I might have gone crazy.</p>
<p>For reals.</p>
<p><a href="http://projecteuler.net/index.php?section=problems&id=33">Problem 33</a></p>
<blockquote><p>Discover all the fractions with an unorthodox cancelling method.</p></blockquote>
<pre name="code" class="ruby">top, bottom = 1, 1

(10..98).each do |i|
	((i/10)..9).each do |jt|
		jt *= 10
		(1..9).each do |jo|
			j = jt + jo
			next if i >= j
			if i % 10 == j / 10 && i.to_f / j == (i / 10).to_f / (j % 10)
				top *= i
				bottom *= j
			end
		end
	end
end

puts bottom / bottom.gcd(top)</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F&amp;title=Project+Euler%3A+Problem+33+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F&amp;title=Project+Euler%3A+Problem+33+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F&amp;title=Project+Euler%3A+Problem+33+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F&amp;headline=Project+Euler%3A+Problem+33+in+Ruby" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Project+Euler%3A+Problem+33+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Project+Euler%3A+Problem+33+in+Ruby&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Project+Euler%3A+Problem+33+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Project+Euler%3A+Problem+33+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Project+Euler%3A+Problem+33+in+Ruby&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F&amp;title=Project+Euler%3A+Problem+33+in+Ruby&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F22%2Fproject-euler-problem-33-in-ruby%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/22/project-euler-problem-33-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the Longest Palindrome in a String</title>
		<link>http://joezack.com/index.php/2010/10/20/find-the-longest-palindrome-in-a-string/</link>
		<comments>http://joezack.com/index.php/2010/10/20/find-the-longest-palindrome-in-a-string/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 03:51:43 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming praxis]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1482</guid>
		<description><![CDATA[I recently discovered programmingpraxis.com, and one of the more recent posts dealt with one of the greplin programming challenges. I figured since people were posting their code there, then it wouldn't be too bad for me to post mine here! Find the Longest Palindrome in a string: I doubt this is an optimal solution, but [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered <a href="http://programmingpraxis.com">programmingpraxis.com</a>, and one of the more recent posts dealt with one of the <a href="http://challenge.greplin.com/">greplin programming challenges</a>. I figured since people were posting their code there, then it wouldn't be too bad for me to post mine here!</p>
<p><a href="http://programmingpraxis.com/2010/10/15/find-the-longest-palindrome-in-a-string/">Find the Longest Palindrome in a string:</a></p>
<p>I doubt this is an optimal solution, but I like how it works:</p>
<pre name="code" class="ruby">
text = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth"

def find_longest_palindrome s1, size
	longest = ""

	s1.size.times do |start|
		break if start + size > s1.size
		s2 = s1[start, size].reverse
		if s1.include? s2
			return s2
		end
	end

	find_longest_palindrome s1, size - 1
end

puts find_longest_palindrome(text, text.length)</pre>
<p>I found the site via this post, <a href="http://sixrevisions.com/resources/10-puzzle-websites-to-sharpen-your-programming-skills/">10 puzzle websites to sharpen your programming skills</a>. Now that the wedding's over (pics soon!) I can't wait to get back to a regular extracurricular programming schedule!</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F&amp;title=Find+the+Longest+Palindrome+in+a+String" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F&amp;title=Find+the+Longest+Palindrome+in+a+String" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F&amp;title=Find+the+Longest+Palindrome+in+a+String" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F&amp;headline=Find+the+Longest+Palindrome+in+a+String" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Find+the+Longest+Palindrome+in+a+String&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Find+the+Longest+Palindrome+in+a+String&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Find+the+Longest+Palindrome+in+a+String&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Find+the+Longest+Palindrome+in+a+String&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Find+the+Longest+Palindrome+in+a+String&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F&amp;title=Find+the+Longest+Palindrome+in+a+String&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F20%2Ffind-the-longest-palindrome-in-a-string%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/20/find-the-longest-palindrome-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Greplin Programming Challenge</title>
		<link>http://joezack.com/index.php/2010/10/08/the-greplin-programming-challenge/</link>
		<comments>http://joezack.com/index.php/2010/10/08/the-greplin-programming-challenge/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 02:55:25 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://joezack.com/?p=1480</guid>
		<description><![CDATA[My fiancee's gone to bed, so I'm bragging to you dear internet. I just completed The Greplin Programming Challenge! The problems were similar to some of the Project Euler problems I've done, but it was still a lot of fun. I can't wait for the next one! The End]]></description>
			<content:encoded><![CDATA[<p>My fiancee's gone to bed, so I'm bragging to you dear internet.</p>
<p>I just completed <a href="http://challenge.greplin.com/">The Greplin Programming Challenge</a>! The problems were similar to some of the Project Euler problems I've done, but it was still a lot of fun. I can't wait for the next one!</p>
<p>The End</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F&amp;title=The+Greplin+Programming+Challenge" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F&amp;title=The+Greplin+Programming+Challenge" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F&amp;title=The+Greplin+Programming+Challenge" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F&amp;headline=The+Greplin+Programming+Challenge" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=The+Greplin+Programming+Challenge&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=The+Greplin+Programming+Challenge&amp;u=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=The+Greplin+Programming+Challenge&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=The+Greplin+Programming+Challenge&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=The+Greplin+Programming+Challenge&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F&amp;title=The+Greplin+Programming+Challenge&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fjoezack.com%2Findex.php%2F2010%2F10%2F08%2Fthe-greplin-programming-challenge%2F" ><img class="lightsocial_img" src="http://joezack.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://joezack.com/index.php/2010/10/08/the-greplin-programming-challenge/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

