<?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>Math + CS = 11</title>
	<atom:link href="http://geoffsquared.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://geoffsquared.com</link>
	<description>Because Orange \gg Green</description>
	<lastBuildDate>Tue, 09 Mar 2010 20:04:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Book Review: TextMate Power Editing for the Mac</title>
		<link>http://geoffsquared.com/2010/03/book-review-textmate-power-editing-for-the-mac/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2010/03/book-review-textmate-power-editing-for-the-mac/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 20:04:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Book Review]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=135</guid>
		<description><![CDATA[TextMate: Power Editing for the Mac accomplishes exactly what it set it  to – show you how powerful TextMate really is and how to use this power  to do exactly what you want.  James Gray has put something for every  level of user into his book.  The novice and average TextMate users [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="Textmate" src="http://ecx.images-amazon.com/images/I/416WB7WEFTL.jpg" alt="" width="168" height="200" />TextMate: Power Editing for the Mac accomplishes exactly what it set it  to – show you how powerful TextMate really is and how to use this power  to do exactly what you want.  James Gray has put something for every  level of user into his book.  The novice and average TextMate users will  gain a breadth of knowledge about keyboard shortcuts as well as seeing  how a few of the built in bundles can help them increase efficiency.   The TextMate gurus out there can even learn about building their own  language grammars for TextMate to recognize.</p>
<p>The book is organized into three major sections with appropriate  chapters in each.  In the first section, Gray shows how to effectively  use TextMate’s project drawer for managing your work, explains  TextMate’s Emacs-like keyboard shortcuts, and demonstrates the power of  the find and replace features with regular expressions.  The second  section shows TextMate’s strength in automating things you would  normally type thereby saving you time and preventing typos. The final  section explains how to write a language grammar yourself and provides a  concrete example of such an implementation.</p>
<p>Despite being somewhat of a manual, the book is very readable with  pictures, simple explanations, and some jokes tossed in.  Although the  book isn’t a quick reference or a complete guide, it is very easy to  find what you are looking for and contains a large amount of information  along with examples.  If you are looking for a good reference book on  the TextMate editor, definitely look into this one as it should contain  everything you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2010/03/book-review-textmate-power-editing-for-the-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back Up Your Twitter Posts</title>
		<link>http://geoffsquared.com/2010/02/back-up-your-twitter-posts/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2010/02/back-up-your-twitter-posts/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 08:10:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=132</guid>
		<description><![CDATA[One of the things that bugs me about Twitter is the inability to efficiently search through the tweets that you have made and the tweets that others have made. There have been countless times where I am thinking &#8220;I know I tweeted about this a month or two ago, where is it.&#8221;
I have decided to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that bugs me about Twitter is the inability to efficiently search through the tweets that you have made and the tweets that others have made. There have been countless times where I am thinking &#8220;I know I tweeted about this a month or two ago, where is it.&#8221;</p>
<p>I have decided to solve this problem myself and start to backup my own twitter account and the accounts of people who I care about. I grab all the tweets of a person using the twython twitter module for Python that I can and store them in a MySQL database for me to do various manipulations on and what not. I also wrote a simple PHP script to query my database and display all the information in a &#8220;nice&#8221; way. Instead of breaking the tweets up into pages of 20 each, I&#8217;d rather see all the tweets at the same time.</p>
<p>If you are interested in looking more into this project, here is my GitHub account where the project is located: <a href="http://github.com/geoffhotchkiss/TwitterBackup">http://github.com/geoffhotchkiss/TwitterBackup </a>. I still have to add the Python file to setup the tables that I use to store the information and give the PHP files I wrote to display the tweets of everyone. Obviously my method isn&#8217;t for everyone since not everyone runs their own MySQL server and webserver, but I figure that those people who do would be interested in something like this.</p>
<p>There are some improvements I would like to make, like breaking the &#8220;getting a new user&#8221; and &#8220;updating current users&#8221; sections into different functions and asking the user what they would like to do. I should also reverse the order in which I am getting tweets. In my current implementation, I am retrieving the most recent tweets to the earliest tweet. This is a problem because sometimes the API doesn&#8217;t like to work or something funky goes on with the authentication and thus the program stops getting tweets. If I go from earliest to most recent, if there&#8217;s a problem, I will still be able to get the rest of the tweets that I missed the first time around. I also need to add a &#8220;sleep until I can ask for more&#8221; feature so that if you are near your allocated API calls,  the program can wait until you have more to continue running.</p>
<p>It would also be a good idea to request for the 20,000 API request limit since only 150 API calls to backup everyone&#8217;s tweets can be too low sometimes.</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2010/02/back-up-your-twitter-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSH Room Maker</title>
		<link>http://geoffsquared.com/2010/01/csh-room-maker/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2010/01/csh-room-maker/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 22:53:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[csh]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[room maker]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=127</guid>
		<description><![CDATA[One of the projects that I have wanted to work on for a while has been a web interface to setup and and preview a room layout. Rather than guessing as to if a certain layout will work and then hoping that the configuration is possible, it would be much nicer to just move the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the projects that I have wanted to work on for a while has been a web interface to setup and and preview a room layout. Rather than guessing as to if a certain layout will work and then hoping that the configuration is possible, it would be much nicer to just move the room around online and see what works and what does not. The best part about it is that there would be a way to send your roommate a copy to see what they think, rather than crappy ms paint drawings, and possibly come up with layouts that you wouldn&#8217;t have been able to before.</p>
<p>I have just completed a first version of a possible CSH Room Maker (<a href="http://www.csh.rit.edu/~geoff/roommaker">http://www.csh.rit.edu/~geoff/roommaker</a>) using HTML5 and it&#8217;s canvas to draw and move shapes around on the screen. Currently, you can click and drag the furniture around anywhere in the room. You can also overlay furniture if you plan on putting that piece of furniture under the other. I need to add formation to the layout about where the build in cabinets are, since they are obviously non-movable, allow for rotations of furniture, allow for input of custom dimensioned furniture, and allow for different room types.</p>
<p>Thus far, HTML5 and its canvas have not been too much of a pain to work with. I am new to JavaScript so I am sure that I am doing a lot of things wrong in my code, but I am happy with it for the most part and will probably work on condensing it when need be, but for right now it works. I am having problems getting keydown events to work properly, I cannot get them to register for some reason. Other than that, the tutorial on canvas at Mozilla Development Center (<a href="http://developer.mozilla.org">http://developer.mozilla.org</a>) is very good and very helpful to learning.</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2010/01/csh-room-maker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Review: The Manga Guide to Calculus</title>
		<link>http://geoffsquared.com/2010/01/book-review-the-manga-guide-to-calculus/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2010/01/book-review-the-manga-guide-to-calculus/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 07:54:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Book Review]]></category>
		<category><![CDATA[Calculus]]></category>
		<category><![CDATA[Manga]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=123</guid>
		<description><![CDATA[I have got to say, I am quite impressed with The Manga Guide to Calculus. As the title suggests, it is an introduction into the ideas of differential and integral calculus through the use of manga and a story line. The book fulfills on this goal and then some.
The Manga Guide to Calculus starts off [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="The Manga Guide to Calculus" src="http://images.amazon.com/images/P/1593271948.01.LZZZZZZZ.jpg" alt="title cover" width="273" height="362" />I have got to say, I am quite impressed with The Manga Guide to Calculus. As the title suggests, it is an introduction into the ideas of differential and integral calculus through the use of manga and a story line. The book fulfills on this goal and then some.</p>
<p>The Manga Guide to Calculus starts off with a brief introduction and review of functions. It then jumps right into derivatives, what they mean, and how to compute them. Integration is then considered along Taylor series and partial differentiation. Throughout the story, the guide frequently references real world applications in economics, physics, and chemistry, and explains problems in these fields through the use of calculus. The author also includes probability, statistics, and trigonometry sections with calculus explanations. Exercises exist at the end of each section for you to complete and solutions are presented at end of the book.</p>
<p>There are a few downsides to the manga style of presentation. Formal proofs and definitions do not lend themselves well to be included, and the book is certainly lacking in this area. There may also be some areas which the reader will have to go over a few times to fully understand and see how the book goes from one idea to the next because of the amount of information being presented.</p>
<p>I would recommend this book to those who want a brief review of calculus, beginners who want context as to its uses, and to those who enjoy reading a good math book. This book is not for those who need a thorough review since many important topics are skipped such as limits, related rates, and volumes of rotations. Overall, Hiroyuki Kojima and Shin Togami did an excellent job in writing and illustrating the book respectively, which makes The Manga Guide to Calculus a very different and attractive learning tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2010/01/book-review-the-manga-guide-to-calculus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone Post</title>
		<link>http://geoffsquared.com/2009/08/iphone-post/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/08/iphone-post/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 08:41:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/2009/08/iphone-post/</guid>
		<description><![CDATA[This is a test post from my iPhone with a picture attached. I hope this works!

]]></description>
			<content:encoded><![CDATA[<p>This is a test post from my iPhone with a picture attached. I hope this works!</p>
<p><a href="http://geoffsquared.com/wp-content/uploads/2009/08/p_1600_1200_7E84ACBB-18BE-4850-9FEE-4A018DAED6CA.jpeg#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img src="http://geoffsquared.com/wp-content/uploads/2009/08/p_1600_1200_7E84ACBB-18BE-4850-9FEE-4A018DAED6CA.jpeg" alt="" width="225" height="300" class="alignnone size-full wp-image-364" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/08/iphone-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Can Haz Four Color Theorem</title>
		<link>http://geoffsquared.com/2009/07/google-can-haz-four-color-theorem/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/07/google-can-haz-four-color-theorem/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 03:08:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[four color theorem]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=117</guid>
		<description><![CDATA[Google’s favicon has bothered me for a little while now – not because it looks bad, but because it uses five colors.
In graph theory, it is not very difficult to prove that any planar graph is five colorable. One proof of the theorem relies on the fact that if a graph is a K­5 it [...]]]></description>
			<content:encoded><![CDATA[<p>Google’s favicon has bothered me for a little while now – not because it looks bad, but because it uses five colors.</p>
<p>In graph theory, it is not very difficult to prove that any planar graph is five colorable. One proof of the theorem relies on the fact that if a graph is a K­<sub>5</sub> it is non-planar. Thus, at least one vertex must not be adjacent to a second and you can alternate between the colors of those two vertices to do the rest of the graph.</p>
<p>In Google’s main logo as seen on google.com, the logo uses blue, red, yellow, and green. Four colors. So far, so good. When you look at the favicon, they use blue, red, yellow, green, and white. Five colors. Some may argue that the white shouldn’t be counted because it is the background color, but I believe that when a logo needs the background as much as it does in Google’s favicon (without it there wouldn’t be a ‘g’) it should be counted.</p>
<p>The logo could easily be adjusted as to only use four colors. For example, the blue parts could be colored red and the white could be changed to blue. Or following along with the use of two blue parts and two red parts in Google’s main logo, the green color be yellow, the yellow in the g could be red and the g could be colored green instead of white. Problem solved.</p>
<p>Even the main logo could also be changed to accommodate for the white background either by changing the color of the ‘o’ or ‘l’ to blue or red and leaving the background white or the background could be changed to the original color of the ‘o’ or ‘l’.</p>
<p>&lt;/rant&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/07/google-can-haz-four-color-theorem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lights Out!</title>
		<link>http://geoffsquared.com/2009/07/lights-out/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/07/lights-out/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 23:38:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=114</guid>
		<description><![CDATA[
The other night I was kind of board so I decided to write a game in Python. I&#8217;ve already written a Hangman game, but that really isn&#8217;t any fun to play by myself since I haven&#8217;t implemented a random word feature. I was looking around online for a not so hard game to write and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" title="Lights Out" src="http://www.site.uottawa.ca/~yymao/projects/lightoutpic.jpg" alt="" width="225" height="300" /></p>
<p>The other night I was kind of board so I decided to write a game in Python. I&#8217;ve already written a Hangman game, but that really isn&#8217;t any fun to play by myself since I haven&#8217;t implemented a random word feature. I was looking around online for a not so hard game to write and I came accross Lights Out and my reaction was &#8220;OMG I TOTALLY REMEMBER THAT GAME&#8221; so I had to write it. It was pretty easy and I had a lot of fun writing it.</p>
<p>Here is a link to the files on GitHub: <a href="http://github.com/geoffhotchkiss/MyLightsOut/tree/master">http://github.com/geoffhotchkiss/MyLightsOut/tree/master</a></p>
<p>Here&#8217;s a list of extensions and things I wish to add to the game in no specific order:</p>
<ol>
<li>Error checking with user input</li>
<li>GUI</li>
<li>Wrapping</li>
<li>3d lights out!</li>
<li>Various shapes of boards to play on</li>
<li>Web interface</li>
<li>Solver</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/07/lights-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Who Doesn&#039;t Love Dynamic Programming</title>
		<link>http://geoffsquared.com/2009/06/who-doesnt-love-dynamic-programming/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/06/who-doesnt-love-dynamic-programming/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 03:04:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=108</guid>
		<description><![CDATA[I got kind of bored last night so I decided it would be a good idea to do some more playing around with Python and Project Euler. One of the problems that I really like is problem 14 and it asks to find the number under 1,000,000 which produces the longest chain when ran through [...]]]></description>
			<content:encoded><![CDATA[<p>I got kind of bored last night so I decided it would be a good idea to do some more playing around with Python and Project Euler. One of the problems that I really like is problem 14 and it asks to find the number under 1,000,000 which produces the longest chain when ran through the Collatz Conjecture. The idea behind the conjecture is that given the piece-wise function f(x) = x/2 if x is even or 3x+1 if x is odd, f(x) will converge down to 1 in the integers.</p>
<p>Here&#8217;s my Python code. I originally tried to to it with lists but it wasn&#8217;t working out so well so I decided to solve the problem using a dictionary. I also got kind of pissed when everything was off by like 1 index so I named my dictionary dick. Program outputted an answer in around 6.3 seconds. Not too bad&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> solution2<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
    dick = <span style="color: black;">&#123;</span><span style="color: #ff4500;">1</span>:<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>,n+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        count = <span style="color: #ff4500;">1</span>
        x = i
        <span style="color: #ff7700;font-weight:bold;">while</span> i <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">1</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> dick.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:
                count = count + <span style="color: #ff4500;">1</span> + dick<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> - <span style="color: #ff4500;">2</span>
                i = <span style="color: #ff4500;">1</span>
            <span style="color: #ff7700;font-weight:bold;">elif</span> even<span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:
                count = count + <span style="color: #ff4500;">1</span>
                i = i / <span style="color: #ff4500;">2</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                count = count + <span style="color: #ff4500;">1</span>
                i = <span style="color: #ff4500;">3</span><span style="color: #66cc66;">*</span>i + <span style="color: #ff4500;">1</span>
        dick<span style="color: black;">&#91;</span>x<span style="color: black;">&#93;</span> = count
    mysteps = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>dick.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> dick.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> v == mysteps:
            <span style="color: #ff7700;font-weight:bold;">return</span> k</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/06/who-doesnt-love-dynamic-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#039;s My String&#8230;</title>
		<link>http://geoffsquared.com/2009/06/its-my-string/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/06/its-my-string/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 09:44:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[bar codes]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Delicious Library 2]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Geoff's Theorem]]></category>
		<category><![CDATA[K&R2]]></category>
		<category><![CDATA[orange]]></category>
		<category><![CDATA[Shoes]]></category>
		<category><![CDATA[Zappos]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=104</guid>
		<description><![CDATA[Okay, I just had way too much fun writing this so I thought I&#8217;d post it. It&#8217;s exercise 4-1 in K&#038;R2. It&#8217;s pretty much &#8220;write a function which returns the rightmost index of some character in some string.&#8221;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include &#60;stdio.h&#62;
#include &#60;string.h&#62;
&#160;
int strindex&#40;char s&#91;&#93;, int t&#41;;
&#160;
char mystring&#91;&#93; = &#34;This is my string and I can cry if [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, I just had way too much fun writing this so I thought I&#8217;d post it. It&#8217;s exercise 4-1 in K&#038;R2. It&#8217;s pretty much &#8220;write a function which returns the rightmost index of some character in some string.&#8221;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> strindex<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">char</span> mystring<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;This is my string and I can cry if I want to.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> mychar <span style="color: #339933;">=</span> <span style="color: #ff0000;">'z'</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%c is at %d in %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> mychar<span style="color: #339933;">,</span> strindex<span style="color: #009900;">&#40;</span>mystring<span style="color: #339933;">,</span> mychar<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> mystring<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> strindex<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> t<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>t <span style="color: #339933;">==</span> s<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> i<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>On a somewhat more serious note, I have finally bought some new shoes (yay?) from Zappos.com. They&#8217;re orange and like all orange things, they are good. <strong>Geoff&#8217;s Theorem: If something is orange, then it is good.</strong></p>
<p>Another cool thing that every Mac user should play around with is Delicious Library 2. If you have never heard of it, think of it as a digital book shelf where you can display books, movies, video games, electronics, ect. that you own. The best part is that it lets you use your iSight camera to scan in the bar codes for everything! I got it as part of the Macheist bundle and have never played with it until now and I gotta tell you, scanning everything in is way more fun than it should be.</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/06/its-my-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C</title>
		<link>http://geoffsquared.com/2009/06/c/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://geoffsquared.com/2009/06/c/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 06:47:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[K&R2]]></category>
		<category><![CDATA[language]]></category>

		<guid isPermaLink="false">http://geoffsquared.com/?p=92</guid>
		<description><![CDATA[I&#8217;ve decided that I want to learn C instead of Haskell and Python now and am using the book to learn from. I gotta say, I&#8217;m very impressed with K&#38;R2. Absolutely great. The best part about the book is that it contains many exercises at the end of each section which gives you practice writing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided that I want to learn C instead of Haskell and Python now and am using <em>the book</em> to learn from. I gotta say, I&#8217;m very impressed with K&amp;R2. Absolutely great. The best part about the book is that it contains many exercises at the end of each section which gives you practice writing C programs. I just finished the 2-4 exercises and it was quite a challenge for some reason. The problem was to write a function that takes two strings and remembers the characters in one string from the other. I thought it&#8217;s worth posting my solution. I&#8217;m not sure how &#8216;good&#8217; my style is, but I&#8217;m following my style from K&amp;R so it can&#8217;t be very bad&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> squeeze<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> s1<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Hello, world!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> s2<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Hlo&quot;</span><span style="color: #339933;">;</span>
    squeeze<span style="color: #009900;">&#40;</span>s1<span style="color: #339933;">,</span> s2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> s1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* squeeze: deletes all characters in s2 from s1 */</span>
<span style="color: #993333;">void</span> squeeze<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> s1<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">char</span> s2<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> k<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> s1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> found <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>k <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> s2<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>s1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> s2<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                found <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>found<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            s1<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> s1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    s1<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The stuff in the main is just some testing that I did. From what I can tell, it seems to work as expected. Yay C!</p>
]]></content:encoded>
			<wfw:commentRss>http://geoffsquared.com/2009/06/c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
