<?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; Algorithms</title>
	<atom:link href="http://www.dallinjones.com/category/programming/algorithms/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>How to convert from pixels to millimeters</title>
		<link>http://www.dallinjones.com/2008/07/how-to-convert-from-pixels-to-millimeters/</link>
		<comments>http://www.dallinjones.com/2008/07/how-to-convert-from-pixels-to-millimeters/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 13:47:46 +0000</pubDate>
		<dc:creator>SlipStream</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Programming]]></category>

		<guid isPermaLink="false">http://www.dallinjones.com/2008/07/02/how-to-convert-from-pixels-to-millimeters/</guid>
		<description><![CDATA[ I am working with PHP and FPDF to generate a PDF invoice. The designers have created a couple of very helpful documents, there are three total. The first is a mockup of the invoice. The second shows fonts, font sizes, and font colors. The last document show the positioning of all elements on the [...]]]></description>
			<content:encoded><![CDATA[<p> I am working with PHP and FPDF to generate a PDF invoice. The designers have created a couple of very helpful documents, there are three total. The first is a mockup of the invoice. The second shows fonts, font sizes, and font colors. The last document show the positioning of all elements on the invoice. My only problem, is that the document was made with pixels at a resolution of 300 DPI rather than in millimeters. Anyone that is familiar with FPDF will know that PDF&#8217;s created with FPDF can not be generated with pixels in mind. PDF documents in FPDF can only use point (pt), millimeteres (mm), centimeters (cm), or inches (in).<span id="more-65"></span>So I needed to come up with a way to convert things to what I needed them to be. Here is the solution I came up with. First, we need to discuss the conversion factors. My document had a DPI of 300, DPI stands for Dots Per Inch. This means that in every in there are 300 pixels. But we aren&#8217;t using inches for measurements on the document, we are using millimeters. Well, there are 25.4 millimeters in an inch. So, how do we go all the way from pixels to millimeters. Simple.</p>
<p>In chemistry, we studied something called dimensional analysis. Dimensional analysis is a method for converting from one unit to another. So first off we multiply the number of pixels by 1 over our DPI (in this case 300 DPI) then we multiply that by 25.4 by one inch (number of millimeters in an inch) Once everything cancels out we are left with a fairly nice, simple and easy to use formula.<br />
<code>mm = (pixels * 25.4) / dpi</code><br />
In order to convert back from millimeters to pixels we simply reverse the formula using simple algebra.<br />
<code>pixels = (mm * dpi) / 25.4</code><br />
There you have it. A very simple way to convert from pixels to millimeters. And then from millimeters back to pixels.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dallinjones.com/2008/07/how-to-convert-from-pixels-to-millimeters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rounding to the nearest half dollor (or quarter dollar)</title>
		<link>http://www.dallinjones.com/2008/06/rounding-to-the-nearest-half-dollor-or-quarter-dollar/</link>
		<comments>http://www.dallinjones.com/2008/06/rounding-to-the-nearest-half-dollor-or-quarter-dollar/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 14:35:09 +0000</pubDate>
		<dc:creator>SlipStream</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Programming]]></category>

		<guid isPermaLink="false">http://www.dallinjones.com/2008/06/18/rounding-to-the-nearest-half-dollor-or-quarter-dollar/</guid>
		<description><![CDATA[One of my recent projects required that I round the price I was calculating to the nearest half dollar. This started out at a pain. Rounding to the floor, or to the ceiling, or normal rounding is quite easy. But I have never had to round to the nearest half dollar. (or quarter dollar) After [...]]]></description>
			<content:encoded><![CDATA[<p>One of my recent projects required that I round the price I was calculating to the nearest half dollar. This started out at a pain. Rounding to the floor, or to the ceiling, or normal rounding is quite easy. But I have never had to round to the nearest half dollar. (or quarter dollar) After a little bit of time thinking about it, I came up with a solution.<span id="more-63"></span>I first thought about the algorithm needed to round to the floor or to the ceiling. This was easy, since the project is a PHP project, I simply had to use the rounding functions. Rounding to the nearest half dollar was harder because we had to come up with a way to round evenly. So here is the algorithm I used:</p>
<p><code>$rounded = round(($initial_value / .5), 0) * .5</code></p>
<p>There you have it. A very simple (and quick way) of rounding to the nearest half dollar. To be able to round to the nearest quarter dollar, tenth of a dollar or anything else you feel like rounding to, simply change the .5 to .25 (for quarter dollar) or .1 (for tenth of a dollar) depending on what is needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dallinjones.com/2008/06/rounding-to-the-nearest-half-dollor-or-quarter-dollar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
