<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Mad Computer Science</title>
	<atom:link href="http://madcs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://madcs.wordpress.com</link>
	<description>Enslaving the human race, one opcode at a time.</description>
	<lastBuildDate>Sat, 16 Apr 2011 09:23:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='madcs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Mad Computer Science</title>
		<link>http://madcs.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://madcs.wordpress.com/osd.xml" title="Mad Computer Science" />
	<atom:link rel='hub' href='http://madcs.wordpress.com/?pushpress=hub'/>
		<item>
		<title>On Memory Hogs and Compression, Part 1.</title>
		<link>http://madcs.wordpress.com/2009/09/23/on-memory-hogs-and-compression-part-1/</link>
		<comments>http://madcs.wordpress.com/2009/09/23/on-memory-hogs-and-compression-part-1/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 19:28:04 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Everything]]></category>

		<guid isPermaLink="false">http://madcs.wordpress.com/?p=58</guid>
		<description><![CDATA[A discussion of how we distort pictures to store them on computers.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=58&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A line I picked up from one of my high school Computer Science teachers: &#8220;Graphics are memory hogs.&#8221;  Computers represent pictures as a big grid of colors.  Each cell in this grid is called a pixel (short for &#8220;picture element&#8221;), and usually has an ordered triple of numbers representing what color it should be.  When these pixels are very small and numerous, the picture looks less like a collection of squares, and more like the picture represented.  A similar effect is used to shade and color graphics in newspapers; look closely enough and you&#8217;ll notice that the colors are made up of lots of tiny colored dots.  Let&#8217;s look at an example&#8230;<span id="more-58"></span></p>
<div id="attachment_59" class="wp-caption alignnone" style="width: 460px"><a href="http://madcs.files.wordpress.com/2009/09/pm2-path.png"><img class="size-full wp-image-59" title="PM2-Path" src="http://madcs.files.wordpress.com/2009/09/pm2-path.png?w=450&#038;h=337" alt="A screenshot of Paper Mario 2" width="450" height="337" /></a><p class="wp-caption-text">A screenshot of Paper Mario 2</p></div>
<p>Here, we see trees, bushes, Mario, his friend, and a monster, all pretty clearly.  Now, let&#8217;s look closer at Mario&#8217;s head:</p>
<div id="attachment_62" class="wp-caption alignnone" style="width: 460px"><a href="http://madcs.files.wordpress.com/2009/09/pm2-zoomed.png"><img class="size-full wp-image-62" title="PM2-Zoomed" src="http://madcs.files.wordpress.com/2009/09/pm2-zoomed.png?w=450&#038;h=337" alt="Zooming in on Mario's head" width="450" height="337" /></a><p class="wp-caption-text">Zooming in on Mario&#39;s head</p></div>
<p>Looking closer, we clearly see the grid.  Each of these squares shows the average of all the colors that are underneath it in the &#8220;actual&#8221; picture being rendered.</p>
<p>Why do we represent pictures like this?  For one, it&#8217;s mathematically easy to deal with pictures like this when programming.  In most of today&#8217;s computing, we only represent colors in images with a set of three numbers between 0 and 255, one for red, one for green, and one for blue.  So (255, 0, 0) would be red, (0, 0, 0) would be black, (255, 128, 128) would be pink, and so on.  I pose a similar question for representing colors: why do we limit the resolution of each frequency to 256 digits?</p>
<p>The answer to both of these questions, of course, is that &#8220;the human eye isn&#8217;t bothered by it.&#8221;  We can&#8217;t see much of a difference between the shades of blue that would be represented by (0, 0, 190) and (0, 0, 190.5), so we don&#8217;t bother with it.  Note: This isn&#8217;t entirely true; in some cases, like in the 3D programming interface &#8220;OpenGL,&#8221; we represent the strength of the red, green, and blue channels by decimal numbers between 0.0 and 1.0.  So (0.743, 0.16513, 0.1665) would be valid for a &#8220;faded red&#8221; sort of color.  We still don&#8217;t have infinite precision with this method, but, like I&#8217;ve said, we don&#8217;t really <em>need</em> it.</p>
<p>Similarly, we&#8217;re usually okay with seeing a grid of square pixels to represent pictures, text, and so on, as long as the pixels are really tiny.  Even a modern &#8220;high definition&#8221; television, which is sold to make everything look realistic, uses a grid 1,920 pixels wide and 1,080 pixels tall to represent its picture&#8211;note that this is certainly an improvement from the old &#8220;standard definition&#8221; of 640 pixels wide and 480 pixels tall, but you might not have noticed the blockiness in it because most standard definition televisions blurred the lines between pixels by nature (there&#8217;s also interleaving, but I won&#8217;t get into that here).</p>
<p>But is a big matrix of 3-tuples of bytes the most efficient way to represent an image, never mind being easy to work with?  The example picture I gave above is 800 pixels wide and 600 pixels tall.  Each color takes three bytes to store its (red, green, blue) values.  So 800×600 pixels × 3 bytes/pixel = 1,440,000 bytes.  That&#8217;s one and a half million integers, each between 0 and 255, to give us a decent-sized picture.  Certainly, a picture being &#8220;worth a thousand words&#8221; holds in cases like these.</p>
<p>Thankfully, data compression can help.  Compression is a way to &#8220;summarize&#8221; a file, cutting out redundancies wherever practical, to achieve a smaller file that still sufficiently represents the original file.  An image compression algorithm might say, &#8220;there&#8217;s a rectangle at coordinates (63, 75) that is 104 pixels wide and 52 pixels tall filled with the color (37, 160, 67).&#8221;  Roughly, that&#8217;s two bytes to store the position, two bytes to store the dimensions, and three bytes to store the color&#8211;let&#8217;s say it takes one byte to store the instruction to draw a rectangle, and we are using 1+2+2+3 = 8 bytes to store a piece of an image that would&#8217;ve normally taken 104×52×3 = 16,224 bytes.</p>
<p>If the image uses 256 or fewer colors, we can compress even better, using a &#8220;palette&#8221; of sorts.  Basically, all the different colors that are used in the image are stored in the palette, which will be 256×3 bytes long, at most.  Then, in storing the image, instead of storing the color over and over again for each pixel, using three bytes apiece, we can simply use one byte to refer to which color in the palette.  So instead of saying (26, 45, 23), we can say &#8220;the 14th color in the palette&#8221; and, in some cases, save some space.</p>
<p>We can go even further on that idea.  Say the image uses more than 256 colors.  We can &#8220;merge&#8221; many similar colors to an average color in the palette, losing some information about the picture, but letting it fit the &#8220;256 color palette&#8221; paradigm from the paragraph above.  Nothing is particularly special about the number 256, mind you, other than that it&#8217;s the size of the palettes in the popular image compression formats GIF and PNG-8 (and that it&#8217;s the upper bound of numbers that fit in one byte).  16-color palettes are commonly used in video games on consoles like the <abbr title="Super Nintendo Entertainment System">SNES</abbr>, Sega Genesis, and Nintendo DS.</p>
<p>Another interesting way to save space is to only save half the colors in the picture.  Perhaps surprisingly, you can still keep the compressed image looking reasonably close to the original in this way.  Using a method called <abbr title="S3 Texture Compression">S3TC</abbr> (sometimes called &#8220;DXTn&#8221;), only two colors out of every 2×2 pixel block are stored, and the remaining two colors are &#8220;guessed&#8221; based on an average of the two that were stored.  This is a very popular way to compress textures used in modern video games; just about every modern graphics processor has support for S3TC built into its hardware.  In fact, Paper Mario 2 uses this format to store most of its textures:<br />
<div id="attachment_77" class="wp-caption alignnone" style="width: 378px"><a href="http://madcs.files.wordpress.com/2009/09/pm2-mariotexture.png"><img class="size-full wp-image-77" title="PM2-MarioTexture" src="http://madcs.files.wordpress.com/2009/09/pm2-mariotexture.png?w=450" alt="A Mario texture extracted from Paper Mario 2, demonstrating S3TC"   /></a><p class="wp-caption-text">A Mario texture extracted from Paper Mario 2, demonstrating S3TC</p></div>Look for the splotches of color that don&#8217;t look quite right.</p>
<p>There are even more things we can do to compress a picture.  The JPEG format, developed by the Joint Photographic Experts Group, uses some advanced tricks that work well on photograph-like images to save space.  It often introduces artefacts, which are most noticeable when more aggressive settings are used to compress.  Often enough, though, these aren&#8217;t too noticeable on photographs and photograph-like images.  JPEG is horribly distorting for non-photographic images, especially those containing sharp transitions between colors, like text.</p>
<p>All of these schemes are retrofitted over the existing &#8220;grid&#8221; I described earlier.  The &#8220;lossy&#8221; schemes (shrinking the palette, guessing pixels, and using JPEG-like tricks) lose even <em>more</em> information on top of the existing loss of any information that didn&#8217;t fit into w×h discrete squares of ℤ<sub>256</sub> triplets.  Only images that are intended to be made of such squares to begin with can be represented &#8220;losslessly&#8221; in such a grid.  Note that these do exist, many artists produce what is called &#8220;pixel art&#8221; designed exactly for this medium.</p>
<p>However, in some cases, we can represent a picture even <em>more</em> accurately than raster graphics, often using even <em>fewer</em> bytes to do so.  This is possible when the picture is drawn as a &#8220;vector&#8221; image.  A vector art program stores the geometry of what is being drawn mathematically, so that curves, gradients, and so on scale nicely to any size when rendered.  Vector formats store exactly what was drawn, describing the curves, edges, and colors exactly as the artist intended, rather than storing an approximation of it in pixels.</p>
<p>Such an approach is only possible, of course, for graphics drawn on a computer.  Digital scanners and cameras with limited <abbr title="Dots Per Inch">DPI</abbr> and resolution can only store a certain number of &#8220;dots.&#8221;  Perhaps in the future, a more advanced sort of camera could store a lower level of information, describing how the light passed through its lens differently, in such a way that the picture could be reproduced in a process similar to rasterizing a vector image.  This is probably rather far-fetched, though; I&#8217;m not exactly a photography expert.</p>
<p>TODO: Discuss similarities to audio and music.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=58&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/09/23/on-memory-hogs-and-compression-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>

		<media:content url="http://madcs.files.wordpress.com/2009/09/pm2-path.png" medium="image">
			<media:title type="html">PM2-Path</media:title>
		</media:content>

		<media:content url="http://madcs.files.wordpress.com/2009/09/pm2-zoomed.png" medium="image">
			<media:title type="html">PM2-Zoomed</media:title>
		</media:content>

		<media:content url="http://madcs.files.wordpress.com/2009/09/pm2-mariotexture.png" medium="image">
			<media:title type="html">PM2-MarioTexture</media:title>
		</media:content>
	</item>
		<item>
		<title>Done purely for the Hack Value.</title>
		<link>http://madcs.wordpress.com/2009/08/10/done-purely-for-the-hack-value/</link>
		<comments>http://madcs.wordpress.com/2009/08/10/done-purely-for-the-hack-value/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 00:57:24 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://madcs.wordpress.com/?p=51</guid>
		<description><![CDATA[Hooray for the PC. Nobody would actually play like this, mind you, but the fact that they all run without conflict is certainly impressive-looking! I&#8217;d say &#8220;see if you can name all the games!&#8221; but many of them are showing title screens. See if you can name all the consoles being emulated!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=51&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://i29.tinypic.com/24vijnm.png"></p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 310px"><a href="http://madcs.files.wordpress.com/2009/08/agathacubeful.jpg"><img class="size-medium wp-image-54" title="AgathaCubeful" src="http://madcs.files.wordpress.com/2009/08/agathacubeful.jpg?w=300&#038;h=225" alt="Several emulated video games running on the sides of a Compiz desktop cube" width="300" height="225" /></a><p class="wp-caption-text">Several emulated video games running on the sides of a Compiz desktop cube</p></div>
<p></a> Hooray for the PC.  Nobody would actually <em>play</em> like this, mind you, but the fact that they all run without conflict is certainly impressive-looking!<br />
I&#8217;d say &#8220;see if you can name all the games!&#8221; but many of them are showing title screens.  See if you can name all the consoles being emulated!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=51&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/08/10/done-purely-for-the-hack-value/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>

		<media:content url="http://madcs.files.wordpress.com/2009/08/agathacubeful.jpg?w=300" medium="image">
			<media:title type="html">AgathaCubeful</media:title>
		</media:content>
	</item>
		<item>
		<title>Constructing an 8-bit music application for the NDS.</title>
		<link>http://madcs.wordpress.com/2009/06/30/constructing-an-8-bit-music-application-for-the-nds/</link>
		<comments>http://madcs.wordpress.com/2009/06/30/constructing-an-8-bit-music-application-for-the-nds/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 22:16:15 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://madcs.wordpress.com/?p=7</guid>
		<description><![CDATA[I&#8217;ve started to code an 8-bit music tool, inspired by the work of 8-bit artists like Bit Shifter and Bubblyfish, both of whom were brilliant to see live at the concert of Stevens Anime Club&#8217;s annual Castle Point Anime Convention earlier this year. The two aforementioned musicians compose and perform their music on the Nintendo [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=7&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to code an 8-bit music tool, inspired by the work of 8-bit artists like <a href="http://bit.shifter.net/">Bit Shifter</a> and <a href="http://www.bubblyfish.com/">Bubblyfish</a>, both of whom were brilliant to see live at the concert of Stevens Anime Club&#8217;s annual <a href="http://www.stevens.edu/anime/cpac/">Castle Point Anime Convention</a> earlier this year.  The two aforementioned musicians compose and perform their music on the Nintendo Game Boy (as do <a href="http://www.8bitpeoples.com/discography?show=all">many other 8-bit musicians</a>), using its <abbr title="Programmable Sound Generator">PSG</abbr> to generate the blips and beeps of various frequencies that make up their songs.</p>
<p>The Game Boy Advance is generally used for this, presumably the last of the &#8220;Game Boy&#8221; series of hardware from Nintendo, because it has hardware backwards-compatibility to all the software of the original Game Boy, and because the older Game Boys are just that&#8211;older, harder to come by, and more likely to be broken.</p>
<p>The Nintendo DS isn&#8217;t backwards-compatible with the older Game Boy software, but it is backwards-compatible with <abbr title="Game Boy Advance">GBA</abbr> software.  Since the GBA exposed the original Game Boy&#8217;s PSG to GBA-specific software, the DS must also provide that functionality, so the same type of PSG was included in the DS hardware.  This is fortunate, since the DS is relatively easy to develop for, thanks to <a href="http://devkitpro.org/">devkitPro</a>.  An example of the use of the PSG in the DS can be found in the very nifty <a href="http://dev-scene.com/NDS/AXE">AXE</a>, written by PinEight.</p>
<p>I have no experience with other existing 8-bit music composition software, but I do have knowledge of music theory (thanks to my brilliant professor <a href="http://www.andybrick.com/">Andy Brick</a>, who coincidentally has composed and conducted quite a bit of video game music&#8211;check it out!), and I am trying to work both of these facts to my advantage in an effort to make a unique and useful interface for my application.  One of my ideas for a user interface involves a selection of chords that would be valid in syntactic progression, where the program takes care of all the voice leading rules after the user has given all the specifics of what he or she wants to be used.</p>
<p>There are some other ideas floating around in my head, too.  For now, the interface is very simple: a proof of concept using Zelda 64 &#8220;Ocarina-like&#8221; controls (the C-buttons map to A, B, X, and Y, and the A button maps to the DS&#8217; R).  I&#8217;ll post more on this project as I make progress on it.  In the meantime, check out some of <a href="http://www.8bitpeoples.com/discography?show=all#8BP059">Bit Shifter&#8217;s Information Chase album</a>, available for download for free!  (In MP3 format, I know, I&#8217;m sorry)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=7&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/06/30/constructing-an-8-bit-music-application-for-the-nds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding the most efficient way to be a college student during the summer</title>
		<link>http://madcs.wordpress.com/2009/06/18/finding-the-most-efficient-way-to-be-a-college-student-during-the-summer/</link>
		<comments>http://madcs.wordpress.com/2009/06/18/finding-the-most-efficient-way-to-be-a-college-student-during-the-summer/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 20:22:54 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://madcs.wordpress.com/?p=17</guid>
		<description><![CDATA[Throughout the course of my stay at Stevens, I've found that, as a college student, one of the most important things to know (if not <em>the</em> most important thing) is where and how I'm going to get my next <a href="http://catb.org/~esr/jargon/html/A/ANSI-standard-pizza.html">pizza</a>.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=17&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Throughout the course of my stay at Stevens, I&#8217;ve found that, as a college student, one of the most important things to know (if not <em>the</em> most important thing) is where and how I&#8217;m going to get my next <a href="http://catb.org/~esr/jargon/html/A/ANSI-standard-pizza.html">pizza</a>.</p>
<p>In a normal semester, there are many events run by student organizations, clubs, and the like, where each use part of their budget to get some pizzas to attract more people to their events.  This is the most cost-efficient way to obtain pizza (short of someone finding some way to get paid to eat pizza (I&#8217;m all ears&#8211;if you&#8217;ve heard of anything like this, <em>please</em> comment)).  It&#8217;s also good because the pizzas often come from one of the many fine pizza restaurants in Hoboken.</p>
<p>The second-most efficient method relates to the dreaded <a href="http://stevensdiningservices.com/plans.html">meal plan</a>.  Any student here living in on-campus housing that doesn&#8217;t have a kitchen in his or her room, with certain exceptions, has to be on the meal plan.  The meal plan has you pay a constant price up front for an &#8220;unlimited&#8221; number of times to be let in to the dining hall.  The dining hall has an all-you-can-eat buffet, with pizza and various other foods (that rotate day to day).  The pizza is <em>okay</em>, I certainly don&#8217;t expect to hold it up to proper Hoboken Italian restaurant standards; that would be rather ridiculous to expect of a campus dining hall.  But if it&#8217;s already been paid for, cashing in on the meal plan is a viable method by which to acquire pizza.</p>
<p>Unfortunately, there&#8217;s not always a free-pizza event going on, especially during the summer.  Worse yet, the dining hall is closed during the summer.  This means the pizza money has to come out of my own pocket.  There are many places to choose from here, and I need to determine how I can get the most pizza for the least amount of money.  So, I wrote a small, trivial application in C++ (which should be understandable to beginners) that compares an arbitrary number of pizza places based on the amount of pizza you get for the price you pay (per slice).</p>
<p><pre class="brush: cpp;">
#include &lt;algorithm&gt; // for sort()
#include &lt;iostream&gt; // for simple i/o
#include &lt;cstdlib&gt; // this is really only here for aesthetic purposes
#include &lt;vector&gt; // nicer to use than arrays, especially with stl algorithm
#include &lt;cmath&gt; // for M_PI

struct pizza_attribs {
	int num;  // index so we know who's the best after sorting
	int slices;  // the number of pieces, not the number of cuts.
	float diameter; // width of the pie
	float slice_cost;  // slice price
	float bang_for_buck;  // = (slice area)/price
};

using namespace std;

bool pa_compare(pizza_attribs a, pizza_attribs b) {
	return a.bang_for_buck &gt; b.bang_for_buck;
}

int main() {
	vector&lt;pizza_attribs&gt; pa_list;
	int count;

	cout &lt;&lt; &quot;Be consistent with your units!&quot; &lt;&lt; endl &lt;&lt; endl;
	cout &lt;&lt; &quot;How many places to compare? &quot;;
	cin &gt;&gt; count;
	for(int i = 0; i &lt; count; ++i) {
		pizza_attribs pie;

		pie.num = i;
		cout &lt;&lt; &quot;[pizza place #&quot;&lt;&lt;i&lt;&lt;&quot;] Price of a slice of pizza? &quot;;
		do { cin &gt;&gt; pie.slice_cost; } while(pie.slice_cost &lt;= 0);
		cout &lt;&lt; &quot;[pizza place #&quot;&lt;&lt;i&lt;&lt;&quot;] Number of slices in a pie? &quot;;
		do { cin &gt;&gt; pie.slices; } while(pie.slices &lt;= 0);
		cout &lt;&lt; &quot;[pizza place #&quot;&lt;&lt;i&lt;&lt;&quot;] Diameter of the pie? &quot;;
		do { cin &gt;&gt; pie.diameter; } while(pie.diameter &lt;= 0);

		pie.bang_for_buck = ((M_PI*pow(pie.diameter/2, 2))
		                     / pie.slices) / pie.slice_cost;

		pa_list.push_back(pie);
		cout &lt;&lt; endl;
	}

	sort(pa_list.begin(), pa_list.end(), pa_compare);

	cout &lt;&lt; &quot;The results are in!&quot; &lt;&lt; endl;
	for(int i = 0; i &lt; pa_list.size(); ++i) {
		cout &lt;&lt; &quot;[pizza place #&quot;&lt;&lt;pa_list[i].num&lt;&lt;&quot;] bang for buck: &quot;
		  &lt;&lt; pa_list[i].bang_for_buck/pa_list[0].bang_for_buck &lt;&lt; endl;
	}

	return 0;
}
</pre></p>
<p>For example, the two closest pizza places to me right now are <a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;sll=40.743668,-74.028982&amp;hl=en&amp;q=benny+tudino%27s&amp;ie=UTF8&amp;update=1&amp;sspn=0.000000,0.000000&amp;vps=1&amp;jsv=163d&amp;latlng=40744239,-74029117,9704986407736334850&amp;ei=4586SrupC4rWMM_ErOQD&amp;cd=1&amp;dtab=2&amp;pcsi=9704986407736334850,1">Benny Tudino&#8217;s</a> and <a href="http://maps.google.com/maps?q=603+Washington+Street,Hoboken,+NJ+07030&amp;ie=UTF8&amp;hl=en&amp;sll=40.743668,-74.028982&amp;sspn=0.006295,0.006295&amp;latlng=40743546,-74028923,7820519856757041947&amp;ei=gp86SoqPF4mCNOizzIoE&amp;cd=3">H&amp;S Giovanni&#8217;s</a>.  Benny&#8217;s slices are taken from a 28-inch pie, sliced into 8 pieces, and cost $3.00 apiece.  Gio&#8217;s slices are taken from a 22-inch pie, sliced into 8 pieces and cost $3.00 apiece (one can already intuitively figure out that you&#8217;d get more pizza from Benny&#8217;s).  According to this program, you get an estimated 61.7% of the pizza at Gio&#8217;s that you would at Benny&#8217;s.</p>
<p>Now, this program makes some unreasonable assumptions: Namely, it assumes that all pizzas are of the same thickness, and it doesn&#8217;t factor in how good the pizza tastes.  However, it makes objectively comparing pizza slices by area versus price a little bit easier.</p>
<p>TODO: Factor in distance to restaurant?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=17&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/06/18/finding-the-most-efficient-way-to-be-a-college-student-during-the-summer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>
	</item>
		<item>
		<title>The Obsolescence of Tool-Assisted Speed-running</title>
		<link>http://madcs.wordpress.com/2009/06/18/the-obsolescence-of-tool-assisted-speed-running/</link>
		<comments>http://madcs.wordpress.com/2009/06/18/the-obsolescence-of-tool-assisted-speed-running/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 06:38:02 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Everything]]></category>

		<guid isPermaLink="false">http://madcs.wordpress.com/?p=10</guid>
		<description><![CDATA[Some time ago, <a href="http://hotwigati.wordpress.com/">navaburo</a> and I were hanging out in my dorm room, and we ended up thinking about the concept of writing an AI to find the best (shortest) path through a video game.  A couple days later, we went down to the <a href="http://tarantula.phy.stevens.edu/wiki/index.php/Linux_Lab">Linux Lab</a> and fleshed out the idea on paper.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=10&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>(And later, its adaptation into an exercise in human computing and cooperative single-player gaming)</p>
<p>Some time ago, <a href="http://hotwigati.wordpress.com/">navaburo</a> and I were hanging out in my dorm room, and we ended up thinking about the concept of writing an <abbr title="Artificial Intelligence">AI</abbr> to find the best (shortest) path through a video game.  A couple days later, we went down to the <a href="http://tarantula.phy.stevens.edu/wiki/index.php/Linux_Lab">Linux Lab</a> and fleshed out the idea on paper.</p>
<p>For those unfamiliar with the concept of &#8220;Tool-Assisted Speed-running,&#8221; it is a process done by some video game enthusiasts in which they play a game on a an emulated (or &#8220;virtual&#8221;) machine, using special features of the emulator to let them more easily make an almost &#8220;perfect run&#8221; of the game, where they complete the primary objective as quickly as possible.  This usually involves slowing down the game to give them the opportunity to take shortcuts and pull off maneuvers that wouldn&#8217;t have been possible with the limitations of human reaction time and reflexes.  Sometimes, they also use &#8220;luck manipulation,&#8221; which involves taking a snapshot of the machine&#8217;s state (also known as a &#8220;savestate&#8221;) before an event that relies on a &#8220;random&#8221; number, and restoring the machine to that state again and again, until a desired number is generated.  Similarly, they often use this functionality to rewind the gameplay in case they make a mistake.  When a speed-runner completes a game this way, he or she might post a replay of the &#8220;run&#8221; on the internet to share with others; there are communities on the web in which speed-runners will compete to complete classic video games with the fastest times they can manage.</p>
<p>navaburo and I theorized that, using an emulator for a given video game console, we could calculate the fastest possible path through the game by using a search on all of the possible inputs starting from the machine&#8217;s initial state.  This is most likely very impractical to compute, even for the relatively sophisticated computer hardware we have today.  Nevertheless, we decided that as long as we could provably calculate the optimal path to do some trivial task, we could also calculate the optimal path to the very end of the game.  For proof of concept, we decided on <a href="http://en.wikipedia.org/wiki/Super_Mario_Bros.">Super Mario Bros.</a> for the <abbr title="Nintendo Entertainment System">NES</abbr>, and we&#8217;d call the program &#8220;OptiMario.&#8221;  We spent some time looking into ways to bootstrap our search into the input functions of various open-source NES emulators, including the popular <a href="http://fceultra.sourceforge.net/">FCE Ultra</a> and <a href="http://nestopia.sourceforge.net/">Nestopia</a>, before deciding that for our purposes, the simpler (and lesser-known) <a href="http://packages.debian.org/stable/otherosfs/nestra">NEStra</a> would suffice.  So far, we&#8217;ve hacked the beginnings of a foundation for this project into NEStra.</p>
<p>I won&#8217;t go too much into our methods just yet, mostly because we still haven&#8217;t implemented it and the exact method we end up using might change.  However, in theory, it seems we might be able to create an artificial &#8220;ultimate speed-runner&#8221; that is able to complete a game in the fastest <em>possible</em> time, perhaps even using glitches and shortcuts previously unknown (if it can be done with a valid input string, and it shaves seconds off the final elapsed time, such a program (properly implemented) will find it).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=10&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/06/18/the-obsolescence-of-tool-assisted-speed-running/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello World!</title>
		<link>http://madcs.wordpress.com/2009/06/17/hello-world/</link>
		<comments>http://madcs.wordpress.com/2009/06/17/hello-world/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 21:22:02 +0000</pubDate>
		<dc:creator>madcs</dc:creator>
				<category><![CDATA[Everything]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[So good of you to join me.  I'll be posting here about my various projects and whatever else I think is interesting enough to post.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=1&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><code>++++++++++[&gt;+++++++&gt;++++++++++&gt;+++&gt;+&lt;&lt;&lt;&lt;-]&gt;++.&gt;+.+++++++..+++.&gt;++.&lt;&lt;+++++++++++++++.&gt;.+++.------.--------.&gt;+.&gt;.</code></p>
<p>So good of you to join me.  I&#8217;ll be posting here about my various projects and whatever else I think is interesting enough to post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/madcs.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/madcs.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/madcs.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=madcs.wordpress.com&amp;blog=8220093&amp;post=1&amp;subd=madcs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://madcs.wordpress.com/2009/06/17/hello-world/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64e0fa344152a451170bc597178b8fbc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">madcs</media:title>
		</media:content>
	</item>
	</channel>
</rss>
