<?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>DallinJones.com &#187; Computational Theory</title>
	<atom:link href="http://www.dallinjones.com/category/programming/computational-theory/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dallinjones.com</link>
	<description>One more geek in the world.</description>
	<lastBuildDate>Fri, 09 Apr 2010 17:02: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>EVEN-EVEN Simulation</title>
		<link>http://www.dallinjones.com/2008/01/even-even-simulation/</link>
		<comments>http://www.dallinjones.com/2008/01/even-even-simulation/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 05:27:32 +0000</pubDate>
		<dc:creator>SlipStream</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Computational Theory]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.dallinjones.com/2008/01/22/even-even-simulation/</guid>
		<description><![CDATA[Simulate the EVEN-EVEN automaton found in the book in code. Don’t just “solve the problem”—implement the machine (i.e., there should be evidence of the states and transitions in your code). Input at least the strings below. The output should echo the string in quotes and indicate whether it is in the language EVEN-EVEN or not.
a, [...]]]></description>
			<content:encoded><![CDATA[<p>Simulate the EVEN-EVEN automaton found in the book in code. Don’t just “solve the problem”—implement the machine (i.e., there should be evidence of the states and transitions in your code). Input at least the strings below. The output should echo the string in quotes and indicate whether it is in the language EVEN-EVEN or not.</p>
<p>a, abab, aabbab, baab, &lt;the empty string&gt;<br />
<span id="more-42"></span><br />
My solution was written in JAVA and consists of approximately 80 lines of code. Please feel free to comment on my code. Are there things that I could have done better? Are there things that I could explain further. Remember this is my code, and that I have displayed it here for others to learn from. Don&#8217;t simply copy it and call it your own. I own copyright, and because I show the code does not mean that I have given up my rights to this code.</p>
<p><code></code></p>
<pre><font color="#804040"> 1</font>  <font color="#ee0000">/**</font>
<font color="#804040"> 2</font>  <font color="#ee0000"> *</font><font color="#ff1493"> EVEN-EVEN Simulation</font>
<font color="#804040"> 3</font>  <font color="#ee0000"> *</font><font color="#ff1493"> Written By: Dallin Jones</font>
<font color="#804040"> 4</font>  <font color="#ee0000"> *</font><font color="#ff1493"> CS3240 - Computational Theory</font>
<font color="#804040"> 5</font>  <font color="#ee0000"> *</font><font color="#ff1493"> For use by him and his professor (and person he dubs as the grader)</font>
<font color="#804040"> 6</font>  <font color="#ee0000"> *</font><font color="#ff1493"> It is not to be used by any one else.</font><font color="#ee0000"> </font>
<font color="#804040"> 7</font>  <font color="#ee0000"> */</font>
<font color="#804040"> 8</font>
<font color="#804040"> 9</font>  <font color="#cd00cd">package</font> com.dallinjones.cs3240.p1;
<font color="#804040">10</font>
<font color="#804040">11</font>  <font color="#cd00cd">import</font> java.io.*;
<font color="#804040">12</font>
<font color="#804040">13</font>  <font color="#0000ff"><strong>public</strong></font> <font color="#0000ff"><strong>class</strong></font> AppLauncher {
<font color="#804040">14</font>    <font color="#ee0000">/**</font>
<font color="#804040">15</font>  <font color="#ee0000">   *</font><font color="#ff1493"> The transtion table works as follows:</font>
<font color="#804040">16</font>  <font color="#ee0000">   *</font><font color="#ff1493">   Each row in the table represents a state from 0-3</font>
<font color="#804040">17</font>  <font color="#ee0000">   *</font><font color="#ff1493">   State 0 Even-Even (Accepting state defined by [0][0]</font>
<font color="#804040">18</font>  <font color="#ee0000">   *</font><font color="#ff1493">   State 1 Even-Odd (Not-Accepting state defined by [1][0]</font>
<font color="#804040">19</font>  <font color="#ee0000">   *</font><font color="#ff1493">   State 2 Odd-Even (Not Accepting state defined by [2][0]</font>
<font color="#804040">20</font>  <font color="#ee0000">   *</font><font color="#ff1493">   State 3 Odd-Odd (Not Accepting state defined by [3][0]</font>
<font color="#804040">21</font>  <font color="#ee0000">   *</font><font color="#ff1493">   </font>
<font color="#804040">22</font>  <font color="#ee0000">   *</font><font color="#ff1493">   Columns 1 and 2 show which state to move to for input in that column</font>
<font color="#804040">23</font>  <font color="#ee0000">   *</font><font color="#ff1493">   The input given is currentState - 'a' + 1 (this shoudl give us 1 or 2</font>
<font color="#804040">24</font>  <font color="#ee0000">   *</font><font color="#ff1493">   for a or b respectivley)  </font>
<font color="#804040">25</font>  <font color="#ff1493">   </font><font color="#ee0000">*/</font>
<font color="#804040">26</font>    <font color="#0000ff"><strong>private</strong></font> <font color="#0000ff"><strong>static</strong></font> <font color="#0000ff"><strong>int</strong></font>[][] transitionTable = {
<font color="#804040">27</font>      {<font color="#00cd00">1</font>, <font color="#00cd00">1</font>, <font color="#00cd00">2</font>},
<font color="#804040">28</font>      {<font color="#00cd00">0</font>, <font color="#00cd00">0</font>, <font color="#00cd00">3</font>},
<font color="#804040">29</font>      {<font color="#00cd00">0</font>, <font color="#00cd00">3</font>, <font color="#00cd00">0</font>},
<font color="#804040">30</font>      {<font color="#00cd00">0</font>, <font color="#00cd00">2</font>, <font color="#00cd00">1</font>}
<font color="#804040">31</font>    };
<font color="#804040">32</font>
<font color="#804040">33</font>    <font color="#0000ff"><strong>public</strong></font> <font color="#0000ff"><strong>static</strong></font> <font color="#0000ff"><strong>int</strong></font> simulateEvenEven(String testString) {
<font color="#804040">34</font>      <font color="#0000ff"><strong>int</strong></font> currentState = <font color="#00cd00">0</font>;
<font color="#804040">35</font>      testString = testString.toLowerCase();
<font color="#804040">36</font>      <font color="#0000ff"><strong>char</strong></font>[] brokenUp = testString.toCharArray();
<font color="#804040">37</font>
<font color="#804040">38</font>      <font color="#0000ff"><strong>for</strong></font> (<font color="#0000ff"><strong>int</strong></font> i = <font color="#00cd00">0</font>; i &lt; brokenUp.length; i++) {
<font color="#804040">39</font>        <font color="#0000ff"><strong>if</strong></font> ( (brokenUp[i] == <font color="#00cd00">'a'</font>) || (brokenUp[i] == <font color="#00cd00">'b'</font>) ) {
<font color="#804040">40</font>          currentState = transitionTable[currentState][brokenUp[i] - <font color="#00cd00">'a'</font> + <font color="#00cd00">1</font>];
<font color="#804040">41</font>        } <font color="#0000ff"><strong>else</strong></font> {
<font color="#804040">42</font>          <font color="#0000ff"><strong>return</strong></font> <font color="#00cd00">0</font>;
<font color="#804040">43</font>        }
<font color="#804040">44</font>      }
<font color="#804040">45</font>      <font color="#0000ff"><strong>return</strong></font> transitionTable[currentState][<font color="#00cd00">0</font>];
<font color="#804040">46</font>    }
<font color="#804040">47</font>
<font color="#804040">48</font>    <font color="#ee0000">/**</font>
<font color="#804040">49</font>  <font color="#ee0000">   </font><font color="#ee0000">* </font><font color="#ff1493">@param</font><font color="#008b8b"> args</font>
<font color="#804040">50</font>  <font color="#ee0000">   */</font>
<font color="#804040">51</font>    <font color="#0000ff"><strong>public</strong></font> <font color="#0000ff"><strong>static</strong></font> <font color="#0000ff"><strong>void</strong></font> main(String[] args) {
<font color="#804040">52</font>      <font color="#0000ff"><strong>boolean</strong></font> exit = <font color="#00cd00">false</font>;
<font color="#804040">53</font>      BufferedReader input = <font color="#0000ff"><strong>new</strong></font> BufferedReader(<font color="#0000ff"><strong>new</strong></font> InputStreamReader(System.in));
<font color="#804040">54</font>      String inputLine = <font color="#00cd00">null</font>;
<font color="#804040">55</font>
<font color="#804040">56</font>      System.out.println(<font color="#00cd00">"EVEN-EVEN Simulation</font><font color="#ff1493">\n</font><font color="#00cd00">Dallin Jones</font><font color="#ff1493">\n</font><font color="#00cd00">CS3240</font><font color="#ff1493">\n</font><font color="#00cd00">"</font>);
<font color="#804040">57</font>      <font color="#0000ff"><strong>while</strong></font> (!exit) {
<font color="#804040">58</font>        <font color="#0000ff"><strong>try</strong></font> {
<font color="#804040">59</font>          System.out.print(<font color="#00cd00">"Type 'exit' to quit or enter a string &gt;"</font>);
<font color="#804040">60</font>          inputLine = input.readLine();
<font color="#804040">61</font>          <font color="#0000ff"><strong>if</strong></font> (inputLine.equals(<font color="#00cd00">"exit"</font>)) {
<font color="#804040">62</font>            exit = <font color="#00cd00">true</font>;
<font color="#804040">63</font>          } <font color="#0000ff"><strong>else</strong></font> {
<font color="#804040">64</font>          <font color="#0000ff"><strong>int</strong></font> returnValue = simulateEvenEven(inputLine);
<font color="#804040">65</font>            System.out.print(<font color="#00cd00">"'"</font> + inputLine + <font color="#00cd00">"' "</font>);
<font color="#804040">66</font>            <font color="#0000ff"><strong>if</strong></font> (returnValue != <font color="#00cd00">0</font>) {
<font color="#804040">67</font>              System.out.println(<font color="#00cd00">"- Valid string"</font>);
<font color="#804040">68</font>            } <font color="#0000ff"><strong>else</strong></font> {
<font color="#804040">69</font>              System.out.println(<font color="#00cd00">"- Invalid string"</font>);
<font color="#804040">70</font>            }
<font color="#804040">71</font>          }
<font color="#804040">72</font>        } <font color="#0000ff"><strong>catch</strong></font> (IOException ioe) {
<font color="#804040">73</font>          System.out.println(<font color="#00cd00">"IOExpection caught while trying to read an input string!</font><font color="#ff1493">\n</font><font color="#00cd00">"</font>);
<font color="#804040">74</font>          System.exit(<font color="#00cd00">1</font>);
<font color="#804040">75</font>        }
<font color="#804040">76</font>      }
<font color="#804040">77</font>      System.out.println(<font color="#00cd00">"Exiting Program..."</font>);
<font color="#804040">78</font>    }
<font color="#804040">79</font>  }</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dallinjones.com/2008/01/even-even-simulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

