<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments for Nerd Fortress</title>
	<atom:link href="http://nerdfortress.com/index.php/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://nerdfortress.com</link>
	<description>Where a Nerd can be a Nerd</description>
	<pubDate>Sun, 06 Jul 2008 11:46:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>Comment on B Work is Bad for the Soul: What Goes Wrong Behind Blockbuster Movies by Toys Toys and More Toys &#187; Blog Archive &#187; B Work is Bad for the Soul: What Goes Wrong Behind Blockbuster Movies</title>
		<link>http://nerdfortress.com/index.php/2008/06/04/b-work-is-bad-for-the-soul-what-goes-wrong-behind-blockbuster-movies/#comment-55</link>
		<dc:creator>Toys Toys and More Toys &#187; Blog Archive &#187; B Work is Bad for the Soul: What Goes Wrong Behind Blockbuster Movies</dc:creator>
		<pubDate>Thu, 05 Jun 2008 04:44:04 +0000</pubDate>
		<guid isPermaLink="false">http://nerdfortress.com/?p=32#comment-55</guid>
		<description>[...] Read the rest of this great post here [...]</description>
		<content:encoded><![CDATA[<p>[...] Read the rest of this great post here [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Using Windows Server 2008 workstation - Audio Stutters? by Yves</title>
		<link>http://nerdfortress.com/index.php/2008/03/12/using-windows-server-2008-workstation-audio-stutters/#comment-31</link>
		<dc:creator>Yves</dc:creator>
		<pubDate>Mon, 19 May 2008 16:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://nerdfortress.com/?p=12#comment-31</guid>
		<description>thank you very much! i'm running server 2008 under virtualbox, and suspected the virtualization as source of the problem.</description>
		<content:encoded><![CDATA[<p>thank you very much! i&#8217;m running server 2008 under virtualbox, and suspected the virtualization as source of the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Ruby on Rails: Let&#8217;s Get Real by Randal L. Schwartz</title>
		<link>http://nerdfortress.com/index.php/2008/05/13/ruby-on-rails-lets-get-real/#comment-24</link>
		<dc:creator>Randal L. Schwartz</dc:creator>
		<pubDate>Tue, 13 May 2008 18:33:27 +0000</pubDate>
		<guid isPermaLink="false">http://nerdfortress.com/?p=22#comment-24</guid>
		<description>If you want a web application framework that *does* have a good, mature IDE, and scales better than RoR, take a look at Seaside (http://seaside.st), written in portable Smalltalk.</description>
		<content:encoded><![CDATA[<p>If you want a web application framework that *does* have a good, mature IDE, and scales better than RoR, take a look at Seaside (http://seaside.st), written in portable Smalltalk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Programming Challenge: Time Parser by Random Boy</title>
		<link>http://nerdfortress.com/index.php/2008/02/14/programming-challenge-time-parser/#comment-4</link>
		<dc:creator>Random Boy</dc:creator>
		<pubDate>Mon, 25 Feb 2008 16:22:14 +0000</pubDate>
		<guid isPermaLink="false">http://nerdfortress.com/?p=5#comment-4</guid>
		<description>Back in college I discovered the &lt;a href="http://www.quit-clan.de/docwiki/view.php?pageid=1" rel="nofollow"&gt;D programming language&lt;/a&gt;. Just for kicks, I used it for a project in my machine learning class. I really liked D's blance of elegance and speed. Now, several years later, the language has grown up quite a bit and seems to be a valid contender for game and systems programming. I thought this excercise would be a good way to get back into the language.

Here is my solution to this month's challenge using the D language. I could have used regular expressions, but wanted to see how fast a hand-coded algorithm would be.

&lt;pre&gt;
import tango.io.Console;
import tango.io.Stdout;
import Float = tango.text.convert.Float;
import tango.stdc.ctype;
import tango.time.StopWatch;

const int MAX_PARTS = 3;
const int BUFFER_SIZE = 1024;
char[BUFFER_SIZE] numberBuffer;

void waitEnter()
{
  Cout("\nPress Enter to continue").flush;
  Cin.get();
}

// We will build the result in a single pass. This should be rather fast.
// For each time we encounter, grab the components, then calculate the total seconds.	
char[] parse(char[] timeString)
{
  // Add a space at the end to trigger the close of the final token
  timeString = timeString.dup ~ ' ';
	
  // Look into putting these on the stack to make even faster
  char[] result;
  int numberBufferIndex;
	
  bool insideTime;
  bool insideNumber;
  double[MAX_PARTS] parts;
  int partIndex = 0;
  char[100] conversionBuffer = void;

  foreach(char c; timeString)
  {
    if (isdigit(c) &#124;&#124; (insideTime &#038;&#038; c == '.'))
    {			
      if (!insideTime)
      {
        insideTime = true;
      }

      numberBuffer[numberBufferIndex++] = c;
    }
    else if (insideTime)
    {
      parts[partIndex++] = Float.parse(numberBuffer[0..numberBufferIndex]);
      numberBufferIndex = 0;

      // See if we just left a time token
      if (c == ' ')
      {
        double totalSeconds = 0;
        for (int i = partIndex-1, m = 1; i &gt;=0; i--, m *= 60)
        {
          totalSeconds += parts[i] * m;
        }

        result ~= Float.format(conversionBuffer, totalSeconds);
        result ~= ' ';
        
        insideTime = false;
        partIndex = 0;
        parts[] = 0;
      }
    }
    else
    {
        // Not part of a time token
        result = result ~ c;
    }		
  }

  return result;
}

int main(char[][] args)
{
  char[] input = args[0];
  //input = "1:45.2 + 83 - 2:34";

  StopWatch elapsed;
  elapsed.start;

  int loopTimes = 10000;
  for (int i = 0; i &lt; loopTimes; i++)
  {
    parse(input);
  }

  double timePerLoop = elapsed.stop / loopTimes;
	
  Cout("Parsing: " ~ input).newline;
  Cout("Result: " ~ parse(input)).newline;

  Stdout.formatln("Time to parse: {0:f4} ms", timePerLoop * 1000);

  waitEnter();
  return 0;
}
&lt;/pre&gt;

This bad boy runs the example problem in under .0027 ms on my 2.4 GHz Core2 Duo running Vista x64.</description>
		<content:encoded><![CDATA[<p>Back in college I discovered the <a href="http://www.quit-clan.de/docwiki/view.php?pageid=1" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.quit-clan.de');" rel="nofollow">D programming language</a>. Just for kicks, I used it for a project in my machine learning class. I really liked D&#8217;s blance of elegance and speed. Now, several years later, the language has grown up quite a bit and seems to be a valid contender for game and systems programming. I thought this excercise would be a good way to get back into the language.</p>
<p>Here is my solution to this month&#8217;s challenge using the D language. I could have used regular expressions, but wanted to see how fast a hand-coded algorithm would be.</p>
<pre>
import tango.io.Console;
import tango.io.Stdout;
import Float = tango.text.convert.Float;
import tango.stdc.ctype;
import tango.time.StopWatch;

const int MAX_PARTS = 3;
const int BUFFER_SIZE = 1024;
char[BUFFER_SIZE] numberBuffer;

void waitEnter()
{
  Cout(&#8221;\nPress Enter to continue&#8221;).flush;
  Cin.get();
}

// We will build the result in a single pass. This should be rather fast.
// For each time we encounter, grab the components, then calculate the total seconds.
char[] parse(char[] timeString)
{
  // Add a space at the end to trigger the close of the final token
  timeString = timeString.dup ~ &#8216; &#8216;;

  // Look into putting these on the stack to make even faster
  char[] result;
  int numberBufferIndex;

  bool insideTime;
  bool insideNumber;
  double[MAX_PARTS] parts;
  int partIndex = 0;
  char[100] conversionBuffer = void;

  foreach(char c; timeString)
  {
    if (isdigit(c) || (insideTime &#038;&#038; c == &#8216;.&#8217;))
    {
      if (!insideTime)
      {
        insideTime = true;
      }

      numberBuffer[numberBufferIndex++] = c;
    }
    else if (insideTime)
    {
      parts[partIndex++] = Float.parse(numberBuffer[0..numberBufferIndex]);
      numberBufferIndex = 0;

      // See if we just left a time token
      if (c == &#8216; &#8216;)
      {
        double totalSeconds = 0;
        for (int i = partIndex-1, m = 1; i >=0; i&#8211;, m *= 60)
        {
          totalSeconds += parts[i] * m;
        }

        result ~= Float.format(conversionBuffer, totalSeconds);
        result ~= &#8216; &#8216;;

        insideTime = false;
        partIndex = 0;
        parts[] = 0;
      }
    }
    else
    {
        // Not part of a time token
        result = result ~ c;
    }
  }

  return result;
}

int main(char[][] args)
{
  char[] input = args[0];
  //input = &#8220;1:45.2 + 83 - 2:34&#8243;;

  StopWatch elapsed;
  elapsed.start;

  int loopTimes = 10000;
  for (int i = 0; i < loopTimes; i++)
  {
    parse(input);
  }

  double timePerLoop = elapsed.stop / loopTimes;

  Cout("Parsing: " ~ input).newline;
  Cout("Result: " ~ parse(input)).newline;

  Stdout.formatln("Time to parse: {0:f4} ms", timePerLoop * 1000);

  waitEnter();
  return 0;
}
</pre>
<p>This bad boy runs the example problem in under .0027 ms on my 2.4 GHz Core2 Duo running Vista x64.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Programming Challenge: Time Parser by Mr. ANSI Pants</title>
		<link>http://nerdfortress.com/index.php/2008/02/14/programming-challenge-time-parser/#comment-3</link>
		<dc:creator>Mr. ANSI Pants</dc:creator>
		<pubDate>Fri, 22 Feb 2008 17:23:52 +0000</pubDate>
		<guid isPermaLink="false">http://nerdfortress.com/?p=5#comment-3</guid>
		<description>Here's my whack at it in PHP.

&lt;pre&gt;
&#60;?php
function array_swap(&#038;$array, $key1, $key2)
{
	if ($key1 == $key2) return;

	$array[$key1] += $array[$key2];
	$array[$key2] = $array[$key1] - $array[$key2];
	$array[$key1] -= $array[$key2];
}

function convert_time($original)
{
	$pieces = explode(':', $original);
	array_swap($pieces, 0, count($pieces) - 1);

	if (count($pieces) == 1 &#038;&#038; !is_numeric($pieces[0]))
	{
		return $original;
	}

	$result = 0;
	$multiplier = 1;
	foreach ($pieces as $piece)
	{
		$result += $piece * $multiplier;
		$multiplier *= 60;
	}

	return $result;
}

function convert_expression($expression)
{
	$pieces = preg_split('/[\s]+/', $expression);
	$pieces = array_map('convert_time', $pieces);
	return implode(' ', $pieces);
}

echo convert_expression('1:45.2 + 83 - 2:34');
?&#62;
&lt;/pre&gt;

-Mr. ANSI Pants

P.S.  I just timed this sucker on my 2.66 GHz Core2 Duo (running Windows XP Pro) and averaged 0.04 milliseconds on the example problem.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my whack at it in PHP.</p>
<pre>
&lt;?php
function array_swap(&#038;$array, $key1, $key2)
{
	if ($key1 == $key2) return;

	$array[$key1] += $array[$key2];
	$array[$key2] = $array[$key1] - $array[$key2];
	$array[$key1] -= $array[$key2];
}

function convert_time($original)
{
	$pieces = explode(&#8217;:', $original);
	array_swap($pieces, 0, count($pieces) - 1);

	if (count($pieces) == 1 &#038;&#038; !is_numeric($pieces[0]))
	{
		return $original;
	}

	$result = 0;
	$multiplier = 1;
	foreach ($pieces as $piece)
	{
		$result += $piece * $multiplier;
		$multiplier *= 60;
	}

	return $result;
}

function convert_expression($expression)
{
	$pieces = preg_split(&#8217;/[\s]+/&#8217;, $expression);
	$pieces = array_map(&#8217;convert_time&#8217;, $pieces);
	return implode(&#8217; &#8216;, $pieces);
}

echo convert_expression(&#8217;1:45.2 + 83 - 2:34&#8242;);
?&gt;
</pre>
<p>-Mr. ANSI Pants</p>
<p>P.S.  I just timed this sucker on my 2.66 GHz Core2 Duo (running Windows XP Pro) and averaged 0.04 milliseconds on the example problem.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.145 seconds -->
