<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Connecting the dots</title>
	<atom:link href="http://benjaminbaka.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjaminbaka.wordpress.com</link>
	<description>The sky is not the limit</description>
	<pubDate>Mon, 24 Mar 2008 09:25:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby selection sort.</title>
		<link>http://benjaminbaka.wordpress.com/2008/03/24/ruby-selection-sort/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/03/24/ruby-selection-sort/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 09:25:10 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[ruby selection sort]]></category>

		<category><![CDATA[selection sort]]></category>

		<category><![CDATA[selection sort in ruby]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=33</guid>
		<description><![CDATA[The general idea behind selection sort is, finding the least element in an array and exchanging it with the item in the first position of that given array.  Two loops are used. The outer one  shows where we are in the array and the second finds the smallest element between the current array item and [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The general idea behind selection sort is, finding the least element in an array and exchanging it with the item in the first position of that given array.  Two loops are used. The outer one  shows where we are in the array and the second finds the smallest element between the current array item and the last item. Any time the smallest element is found its exchanged with the outer loops current variable. By the end every execution of an inner loop the items to the left are sorted in order leaving the right side unsorted.</p>
<p>1  a = [ 5,2,1,7,4,3]</p>
<p>2  (a.size-1).times do |i| #produces the indexes of the array elements<br />
3    min = i  #the current item is concidered or assumed to be the smallest<br />
4      (i+1).upto(a.size-1) do |j|  #scan from a[j+1 ... size-1]<br />
5        if a[j] &lt; a[min]<br />
6          min = j        #update new minimum value<br />
7        end<br />
8      end<br />
9    temp = a[i]       #the code below is to swap the<br />
10    a[i] = a[min]     #elements.<br />
11    a[min] = temp<br />
12  end</p>
<p>13  puts a</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=33&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/03/24/ruby-selection-sort/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>challenge #6 display a chess board</title>
		<link>http://benjaminbaka.wordpress.com/2008/03/20/challenge-6-display-a-chess-board/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/03/20/challenge-6-display-a-chess-board/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 17:59:52 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[challenges]]></category>

		<category><![CDATA[chess program in ruby]]></category>

		<category><![CDATA[chess ruby]]></category>

		<category><![CDATA[ruby chess]]></category>

		<category><![CDATA[ruby chess board display]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=32</guid>
		<description><![CDATA[I do not know but i know dear reader that you have seen a programming problem like this one ;
***        ***
***
***        ***
The program displays something in the form of a chess board where the * are the black boxes and the spaces  are the white boxes.
To solve this using Ruby, we need [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I do not know but i know dear reader that you have seen a programming problem like this one ;</p>
<p>***        ***</p>
<p>***</p>
<p>***        ***</p>
<p>The program displays something in the form of a chess board where the * are the black boxes and the spaces  are the white boxes.</p>
<p>To solve this using Ruby, we need two loops. One for the outer loop and other loop for the inner loop. Horizontally, number the boxes as number in increasing order. We achieve that by adding the variables of the two loops. If the result of the addition divided  by 2 gives us 0 then the loop we print spaces to represent a white space else we print *.</p>
<p>In the code, the second loop is used duplicate the print out. Remove it and see how it work.</p>
<p>1  outer = ARGV[0].to_i<br />
2  inner = ARGV[1].to_i</p>
<p>3  outer.times do |j|<br />
4    3.times do<br />
5       1.upto(inner) do |i|<br />
6          if (j+i)%2 == 0<br />
7               print &#8220;    &#8220;<br />
8          else<br />
9               print &#8220;****&#8221;<br />
10          end<br />
11       end<br />
12      puts<br />
13    end<br />
14  end</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=32&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/03/20/challenge-6-display-a-chess-board/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>My First C program</title>
		<link>http://benjaminbaka.wordpress.com/2008/03/13/my-first-c-program/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/03/13/my-first-c-program/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 10:06:32 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[C]]></category>

		<category><![CDATA[compiling C program]]></category>

		<category><![CDATA[hello world C]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=31</guid>
		<description><![CDATA[I remember almost five years back, i met a group of programmer friends who dared not to write any C code because they considered it some sort of black art reserved for only brainy and guru programmers. But through a series of enlightenment now i have put all those thoughts behind me. I have started [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I remember almost five years back, i met a group of programmer friends who dared not to write any C code because they considered it some sort of black art reserved for only brainy and guru programmers. But through a series of enlightenment now i have put all those thoughts behind me. I have started programming in C and this is my first program. I am not saying the road is going to be smooth, that i know, but i am just saying, i do not see myself relenting in my efforts to program the best of C and Ruby that i can.</p>
<p>1  /* This is an hello world program */<br />
2  #include &lt;stdio.h&gt;</p>
<p>3  int main(void)<br />
4    {<br />
5      printf(&#8221;Hello World\n&#8221;);<br />
6      return 0;<br />
7    }<br />
To compile the code, cc -c</p>
<p>To make it executable, cc -o hello hello.c</p>
<p>To run it ,  ./hello</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=31&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/03/13/my-first-c-program/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby String.chomp Remix</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/25/ruby-stringchomp-remix/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/25/ruby-stringchomp-remix/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 16:08:22 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[ruby chomp]]></category>

		<category><![CDATA[ruby squeeze]]></category>

		<category><![CDATA[ruby strip]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=30</guid>
		<description><![CDATA[While i was sitting down playing with regular expressions, i decided to write a small application String  chomp method my way. If perhaps you wanted to remove all whitespaces within and around a string you would have to do it using strip and squeeze methods but the same effect can be achieved by using regular [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>While i was sitting down playing with regular expressions, i decided to write a small application String  chomp method my way. If perhaps you wanted to remove all whitespaces within and around a string you would have to do it using strip and squeeze methods but the same effect can be achieved by using regular expressions. It even works with n or t etc.</p>
<p>First, we scan for words with w+ and join them with a single space.</p>
<p>1  #Building my own chomp</p>
<p>2  class String<br />
3    def bchomp<br />
4      self.scan(/w+/).join(&#8217; &#8216;)<br />
5    end<br />
6  end</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=30&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/25/ruby-stringchomp-remix/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby color console output</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/22/ruby-color-console-output/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/22/ruby-color-console-output/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 01:41:39 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[filla]]></category>

		<category><![CDATA[console color]]></category>

		<category><![CDATA[console tricks]]></category>

		<category><![CDATA[ruby color output console]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/2008/02/22/ruby-color-console-output/</guid>
		<description><![CDATA[There seems to be a growing demand on ways to do console output with color. That is fine by me. I just discoverd about ncurses and from what i see it looks promising. I am going out to try it.
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There seems to be a growing demand on ways to do console output with color. That is fine by me. I just discoverd about ncurses and from what i see it looks promising. I am going out to try it.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=29&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/22/ruby-color-console-output/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>Accra.rb</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/22/accrarb/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/22/accrarb/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 01:31:44 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[filla]]></category>

		<category><![CDATA[Accra Ruby]]></category>

		<category><![CDATA[Accra.rb]]></category>

		<category><![CDATA[programming in Accra]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=28</guid>
		<description><![CDATA[Ruby, and nice,modern and interesting language to program in has caught the attention of some programmers in Ghana. Thus the formation of Accra.rb(Accra is the capital city of Ghana.) We intended to form this programming group to share knowledge about Ruby and also spread the good news about ruby. Currently we are just a handful [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ruby, and nice,modern and interesting language to program in has caught the attention of some programmers in Ghana. Thus the formation of Accra.rb(Accra is the capital city of Ghana.) We intended to form this programming group to share knowledge about Ruby and also spread the good news about ruby. Currently we are just a handful of members and we just had our first meeting on the 16th of Feb,2008. I hope and know this group will have a long way to gooooooooo.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=28&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/22/accrarb/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>challenge #5 Ruby Bubble Sort</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/22/challenge-5-ruby-bubble-sort/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/22/challenge-5-ruby-bubble-sort/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 01:27:01 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[challenges]]></category>

		<category><![CDATA[bubble sort]]></category>

		<category><![CDATA[challenge 5]]></category>

		<category><![CDATA[programming challenges]]></category>

		<category><![CDATA[ruby bubble sort]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=27</guid>
		<description><![CDATA[Today, i sat up to write a bubble sort in ruby. This is how it goes. First things first. We device a way to find the largest number by comparing the each element with the next. Then we swap them if they are not in ascending order. After the first iteration the biggest number will [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today, i sat up to write a bubble sort in ruby. This is how it goes. First things first. We device a way to find the largest number by comparing the each element with the next. Then we swap them if they are not in ascending order. After the first iteration the biggest number will be the last in the array. Bring another loop (outer) will help us sort it but the problem is that, we will still go through the array even if the array is already sorted. Therefore, before the beginning of the program we assume there is swaping to be done. Swap therefore is true. If there is a swap then swap, then there is probably some more things unsorted in the array. But if it happens that there were no swap the (break).</p>
<p>1  a = [1,1,1,1,1]</p>
<p>2  (a.size).times do<br />
3    swap = true<br />
4      (a.size-1).times do |i|<br />
5        if a[i] &gt; a[i+1]<br />
6          temp = a[i]<br />
7          a[i] = a[i+1]<br />
8          a[i+1] = temp<br />
9          swap = true<br />
10        end<br />
11       break if swap == false<br />
12    end<br />
13  end</p>
<p>14  puts a</p>
<p>As its said, the best way to understand this is to sometimes follow it with paper and pen. It really does help. I hope to hear comments from you so as to shape my writing styles.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=27&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/22/challenge-5-ruby-bubble-sort/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>Recursive Linear Search #2</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/22/recursive-linear-search-2/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/22/recursive-linear-search-2/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 00:46:46 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[recursion]]></category>

		<category><![CDATA[recursive linear search]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[ruby recursive linear search]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=26</guid>
		<description><![CDATA[So, the code for the first search was OK, but will curtainly not help an non ruby programmer. So i have decided to modify it a bit. This time, instead of using the begin&#8230;..rescue&#8230;&#8230;.end statement we maintain a state of our position with respect to the last position.
1  a = [1,2,3,4,5,4]
2  def find(array,position,key)
3    if position [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So, the code for the first search was OK, but will curtainly not help an non ruby programmer. So i have decided to modify it a bit. This time, instead of using the begin&#8230;..rescue&#8230;&#8230;.end statement we maintain a state of our position with respect to the last position.</p>
<p>1  a = [1,2,3,4,5,4]</p>
<p>2  def find(array,position,key)<br />
3    if position &gt;array.size<br />
4      puts  &#8220;#{key} not found&#8221;<br />
5    elsif key == array[position]<br />
6     puts &#8220;Found #{key}&#8221;<br />
7    else<br />
8      find(array,position+1,key)<br />
9    end<br />
10  end</p>
<p>11  find(a,0,4)</p>
<p>Hope this is better. I am thinking of writing on a ruby bubble sort.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=26&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/22/recursive-linear-search-2/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t be hard on yourself</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/16/dont-be-hard-on-yourself/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/16/dont-be-hard-on-yourself/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 08:09:37 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[beginning ruby]]></category>

		<category><![CDATA[programming difficulties]]></category>

		<category><![CDATA[ruby programming]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/?p=25</guid>
		<description><![CDATA[    Beginning programming is fun to say the least but sometimes, it can become very frustrating. One may come accross a programming challenge that he/she may like to solve but just can&#8217;t solve it. Its not because you are dumb, nor is it that you can not think well or that programming was not meant [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>    Beginning programming is fun to say the least but sometimes, it can become very frustrating. One may come accross a programming challenge that he/she may like to solve but just can&#8217;t solve it. Its not because you are dumb, nor is it that you can not think well or that programming was not meant for you. Its just because like a child you are in your formative years of programming and as such there will be times you will fall. I normally go through this phase from time to time and i even sometimes feel depressed but i have come to realise that it is not that i do not have the brains to solve the question at hand but just that i do not know enough to dice and slice the programming problem. The remedy, i do more research, get to know the problem well enough in order to define it well and sometimes i just leave the problem alone. After sometime i come back to it with a new mindset.</p>
<p>It works for me i do not know if it will for you.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=25&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/16/dont-be-hard-on-yourself/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
		<item>
		<title>challenge #4, listing files recursively with Ruby</title>
		<link>http://benjaminbaka.wordpress.com/2008/02/16/challenge-4-listing-files-recursively-with-ruby/</link>
		<comments>http://benjaminbaka.wordpress.com/2008/02/16/challenge-4-listing-files-recursively-with-ruby/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 02:51:43 +0000</pubDate>
		<dc:creator>bbaka</dc:creator>
		
		<category><![CDATA[challenges]]></category>

		<category><![CDATA[benjamin baka]]></category>

		<category><![CDATA[listing files recursively in ruby]]></category>

		<category><![CDATA[listing files recursively ruby]]></category>

		<category><![CDATA[recursion ruby]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://benjaminbaka.wordpress.com/2008/02/16/challenge-4-listing-files-recursively-with-ruby/</guid>
		<description><![CDATA[After almost a couple of months i have been now able to write a program to lists the files in a directory recursively. I was disappointed at first that i could write a program to do that but now i can. I have also picked up a few useful things on the way to solving [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After almost a couple of months i have been now able to write a program to lists the files in a directory recursively. I was disappointed at first that i could write a program to do that but now i can. I have also picked up a few useful things on the way to solving the challenge that i would not have understood if i left the challenge or problem. The program is just about ten lines of code in ruby.<br />
1  def list(file_name)<br />
2    Dir.new(&#8221;#{file_name}&#8221;).each do |file|<br />
3       next if file.match(/^\.+/)<br />
4       path = &#8220;#{file_name}/#{file}&#8221;<br />
5       if  FileTest.directory?(&#8221;#{path}&#8221;)<br />
6         list(&#8221;#{path}&#8221;)<br />
7       else<br />
8          puts path<br />
9        end<br />
10     end<br />
11  end</p>
<p>12  list(&#8221;/home/foo&#8221;)</p>
<p>On line #3, if the directory contains the .. and . directorys move to the next item in loop</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benjaminbaka.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benjaminbaka.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benjaminbaka.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benjaminbaka.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benjaminbaka.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benjaminbaka.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benjaminbaka.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benjaminbaka.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benjaminbaka.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benjaminbaka.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benjaminbaka.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benjaminbaka.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benjaminbaka.wordpress.com&blog=2258922&post=24&subd=benjaminbaka&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benjaminbaka.wordpress.com/2008/02/16/challenge-4-listing-files-recursively-with-ruby/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/bbaka-128.jpg" medium="image">
			<media:title type="html">bbaka</media:title>
		</media:content>
	</item>
	</channel>
</rss>