<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in Learn to Program | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/6/posts</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <item>
      <title>A Few Things to Try: Table of Contents + posted by Matt Rutledge @ Fri, 25 Apr 2008 18:28:08 -0000</title>
      <description>&lt;p&gt;Hi!&lt;br /&gt;Im new to programming (and Ruby of course) and am working through Chris Pine&amp;#8217;s tutorial as a starting point.  At the end of chapter 7 there is a &amp;#8216;A Few Things to Try&amp;#8217; project where you rewrite the Table of Contents program to utilize arrays.  Id like to house the information (ie Chapter Title and Page) in two seperate arrays and then cycle through code for each string in each array at the same time (hopefully this makes sense..).&lt;/p&gt;


	&lt;p&gt;Here is the code that Ive come up with (but of course doesnt work):&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
page_width = 50

contents = ['Chapter 1: Getting Started','Chapter 2: Numbers','Chapter 3: Letters']
pages = ['1','9','13']

contents.each do |content| and pages.each do |page|
puts(content.ljust(page_width/2)) + (page.rjust(page_width/2))
end
&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;

	&lt;p&gt;Im confident that Im going about this the wrong way&amp;#8230;any  hints?&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;THANKS&lt;/span&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 25 Apr 2008 18:28:08 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:386:2640</guid>
      <author>Matt Rutledge</author>
      <link>http://forums.pragprog.com/forums/6/topics/386</link>
    </item>
    <item>
      <title>where is the answer of quizzes posted by widemine @ Wed, 30 Jan 2008 01:30:18 -0000</title>
      <description>&lt;p&gt;If anyone&amp;#8217;s interested, I put up an answer key to the exercises right here: &lt;a href="http://learntoprogramanswers.blogspot.com/"&gt;http://learntoprogramanswers.blogspot.com/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 30 Jan 2008 01:30:18 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:209:2241</guid>
      <author>widemine</author>
      <link>http://forums.pragprog.com/forums/6/topics/209</link>
    </item>
    <item>
      <title>where is the answer of quizzes posted by Joe Pizzanley @ Thu, 24 Jan 2008 18:18:18 -0000</title>
      <description>&lt;p&gt;if you go to the Ruby forum (&lt;a href="http://www.ruby-forum.com/forum/4"&gt;http://www.ruby-forum.com/forum/4&lt;/a&gt;)and search for &amp;#8220;Pine&amp;#8221; you will get several threads that discuss the quizzes. They helped me quite a bit. If after reading them you still need help, post to the list.&lt;/p&gt;</description>
      <pubDate>Thu, 24 Jan 2008 18:18:18 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:209:2219</guid>
      <author>Joe Pizzanley</author>
      <link>http://forums.pragprog.com/forums/6/topics/209</link>
    </item>
    <item>
      <title>Sort using recursion (10.2 Rite of Passage: Sorting) posted by Tyler Bird @ Fri, 11 Jan 2008 22:17:11 -0000</title>
      <description>&lt;p&gt;I was on the exact same issue and I&amp;#8217;m so pleased with myself that I figured it out I thought I&amp;#8217;d share.&lt;/p&gt;


	&lt;p&gt;Keep in mind, that if you want to solve it yourself this gives you the answer and you should disregard the reply&amp;#8230;&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;NOTE&lt;/span&gt;: Remember to uncomment the method you&amp;#8217;d prefer to run in the &lt;code&gt;sort&lt;/code&gt; method.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
def sort an_array
  #recursive_sort an_array, [], 0
  #iterative_sort an_array, []
end

def iterative_sort unsorted_array, sorted_array

    i = 0
    loop do

      break if unsorted_array.length == 0

      score     = 0                      
      length    = unsorted_array.length  
      this_word = unsorted_array[i]      

      # count each time this_word is the smallest &amp;#38; count itself once
      unsorted_array.each do |array_word|
        if this_word &amp;lt;= array_word
          score += 1
        end
      end

      # this_word is the smallest when score == length      
      if score == length
        sorted_array.push(this_word)
        unsorted_array.delete(this_word)
        i = 0  # start at the beginning of the array next time.
      else
        i += 1 # increment the array to check the next word.
      end

    end

  sorted_array
end

def recursive_sort unsorted_array, sorted_array, i

  return if unsorted_array.length == 0

    score     = 0                      
    length    = unsorted_array.length  
    this_word = unsorted_array[i]      

    # count each time this_word is the smallest &amp;#38; count itself once
    unsorted_array.each do |array_word|
      if this_word &amp;lt;= array_word
        score += 1
      end
    end

    # this_word is the smallest when score == length      
    if score == length
      sorted_array.push(this_word)
      unsorted_array.delete(this_word)
      i = 0
    else
      i += 1 # increment the array to check the next word.
    end

  recursive_sort unsorted_array, sorted_array, i

  sorted_array
end

messy_array = ['alpha', 'echo', 'delta', 'beta', 'charlie']

puts sort(messy_array)
&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;</description>
      <pubDate>Fri, 11 Jan 2008 22:17:11 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:201:2156</guid>
      <author>Tyler Bird</author>
      <link>http://forums.pragprog.com/forums/6/topics/201</link>
    </item>
    <item>
      <title>where is the answer of quizzes posted by amir abbas abdolali @ Fri, 11 Jan 2008 10:43:53 -0000</title>
      <description>&lt;p&gt;Hi everybody&lt;/p&gt;


	&lt;p&gt;At the end of each chapter of &amp;#8220;Learn to Program&amp;#8221; there is some quizzes&lt;br /&gt;but the answer of that quizzes are not in the book&lt;br /&gt;how we can check that we do the quizzes correctly ?&lt;/p&gt;


	&lt;p&gt;thanks&lt;/p&gt;</description>
      <pubDate>Fri, 11 Jan 2008 10:43:53 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:209:2151</guid>
      <author>amir abbas abdolali</author>
      <link>http://forums.pragprog.com/forums/6/topics/209</link>
    </item>
    <item>
      <title>Sort using recursion (10.2 Rite of Passage: Sorting) posted by Leo Baghdassarian @ Sat, 05 Jan 2008 02:28:20 -0000</title>
      <description>&lt;p&gt;Only using the methods from the first 10 chapters of the book, the solution hasn&amp;#8217;t come to me.   What have you come up with?&lt;/p&gt;</description>
      <pubDate>Sat, 05 Jan 2008 02:28:20 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:6:201:2117</guid>
      <author>Leo Baghdassarian</author>
      <link>http://forums.pragprog.com/forums/6/topics/201</link>
    </item>
  </channel>
</rss>
