<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6816646335787825774</id><updated>2011-11-27T19:07:20.569-05:00</updated><category term='floating point'/><category term='roman'/><category term='UNL'/><category term='interlingua'/><category term='revision control'/><category term='searching'/><category term='source code'/><category term='script'/><category term='sorting'/><category term='conversion'/><category term='parsing'/><category term='decimal'/><category term='binary'/><category term='batch'/><title type='text'>Computer Algorithms</title><subtitle type='html'>Discussions on algorithms and other computer science and computer programming topics.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-1180736237143142520</id><published>2010-06-25T14:13:00.000-04:00</published><updated>2010-06-25T14:13:06.519-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interlingua'/><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><category scheme='http://www.blogger.com/atom/ns#' term='searching'/><category scheme='http://www.blogger.com/atom/ns#' term='UNL'/><title type='text'>Multilingual Search Engine Breaks Language Barriers</title><content type='html'>According to an article on the &lt;a href="http://www.scientificcomputing.com/"&gt;Scientific Computing&lt;/a&gt; website, researchers have developed a multilingual search engine to query a contents repository written in Interlingua using questions formulated in any language. The search engine returns a precise answer in the language in which the question was formulated.&lt;br /&gt;&lt;br /&gt;Read more at:&amp;nbsp; &lt;a href="http://www.scientificcomputing.com/news-IN-Multilingual-Search-Engine-Breaks-Language-Barriers-0322310.aspx"&gt;http://www.scientificcomputing.com/news-IN-Multilingual-Search-Engine-Breaks-Language-Barriers-0322310.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-1180736237143142520?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.scientificcomputing.com/news-IN-Multilingual-Search-Engine-Breaks-Language-Barriers-0322310.aspx' title='Multilingual Search Engine Breaks Language Barriers'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/1180736237143142520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=1180736237143142520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/1180736237143142520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/1180736237143142520'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/06/multilingual-search-engine-breaks.html' title='Multilingual Search Engine Breaks Language Barriers'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-8166634797106426914</id><published>2010-06-04T14:37:00.000-04:00</published><updated>2010-06-04T14:37:41.431-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='batch'/><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><category scheme='http://www.blogger.com/atom/ns#' term='source code'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>Parsing Command Line Argument with Batch Files</title><content type='html'>On the site &lt;a href="http://sites.google.com/site/computersciencesourcecode/"&gt;Computer Science 101 with Erik Oosterwal&lt;/a&gt; a method is described for simulating a WHILE loop in a batch file in order to parse all the parameters passed in to the batch file as command line arguments.&amp;nbsp; Here is a copy of the small amount of sample code highlighted in that article:&lt;br /&gt;&lt;br /&gt;&lt;samp&gt;&lt;/samp&gt;&lt;br /&gt;&lt;pre&gt;::     Process all the arguments from the command line&lt;br /&gt;::&lt;br /&gt;:_PROCESS_ARGUMENTS&lt;br /&gt;    IF (%1)==() GOTO:_WRAP_TOP_DIRECTORY_IN_DOUBLE_QUOTES&lt;br /&gt;    SET _Temp_Var=%1&lt;br /&gt;    IF /I (%_Temp_Var:~0,2%)==(-H) GOTO:_INSTRUCTIONS&lt;br /&gt;    IF /I (%_Temp_Var:~0,2%)==(/H) GOTO:_INSTRUCTIONS&lt;br /&gt;    IF /I (%_Temp_Var:~0,2%)==(-?) GOTO:_INSTRUCTIONS&lt;br /&gt;    IF /I (%_Temp_Var:~0,2%)==(/?) GOTO:_INSTRUCTIONS&lt;br /&gt;    IF /I (%_Temp_Var:~0,2%)==(-A) SET Overwrite_File=NO&lt;br /&gt;    IF /I (%_Temp_Var:~0,3%)==(-I:) SET Include_Directory=%_Temp_Var:~3%&lt;br /&gt;    IF /I NOT (%_Temp_Var:~0,1%)==(-) SET Output_File="%~f1"&lt;br /&gt;    SHIFT&lt;br /&gt;    GOTO:_PROCESS_ARGUMENTS&lt;br /&gt;&lt;br /&gt;:_WRAP_TOP_DIRECTORY_IN_DOUBLE_QUOTES&lt;br /&gt;    IF (%Include_Directory%)==() GOTO:_INSTRUCTIONS&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The original article, &lt;a href="http://sites.google.com/site/computersciencesourcecode/home/batch-files-and-scripting/parsing-command-line-inputs"&gt;Parsing Command Line Parameters&lt;/a&gt;, includes a detailed description of how the loop works, how the parameters are evaluated, and a batch file that uses this code to create an include-file for a whole directory tree.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-8166634797106426914?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://sites.google.com/site/computersciencesourcecode/home/batch-files-and-scripting/parsing-command-line-inputs' title='Parsing Command Line Argument with Batch Files'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/8166634797106426914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=8166634797106426914' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/8166634797106426914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/8166634797106426914'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/06/parsing-command-line-argument-with.html' title='Parsing Command Line Argument with Batch Files'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-6947478186017775809</id><published>2010-05-24T09:34:00.000-04:00</published><updated>2010-05-24T09:34:00.028-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='revision control'/><category scheme='http://www.blogger.com/atom/ns#' term='source code'/><title type='text'>New Requirements by NSF for Data Management</title><content type='html'>The American National Science Foundation (NSF) has recently announced&amp;nbsp;&lt;a href="http://www.nsf.gov/news/news_summ.jsp?cntn_id=116928&amp;amp;org=NSF&amp;amp;from=news"&gt;new requirements for handling and sharing data&lt;/a&gt; from projects funded by the agency.&lt;br /&gt;&lt;br /&gt;"Science is becoming data-intensive and collaborative," noted Ed Seidel, acting assistant director for NSF's Mathematical and Physical Sciences directorate. "Researchers from numerous disciplines need to work together to attack complex problems; openly sharing data will pave the way for researchers to communicate and collaborate more effectively."&lt;br /&gt;&lt;br /&gt;"This is the first step in what will be a more comprehensive approach to data policy," added Cora Marrett, NSF acting deputy director. "It will address the need for data from publicly-funded research to be made public."&lt;br /&gt;&lt;br /&gt;The new requirements, although publicly stated to&amp;nbsp;encourage better sharing of data within the science community,&amp;nbsp;are almost certainly related to the recent &lt;em&gt;Climategate&lt;/em&gt; fiasco.&amp;nbsp; It should be seen as a reminder to us all to follow proper procedures when writing software, especially in the area of source code control.&lt;br /&gt;&lt;br /&gt;For more information on&amp;nbsp;&lt;em&gt;Climategate&lt;/em&gt; see the articles in &lt;a href="http://en.wikipedia.org/wiki/Climatic_Research_Unit_email_controversy"&gt;Wikipedia&lt;/a&gt;, &lt;a href="http://online.wsj.com/article/SB10001424052748704342404574576683216723794.html"&gt;Wallstreet Journal&lt;/a&gt;, the &lt;a href="http://di2.nu/foia/HARRY_READ_ME-0.html"&gt;original files related to the scandal&lt;/a&gt;, and &lt;a href="http://assassinationscience.com/climategate/"&gt;an analysis of the emails&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For more information&amp;nbsp;on the subjects that are more directly computer related&amp;nbsp;see the articles in Wikipedia for &lt;a href="http://en.wikipedia.org/wiki/LIMS"&gt;LIMS&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Data_management"&gt;data management&lt;/a&gt;, and &lt;a href="http://en.wikipedia.org/wiki/Revision_control"&gt;source code control&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-6947478186017775809?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.scientificcomputing.com/news-IN-Scientists-Seeking-NSF-Funding-Will-Soon-Be-Required-to-Submit-Data-Management-Plans-051210.aspx' title='New Requirements by NSF for Data Management'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/6947478186017775809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=6947478186017775809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6947478186017775809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6947478186017775809'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/new-requirements-by-nsf-for-data.html' title='New Requirements by NSF for Data Management'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-6111257235255411062</id><published>2010-05-21T08:43:00.000-04:00</published><updated>2010-05-21T08:43:41.176-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='roman'/><title type='text'>Roman Numeral to Decimal Conversion - Algorithm 2</title><content type='html'>A second method for converting Roman numerals to decimal numbers has been posted on the &lt;a href="http://sites.google.com/site/computersciencesourcecode/"&gt;Computer Science 101&lt;/a&gt; website.&lt;br /&gt;&lt;br /&gt;According to the article on that site, the algorithm boils down to this:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Set the character pointer to point at the right-most character. &lt;/li&gt;&lt;li&gt;Set the value of the summing variable to be the value of the current character. &lt;/li&gt;&lt;li&gt;Move the character pointer to the left one step. &lt;/li&gt;&lt;li&gt;Compare the value of the current character to the previous character: &lt;/li&gt;&lt;li&gt;If the current character's value is the same or larger than the previous character, ADD its value to the sum. &lt;/li&gt;&lt;li&gt;Otherwise, if the current character's value is smaller than the previous character, SUBTRACT its value from the sum. &lt;/li&gt;&lt;li&gt;Repeat steps 3-6 until the left-most character has been evaluated.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;You can get a &lt;a href="http://sites.google.com/site/computersciencesourcecode/home/conversion-algorithms/roman-to-decimal---algorithm-2"&gt;full listing of a function employing this algorithm&lt;/a&gt; written in Visual Basic on the Computer Science 101 website.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-6111257235255411062?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://sites.google.com/site/computersciencesourcecode/home/conversion-algorithms/roman-to-decimal---algorithm-2' title='Roman Numeral to Decimal Conversion - Algorithm 2'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/6111257235255411062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=6111257235255411062' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6111257235255411062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6111257235255411062'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/roman-numeral-to-decimal-conversion_21.html' title='Roman Numeral to Decimal Conversion - Algorithm 2'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-5010505095833257012</id><published>2010-05-13T16:22:00.001-04:00</published><updated>2010-05-13T16:23:58.196-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='roman'/><title type='text'>Decimal Number to Roman Numeral Conversion Version 3</title><content type='html'>Two previous posts showed how to convert a decimal&amp;nbsp;value to a Roman numeral.&amp;nbsp; The &lt;a href="http://computeralgorithms.blogspot.com/2008/02/convert-decimal-values-to-roman.html"&gt;first method&lt;/a&gt; was very clunky and elementary, the &lt;a href="http://computeralgorithms.blogspot.com/2008/02/decimal-value-to-roman-numeral.html"&gt;second method&lt;/a&gt; is&amp;nbsp;considerably&amp;nbsp;more efficient.&lt;br /&gt;&lt;br /&gt;It ocurred to me, after designing and implementing the second algorithm, that if you're willing to sacrifice a bit more memory space for a table, then there's a faster way to convert from decimal values to Roman numeral notation. &amp;nbsp;The following code shows an implementation of the algorithm in VB .NET.&amp;nbsp; I call it the MCXI algorithm due to the values of the four rows in the table. There are some funny things going on between the 0 based indexing used in accessing array data and 1 based indexing used in the MID function used for parsing the input string&amp;nbsp;that&amp;nbsp;you may need to address this if you use a different programming language.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="color: #6aa84f;"&gt;' Algorithm MCXI&lt;br /&gt;        ' Written by: Erik Oosterwal&lt;br /&gt;        ' Written on: 1-21-2008&lt;br /&gt;        '&lt;br /&gt;        ' Routine to convert Decimal values to Roman Numeral notation.  This algorithm uses a table to store&lt;br /&gt;        '   all the standard Roman Numeral notation for each digit in each Base-10 digit position (ones, tens,&lt;br /&gt;        '   hundreds, thousands).  Each Decimal character is then evaluated to find its magnitude and extract&lt;br /&gt;        '   the corresponding Roman Numeral notation for that value and prepend it to the output string.&lt;br /&gt;        '&lt;br /&gt;        ' This routine does not check for proper usage - the input is not checked for valid numeral characters&lt;br /&gt;        '   and it does not check to verify that the values are positive values between 1 and 4000.  To make&lt;br /&gt;        '   function robust, you check put checks in place for these conditions.&lt;br /&gt;&lt;br /&gt;        'Store the Roman codes for each Decimal digit.&lt;/span&gt;&lt;br /&gt;        Dim strRoman(,) As String = {{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, _&lt;br /&gt;                                     {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, _&lt;br /&gt;                                     {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, _&lt;br /&gt;                                     {"", "M", "MM", "MMM", "MMMM", "", "", "", "", ""}}&lt;br /&gt;&lt;br /&gt;        Dim strOutput As String = Nothing               &lt;span style="color: #6aa84f;"&gt;' Initialize the output string to blank.&lt;/span&gt;&lt;br /&gt;        Dim intLoopI As Integer = Nothing               &lt;span style="color: #6aa84f;"&gt;' Counter used for the Loop&lt;/span&gt;&lt;br /&gt;        Dim intStrLength As Integer = Nothing           &lt;span style="color: #6aa84f;"&gt;' The length of the input string.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        intStrLength = Len(Me.txtInput.Text)            &lt;span style="color: #6aa84f;"&gt;' Find out how many digits are in the input number (magnitude).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        For intLoopI = intStrLength To 1 Step -1        &lt;span style="color: #6aa84f;"&gt;' MID function uses 1 based indexing for the string pointer.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            strOutput = strRoman(intStrLength - intLoopI, Val(Mid$(Me.txtInput.Text, intLoopI, 1))) &amp;amp; strOutput&lt;br /&gt;&lt;br /&gt;        Next&lt;br /&gt;&lt;br /&gt;        Me.txtOutput.Text = strOutput&lt;br /&gt;&lt;br /&gt;    End Sub&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you can see, algorithm number three (MCXI Algorithm) executes the loop a maximum of 4 times and uses no division or multiplication. This should speed up the run time a great deal over the previous two listings.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-5010505095833257012?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/5010505095833257012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=5010505095833257012' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/5010505095833257012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/5010505095833257012'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/decimal-number-to-roman-numeral.html' title='Decimal Number to Roman Numeral Conversion Version 3'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-3236098114482922527</id><published>2010-05-11T17:00:00.000-04:00</published><updated>2010-05-11T17:00:47.953-04:00</updated><title type='text'>Fizz Buzz Busted!?</title><content type='html'>On the site &lt;a href="http://sites.google.com/site/computersciencesourcecode/fizzbuzz-revisited"&gt;Computer Science 101&lt;/a&gt;, Erik Oosterwal presents two different solutions to the FizzBuzz problem and demonstrates why it is important for developers on larger software teams to write code that is developer-friendly even when the developer-friendly code is less efficient.&lt;br /&gt;&lt;br /&gt;Here's a preview of one of the two solutions:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;void FizzBuzz2(void)&lt;br /&gt;{&lt;br /&gt;    int i = 0;&lt;br /&gt;    char output[10];&lt;br /&gt;    for(i = 1; i&amp;lt;=100; i++)&lt;br /&gt;    {&lt;br /&gt;        strcpy(output, "");&lt;br /&gt;        if(i%3==0)&lt;br /&gt;        {&lt;br /&gt;            strcpy(output, "Fizz");&lt;br /&gt;        }&lt;br /&gt;        if(i%5==0)&lt;br /&gt;        {&lt;br /&gt;            strncat(output, "Buzz", 4);&lt;br /&gt;        }&lt;br /&gt;        if(strcmp(output, "")==0)&lt;br /&gt;        {&lt;br /&gt;            printf("%d\n", i);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            printf("%s\n", output);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-3236098114482922527?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/3236098114482922527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=3236098114482922527' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/3236098114482922527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/3236098114482922527'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/fizz-buzz-busted.html' title='Fizz Buzz Busted!?'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-7898358393585410911</id><published>2010-05-10T16:27:00.000-04:00</published><updated>2010-05-10T16:27:09.642-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='roman'/><title type='text'>Roman Numeral to Decimal Conversion</title><content type='html'>You can find algorithms for creating Roman Numerals from decimal values &lt;a href="http://computeralgorithms.blogspot.com/2008/02/convert-decimal-values-to-roman.html"&gt;here&lt;/a&gt;&amp;nbsp;and &lt;a href="http://computeralgorithms.blogspot.com/2008/02/decimal-value-to-roman-numeral.html"&gt;here&lt;/a&gt;.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;In this post we'll take a look at the first of two algorithms for accepting a Roman Numeral and converting it back into a decimal value.&lt;br /&gt;&lt;br /&gt;The basic rules for this algorithms are:&lt;br /&gt;&lt;br /&gt;Start at the left-most character in the Roman Numeral string and work your way to the last character one character at a time. Add the value of the current character to the total. If the current character has a larger value than the previous character, then subtract 2x the value of the previous character from the total.&lt;br /&gt;&lt;br /&gt;For instance the Roman Numeral&amp;nbsp;XIX&amp;nbsp;has a decimal value of&amp;nbsp;19.&amp;nbsp; We start at the first character, 'X',&amp;nbsp;and add 10 to the running total; our total is now 10.&amp;nbsp;&amp;nbsp;We evaluate&amp;nbsp;the second character, 'I'&amp;nbsp;and add 1 to&amp;nbsp;our running total,&amp;nbsp;which now becomes 11.&amp;nbsp;&amp;nbsp;We evaluate&amp;nbsp;the third&amp;nbsp;character, 'X',&amp;nbsp;and add 10 to our total;&amp;nbsp;our total is now 21, but...&amp;nbsp; Because the current character has a larger value than the previous character we must subtract 2x the value of the previous character, 1, from the total bringing the new total&amp;nbsp;to 19.&amp;nbsp; There are no more characters so we stop.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Function Roman2Decimal(strInput as string) as integer&lt;br /&gt;&lt;br /&gt;   Dim intValues() as integer                &lt;span style="color: #6aa84f;"&gt;' Reserve space for an array.&lt;/span&gt;&lt;br /&gt;   Dim intLoopI as integer = nothing         &lt;span style="color: #6aa84f;"&gt;' Initialize the loop counter to 0.&lt;/span&gt;&lt;br /&gt;   Dim intTotal as integer = nothing         &lt;span style="color: #6aa84f;"&gt;' Clear the total.&lt;/span&gt;&lt;br /&gt;   Dim intPreviousPointer as integer = 99999 &lt;span style="color: #6aa84f;"&gt;' Set the value of the previous pointer to some MAX value.&lt;/span&gt;&lt;br /&gt;   Dim intCurrentPointer as integer = nothing  &lt;span style="color: #6aa84f;"&gt;' This will hold the value of the current Roman Numeral character.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   intValues(M) = 1000             &lt;span style="color: #6aa84f;"&gt;' This array addressing method&lt;/span&gt;&lt;br /&gt;   intValues(D) = 500              &lt;span style="color: #6aa84f;"&gt;'  assumes that the language you&lt;/span&gt;&lt;br /&gt;   intValues(C) = 100              &lt;span style="color: #6aa84f;"&gt;'  are using allows you to use&lt;/span&gt;&lt;br /&gt;   intValues(L) = 50               &lt;span style="color: #6aa84f;"&gt;'  values other than integer values&lt;/span&gt;&lt;br /&gt;   intValues(X) = 10               &lt;span style="color: #6aa84f;"&gt;'  to access data in an array.&lt;/span&gt;&lt;br /&gt;   intValues(V) = 5&lt;br /&gt;   intValues(I) = 1&lt;br /&gt;&lt;br /&gt;   For intLoopI = 0 to (len(strInput)-1)   &lt;span style="color: #6aa84f;"&gt;' Assuming 0 indexing...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      intCurrentPointer = intValues(mid$(strInput,intLoopI,1)) &lt;span style="color: #6aa84f;"&gt;' Get the value of the current Roman Numeral character&lt;/span&gt;&lt;br /&gt;      intTotal = intTotal + intCurrentPointer                  &lt;span style="color: #6aa84f;"&gt;' Add the value to the total.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      If intCurrentPointer &amp;gt; intPreviousPointer then       &lt;span style="color: #6aa84f;"&gt;' If the current value is larger than the previous, then&lt;/span&gt;&lt;br /&gt;         intTotal = intTotal - (2 * intPreviousPointer)    &lt;span style="color: #6aa84f;"&gt;'  subtract twice the value of the previous character from the total.&lt;/span&gt;&lt;br /&gt;      EndIf&lt;br /&gt;&lt;br /&gt;      intPreviousPointer = intCurrentPointer      &lt;span style="color: #6aa84f;"&gt;' Move the value of the current character to be the&lt;/span&gt;&lt;br /&gt;                                                  &lt;span style="color: #6aa84f;"&gt;'  value of the previous character and get then next one.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   Next&lt;br /&gt;&lt;br /&gt;   Roman2Decimal = intTotal&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-7898358393585410911?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/7898358393585410911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=7898358393585410911' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/7898358393585410911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/7898358393585410911'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/roman-numeral-to-decimal-conversion.html' title='Roman Numeral to Decimal Conversion'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-375175086020615237</id><published>2010-05-10T08:56:00.000-04:00</published><updated>2010-05-10T08:56:15.636-04:00</updated><title type='text'>Spam</title><content type='html'>Due to the high number of spam comments recently, the ability to leave anonymous comments has been turned off. You can still leave comments by signing in with your Google or OpenID passwords.&lt;br /&gt;&lt;br /&gt;Thanks for your patience in this matter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-375175086020615237?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/375175086020615237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=375175086020615237' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/375175086020615237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/375175086020615237'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/spam.html' title='Spam'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-6963454184124234010</id><published>2010-05-06T22:22:00.001-04:00</published><updated>2010-05-06T22:55:37.611-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><title type='text'>Infix to RPN Notation</title><content type='html'>Here is a limited algorithm for converting infix notation to RPN notation.  The algorithm has no way of handling unary minuses (indicating negative numbers) nor does it deal with functions such as SIN(), COS(), SQR(), etc.  I describe one way of handling unary minus in the comments of the program listing below and will alter the code to handle those as well as sines, cosines, square roots, etc. at a later date.  In the mean time if you need an infix to RPN converter, this should handle most of your needs.&lt;br /&gt;&lt;br /&gt;Parsing from left to right, any numeric value we encounter or any alphanumeric string that could be interpreted as a variable is sent directly to the output, including decimal points.&lt;br /&gt;&lt;br /&gt;When we encounter anything other than numbers or letters (or a decimal point), we do the following:&lt;br /&gt;&lt;br /&gt;Append a token separator to the output string (in our case a comma.)&lt;br /&gt;&lt;br /&gt;If we encounter an open parenthesis, that parenthesis is pushed to a FILO stack.&lt;br /&gt;&lt;br /&gt;If we encounter a closing parenthesis, we discard it and pop operators from the stack to the end of the output string until we come to an open parenthesis.  The open parenthesis is then also discarded.&lt;br /&gt;&lt;br /&gt;If we encounter a low priority operator (+ or -) then we must first pop all operators (+, -, *, /, ^) from the stack to the end of the output string until the stack is empty or we encounter an open parenthesis and then push the low priority operator on to the stack.&lt;br /&gt;&lt;br /&gt;If we encounter a medium priority operator (* or /) then we must first pop any medium or high priority operators (*, /, ^) from the stack to the end of the output string  until the stack is empty or we encounter a low priority operator (+ or -) or we encounter an open parenthesis, then push the medium priority operator on to the stack.&lt;br /&gt;&lt;br /&gt;If we encounter a high priority operator (^) we pop all other high priority operators from the stack to the end of the output string then push the new high priority operator to the stack.&lt;br /&gt;&lt;br /&gt;Once all the input character have been processed, we pop operators off the stack until it's empty.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The listing below shows a Visual Basic implementation of the algorithm:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;'&lt;br /&gt;'   Infix to RPN - program to convert infix notation to&lt;br /&gt;'       RPN notation.  Operands are separated by commas, to&lt;br /&gt;'       use a different separation character change the&lt;br /&gt;'       line where txtSeparator is initialized.  The operator&lt;br /&gt;'       stack has been set to an upper limit of 100 operators,&lt;br /&gt;'       if you expect to have input strings with more than 100&lt;br /&gt;'       operators (heaven forbid...) increase the size of&lt;br /&gt;'       txtStack in the Dim statement.&lt;br /&gt;'&lt;br /&gt;'       This routine does not handle unary minus signs.  To allow&lt;br /&gt;'       unary minus signs two additional changes must be made.  In the&lt;br /&gt;'       Low Operator case (+, -) we must check to see if the previous&lt;br /&gt;'       input character was an alphanumeric.  If it IS alphanumeric&lt;br /&gt;'       we treat the minus as a normal binary operator.  If it is NOT&lt;br /&gt;'       alphanumeric, then we append a zero and token separator to the&lt;br /&gt;'       output string, and push a special unary minus character to the&lt;br /&gt;'       stack, which has an operator value equal to ^.  You can use the&lt;br /&gt;'       tilde "~" as the unary minus character since it's not being used&lt;br /&gt;'       for anything else.  I'll make this changes to the routine at a&lt;br /&gt;'       later date.&lt;br /&gt;'&lt;br /&gt;'   Written by -    Erik Oosterwal&lt;br /&gt;'   Started on -    Nov. 14, 2005&lt;br /&gt;'   Completed on -  Nov. 15, 2005&lt;br /&gt;&lt;br /&gt;    Dim txtSeparator, txtStack(100), txtCharacter As String     ' Declare all variables&lt;br /&gt;    Dim intPointer, intStackPointer As Integer                  ' used in the routine&lt;br /&gt;&lt;br /&gt;    txtSeparator = ","      ' Set the token separator to a comma&lt;br /&gt;    intPointer = 1          ' Start by looking at the first character in the input string&lt;br /&gt;    intStackPointer = 1     ' Start the operator stack at 1&lt;br /&gt;    txtOutput.Text = ""     ' Clear the output sting&lt;br /&gt;&lt;br /&gt;    While intPointer &lt;= Len(txtInput.Text)                      ' As long as there's characters in the string&lt;br /&gt;    &lt;br /&gt;        txtCharacter = Mid$(txtInput.Text, intPointer, 1)       ' get the next character.&lt;br /&gt;        &lt;br /&gt;        Select Case txtCharacter&lt;br /&gt;        &lt;br /&gt;            Case "0" To "9", ".", "A" To "Z", "a" To "z"        ' Numbers and variables get appended&lt;br /&gt;                txtOutput.Text = txtOutput.Text + txtCharacter  '   directly to the output string.&lt;br /&gt;                &lt;br /&gt;            Case "("&lt;br /&gt;                txtStack(intStackPointer) = txtCharacter        ' Open parentheses get pushed on the stack&lt;br /&gt;                intStackPointer = intStackPointer + 1&lt;br /&gt;                &lt;br /&gt;            Case ")"                                                    ' If we find a closing parenthesis&lt;br /&gt;                While intStackPointer &gt; 1 And _&lt;br /&gt;                        txtStack(intStackPointer - 1) &lt;&gt; "("            ' Clear the stack until we&lt;br /&gt;                    txtOutput.Text = txtOutput.Text + txtSeparator + _&lt;br /&gt;                        txtStack(intStackPointer - 1)                   ' get to the opening parenthesis.&lt;br /&gt;                    intStackPointer = intStackPointer - 1&lt;br /&gt;                Wend&lt;br /&gt;                intStackPointer = intStackPointer - 1       ' Decrease the stack pointer to overwrite the opening parenthesis.&lt;br /&gt;                &lt;br /&gt;            Case "+", "-"                                               ' Lowest operators&lt;br /&gt;                txtOutput.Text = txtOutput.Text + txtSeparator          ' Append a token separator to the output string.&lt;br /&gt;                &lt;br /&gt;' If there are any operators on the stack AND they're higher or equal valued than + and -, then...&lt;br /&gt;'   pop them off the stack and append them to the output string.&lt;br /&gt;                While intStackPointer &gt; 1 And _&lt;br /&gt;                        txtStack(intStackPointer - 1) &lt;&gt; "("&lt;br /&gt;                    txtOutput.Text = txtOutput.Text + _&lt;br /&gt;                        txtStack(intStackPointer - 1) + txtSeparator&lt;br /&gt;                    intStackPointer = intStackPointer - 1&lt;br /&gt;                Wend&lt;br /&gt;                txtStack(intStackPointer) = txtCharacter            ' Push the low operator on the stack.&lt;br /&gt;                intStackPointer = intStackPointer + 1&lt;br /&gt;                &lt;br /&gt;            Case "*", "/"                                           ' Medium operators&lt;br /&gt;                txtOutput.Text = txtOutput.Text + txtSeparator      ' Append a token separator to the output string.&lt;br /&gt;                &lt;br /&gt;' If there are any operators on the stack and they're higher or equal valued than * and /, then&lt;br /&gt;'   pop them off the stack and append them to the output string.&lt;br /&gt;                While intStackPointer &gt; 1 And _&lt;br /&gt;                        (txtStack(intStackPointer - 1) = "*" Or _&lt;br /&gt;                        txtStack(intStackPointer - 1) = "/" Or _&lt;br /&gt;                        txtStack(intStackPointer - 1) = "^")&lt;br /&gt;                    txtOutput.Text = txtOutput.Text + _&lt;br /&gt;                        txtStack(intStackPointer - 1) + txtSeparator&lt;br /&gt;                    intStackPointer = intStackPointer - 1&lt;br /&gt;                Wend&lt;br /&gt;                txtStack(intStackPointer) = txtCharacter        ' Push the medium operator on the stack.&lt;br /&gt;                intStackPointer = intStackPointer + 1&lt;br /&gt;                &lt;br /&gt;            Case "^"                                            ' High operators&lt;br /&gt;                txtOutput.Text = txtOutput.Text + txtSeparator  ' Append a token separator to the output string.&lt;br /&gt;                While intStackPointer &gt; 1 And _&lt;br /&gt;                        txtStack(intStackPointer - 1) = "^"&lt;br /&gt;                    txtOutput.Text = txtOutput.Text + _&lt;br /&gt;                        txtStack(intStackPointer - 1) + txtSeparator&lt;br /&gt;                    intStackPointer = intStackPointer - 1&lt;br /&gt;                Wend&lt;br /&gt;                txtStack(intStackPointer) = txtCharacter        ' Push the high operator on the stack.&lt;br /&gt;                intStackPointer = intStackPointer + 1&lt;br /&gt;                &lt;br /&gt;' There is no default case included in this routine.  Any characters not explicitly taken care&lt;br /&gt;'   of by the cases will be ignored as whitespace.  Some characters, such as x, #, and others&lt;br /&gt;'   that are used to denote binary, hex, octal, etc. numbers could be taken care of in the first&lt;br /&gt;'   case where numeric and alpha tokens are handled.  It's ok to ignore spaces, tabs and other&lt;br /&gt;'   white space.&lt;br /&gt;        &lt;br /&gt;        End Select&lt;br /&gt;    &lt;br /&gt;        intPointer = intPointer + 1             ' Set the pointer to look at the next character&lt;br /&gt;        &lt;br /&gt;    Wend&lt;br /&gt;    &lt;br /&gt;'   All the input characters have been taken care of, now it's time to clear the stack.&lt;br /&gt;'&lt;br /&gt;    While intStackPointer &gt; 1                               ' As long as there's still operators on the stack&lt;br /&gt;        txtOutput.Text = txtOutput.Text + txtSeparator + _&lt;br /&gt;            txtStack(intStackPointer - 1)                   ' Take one off and append it to the output string&lt;br /&gt;        intStackPointer = intStackPointer - 1               ' look at the previous operator&lt;br /&gt;    Wend&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-6963454184124234010?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/6963454184124234010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=6963454184124234010' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6963454184124234010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6963454184124234010'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/infix-to-rpn-notation.html' title='Infix to RPN Notation'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-3190928205200614859</id><published>2010-05-05T18:07:00.001-04:00</published><updated>2010-05-06T22:54:08.878-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sorting'/><title type='text'>A Replacement for the Bubble Sort</title><content type='html'>For reference, here's a listing of the Bubble Sort algorithm in Visual Basic:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;' Bubble Sort&lt;br /&gt;&lt;br /&gt;    Dim I, J, IntArray(), Temp as Integer ' Declare Variables&lt;br /&gt;&lt;br /&gt;    For I = 1 To Length - 1 ' Supposed to be the smaller value&lt;br /&gt;        For J = I To Length ' Supposed to be the larger value&lt;br /&gt;            If IntArray(I) &amp;gt; IntArray(J) Then ' Compare Cells&lt;br /&gt;                Temp = IntArray(I) ' \&lt;br /&gt;                IntArray(I) = IntArray(J) ' | Swap Cells&lt;br /&gt;                IntArray(J) = Temp ' /&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;    Next&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;There's not much good to say about the Bubble Sort except that it's small and compact size-wise.  Performance-wise it's a whole other animal.&lt;br /&gt;&lt;br /&gt;So what do you do when you need a sorting algorithm that's comparable to a Quick Sort in terms of performance but still only takes up about as much space as the Bubble Sort?  Consider implementing the O-Sort.  Here's a listing of the O-Sort in Visual Basic:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;' O-Sort   (Oosterwal Sort)  Version 3&lt;br /&gt;&lt;br /&gt;    SngPhi = 0.78     ' Define phi value&lt;br /&gt;    SngFib = Length * SngPhi    ' Set initial real step size&lt;br /&gt;    Step = Int(SngFib)     ' Set initial integer step size&lt;br /&gt;    &lt;br /&gt;    While (Step &gt; 0)&lt;br /&gt;        &lt;br /&gt;        For I = 1 To Length - Step   ' Range of lower cell&lt;br /&gt;            If IntArray(I) &gt; IntArray(I + Step) Then ' Compare cells&lt;br /&gt;                Temp = IntArray(I)   ' \&lt;br /&gt;                IntArray(I) = IntArray(I + Step) ' | Swap Cells&lt;br /&gt;                IntArray(I + Step) = Temp  ' /&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;            &lt;br /&gt;        SngFib = SngFib * SngPhi   ' Decrease the Real step size&lt;br /&gt;        Step = Int(SngFib)    ' Set the integer step value&lt;br /&gt;        &lt;br /&gt;    Wend&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here's how it works.&lt;br /&gt;&lt;br /&gt;The O-Sort is a type of Comb Sort algorithm.  Comb Sort algorithms use a step size or interval between the two values being compared that starts off large, compared to the number of values being sorted, and becomes smaller for each subsequent pass of the data.  The idea behind the algorithm is to get chunks of the larger values to the end of the list and chunks of the smaller values to the beginning of the list quickly, then with each subsequent pass of the data look at values that are closer together and moving smaller chunks of data shorter distances until during the last pass neighboring data points are compared.&lt;br /&gt;&lt;br /&gt;In practice, with 10,000 elements of completely randomized data the O-Sort takes about 1.6 times longer to sort the data than the Quick Sort.  For comparison, the Shell Sort takes 36 times as long and the Bubble Sort takes over 200 times as long.&lt;br /&gt;&lt;br /&gt;When you have data that is less randomized, such as what you would get when appending lists of sorted data, the Quick Sort is less quick.  When 10% of the data is randomized the O-Sort requires 0.96 as much time to completely sort the data as the Quick Sort.  When only 5% of the data is randomized, the O-Sort takes only 0.61 as much time to completely sort the data as the Quick Sort.&lt;br /&gt;&lt;br /&gt;When you need a fast in-place sorting algorithm that doesn't require much code space consider using the O-Sort routine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-3190928205200614859?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://sites.google.com/site/computersciencesourcecode/sortroutines' title='A Replacement for the Bubble Sort'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/3190928205200614859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=3190928205200614859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/3190928205200614859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/3190928205200614859'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2010/05/replacement-for-bubble-sort.html' title='A Replacement for the Bubble Sort'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-6030938740836488141</id><published>2008-02-18T21:31:00.004-05:00</published><updated>2008-02-18T21:58:57.874-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='roman'/><title type='text'>Decimal Value to Roman Numeral - Algorithm 2</title><content type='html'>If you haven't seen the earlier algorithm to change Decimal Values to Roman Numerals you can read that blog here: &lt;a href="http://computeralgorithms.blogspot.com/2008/02/convert-decimal-values-to-roman.html"&gt;Decimal Values to Roman Numeral Algorithm 1&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following code represents a shorter algorithm that should be easy enough to understand. Algorithm 2 does away with the cumbersome IF statements from the previous algorithm and wraps up all the conversions in one WHILE loop. This function the same principle as that used in the previous algorithm, but instead of hard coding all the values of the Roman Numeral characters and pairs into separate IF and WHILE clauses, the values and characters are stored in a couple of arrays and referenced in a single WHILE loop. I have not compared the speeds of the two algorithms demonstrated here and in &lt;a href="http://computeralgorithms.blogspot.com/2008/02/convert-decimal-values-to-roman.html"&gt;Decimal Values to Roman Numeral Algorithm 1&lt;/a&gt;. The speed tests will be covered in a later blog, but for now, here's the code written in VB .NET:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;center&gt;&lt;b&gt;DECIMAL to ROMAN Algorithm 2&lt;/b&gt;&lt;/center&gt;&lt;br /&gt;&lt;span style="font-size:75%;"&gt;&lt;pre&gt;&lt;br /&gt;    Private Sub cmdConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConvert.Click&lt;br /&gt;&lt;br /&gt;        ' Declare and initialize all variables.  Roman Numerals and their standard combinations&lt;br /&gt;        '   are stored in strRoman.  The corresponding values are stored in intDecimal.&lt;br /&gt;&lt;br /&gt;        Dim strRoman() As String = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}&lt;br /&gt;        Dim intDecimal() As Integer = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}&lt;br /&gt;        Dim intInput As Integer = Nothing           ' Numeric representation of the input field.&lt;br /&gt;        Dim intTemp As Integer = Nothing            ' Used to store the magnitude of each decimal digit.&lt;br /&gt;        Dim intPointer As Short = 0                 ' Pointer to the Roman and Decimal arrays, starts at the first cell.&lt;br /&gt;        Dim intCountI As Short = Nothing            ' Temporary variable used for loops.&lt;br /&gt;&lt;br /&gt;        intInput = CInt(txtInput.Text)              ' Convert the string in the input field to an integer.&lt;br /&gt;        txtOutput.Clear()                           ' Clear the contents of the output field.&lt;br /&gt;&lt;br /&gt;        While intInput &amp;gt; 0                                  ' Check to see if intInput still has any value left in it.&lt;br /&gt;            intTemp = intInput \ intDecimal(intPointer)     ' See how many of the currently selected value can fit in the remaining input.&lt;br /&gt;&lt;br /&gt;            For intCountI = 1 To intTemp&lt;br /&gt;                txtOutput.Text += strRoman(intPointer)      ' Append a number of Roman Characters depending on the value of intTemp.&lt;br /&gt;            Next&lt;br /&gt;&lt;br /&gt;            intInput -= intTemp * intDecimal(intPointer)    ' Subtract the value of the characters that were appended to output from the input.&lt;br /&gt;            intPointer += 1                                 ' Move the pointer to the next cell of the arrays.&lt;br /&gt;        End While&lt;br /&gt;&lt;br /&gt;    End Sub&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;You can download a ZIP file with all the VB .NET project files and an executable using this algorithm &lt;a href="http://www.geocities.com/oosterwal/computer/Decimal2Roman.zip"&gt;here&lt;/a&gt;.  You can also see several other algorithm implementations at the &lt;a href="http://www.geocities.com/oosterwal/computer.html"&gt;Computer Science 101&lt;/a&gt; website.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-6030938740836488141?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.geocities.com/oosterwal/computer/roman.html' title='Decimal Value to Roman Numeral - Algorithm 2'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/6030938740836488141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=6030938740836488141' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6030938740836488141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6030938740836488141'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2008/02/decimal-value-to-roman-numeral.html' title='Decimal Value to Roman Numeral - Algorithm 2'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-5133904383026307622</id><published>2008-02-16T01:36:00.005-05:00</published><updated>2008-02-16T01:53:35.177-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='binary'/><category scheme='http://www.blogger.com/atom/ns#' term='floating point'/><title type='text'>Convert Floating Point Decimal Values to Floating Point Binary Representation</title><content type='html'>&lt;br /&gt;A visitor to this site send me an email asking if it were possible to use the &lt;A HREF="http://www.geocities.com/oosterwal/computer/numericbase.html"&gt;Numeric Base Conversion&lt;/A&gt; algorithm to convert fractions between bases. &amp;nbsp;I thought it would be pretty straight forward to implement the change to the general algorithm, but found it was easier just to make a single purpose algorithm to convert from decimal to binary, since that was specifically what he asked for. &amp;nbsp;As time allows, I'll update the algorithm to make it general purpose to convert fractions between any two bases.&lt;BR /&gt;&lt;BR /&gt;&lt;br /&gt;This algorithm borrows from the general &lt;A HREF="http://www.geocities.com/oosterwal/computer/numericbase.html"&gt;Numeric Base Conversion&lt;/A&gt; algorithm, but it has been simplified to only convert from base 10 to base 2, and an additional portion that converts the fractional part of the input number to a binary fraction has been added.&lt;BR /&gt;&lt;BR /&gt;&lt;br /&gt;Binary fractions are a bit tricky to work with. &amp;nbsp;Some values convert easily, such as 0.5, 0.375, and 0.75, which are 0.1, 0.011, and 0.11, respectively, in binary form. &amp;nbsp;Other fractional values, which are easily displayed in base 10, become long strings of seemingly random bits. &amp;nbsp;For instance, 1/10 = 0.1 (base 10) = 0.000110011001100110... (base 2), and 1/3 = 0.33333... (base 10) = 0.010011001100110011... (base 2), and 1/100 = 0.01 (base 10) = 0.000000101000111101... (base 2).&lt;BR /&gt;&lt;BR /&gt;&lt;br /&gt;If you are already familiar with binary notation, you recognize that each binary digit represents a power of 2. &amp;nbsp;Starting at the least significant bit and moving towards the most significant bit, the bits represent 1, 2, 4, 8, 16, 32, 64, 128, etc. &amp;nbsp;Just as decimal fraction digits represent the inverses of the powers of 10:&amp;nbsp;1/10, 1/100, 1/1000, etc, binary fractional bits represent the inverses of the powers of 2: &amp;nbsp;1/2, 1/4, 1/8, 1/16, etc., which are 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, etc. &amp;nbsp;As you can see, we have to take a binary fraction out to 7 places before we get less than 0.01 (base 10).&lt;BR /&gt;&lt;BR /&gt;&lt;br /&gt;The Visual Basic code below will only output 20 bits, including the decimal point. &amp;nbsp;You can modify this yourself by changing the value assigned to intNumBits near the top of the listing. &amp;nbsp;The embedded comments in the code should be fairly explanatory, but if you have questions or comments, feel free to leave a comment to this post.&lt;BR /&gt;&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;br /&gt;Private Sub Dec2Bin_Click()&lt;br /&gt;&lt;br /&gt;'   Subroutine to convert floating point decimal values to floating point binary values.&lt;br /&gt;'&lt;br /&gt;'   Written by: Erik Oosterwal&lt;br /&gt;'   Started on: October 26, 2005&lt;br /&gt;'   Completed:  October 27, 2005&lt;br /&gt;&lt;br /&gt;    Dim txtNumericBaseData, txtOutputValue As String&lt;br /&gt;    Dim intX, intNumBits As Integer&lt;br /&gt;    Dim dblDecimalValue, dblFractionValue, dblBinaryFraction As Double&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;    intNumBits = 20             ' The number of bits in the output (including the decimal point)&lt;br /&gt;    txtNumericBaseData = "01"   ' Output digits can be either "0" or "1"&lt;br /&gt;    dblBinaryFraction = 0.5     ' Binary fraction bits are powers of 0.5&lt;br /&gt;    txtOutput.Text = ""         ' Clear the display&lt;br /&gt;    txtOutputValue = ""         ' Clear the working output variable&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    dblDecimalValue = Int(CDbl(txtInput.Text))                  ' Get the integer portion of the input&lt;br /&gt;    dblFractionValue = CDbl(txtInput.Text) - dblDecimalValue    ' Get the fractional portion of the input&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;'   Figure out the integer portion of the input.&lt;br /&gt;    While dblDecimalValue &amp;gt; 0&lt;br /&gt;        intX = Int(((dblDecimalValue / 2) - Int(dblDecimalValue / 2)) * 2 + 1.5)&lt;br /&gt;        txtOutputValue = Mid(txtNumericBaseData, intX, 1) + txtOutputValue&lt;br /&gt;        dblDecimalValue = Int(dblDecimalValue / 2)&lt;br /&gt;    Wend&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    If txtOutputValue = "" Then txtOutputValue = "0"    ' If there was no whole number, set it to "0"&lt;br /&gt;    txtOutputValue = txtOutputValue + "."               '   then add a decimal point&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;'   Figure out the fractional portion of the input.&lt;br /&gt;    While Len(txtOutputValue) &amp;lt; intNumBits And dblFractionValue &amp;gt; 0     ' As long as we're not exceeding the&lt;br /&gt;                                                                        ' allowed number of bits in the output&lt;br /&gt;                                                                        ' and there's still part of the input&lt;br /&gt;                                                                        ' value to be converted...&lt;br /&gt;        If dblFractionValue &amp;gt;= dblBinaryFraction Then                   ' If the input number is larger than the fraction bit,&lt;br /&gt;            txtOutputValue = txtOutputValue + "1"                       '   add a "1" to the output and&lt;br /&gt;            dblFractionValue = dblFractionValue - dblBinaryFraction     '   reduce the input number by the fraction bit's value.&lt;br /&gt;        Else                                                            ' Otherwise...&lt;br /&gt;            txtOutputValue = txtOutputValue + "0"                       '   just tag on a "0" to the end of the output.&lt;br /&gt;        End If&lt;br /&gt;        dblBinaryFraction = dblBinaryFraction / 2#                      ' The fraction bit must be cut in half.&lt;br /&gt;    Wend&lt;br /&gt;    &lt;br /&gt;    txtOutput.Text = txtOutputValue                     ' Send the output value to the display.&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For a more generalized routine that can convert integer values between any two numeric bases, see the &lt;A HREF="http://www.geocities.com/oosterwal/computer/numericbase.html"&gt;Numeric Base Conversion&lt;/A&gt; article from the main &lt;A HREF="http://www.geocities.com/oosterwal/computer.html"&gt;Computer Science 101&lt;/A&gt; page.&lt;BR /&gt;&lt;br /&gt;&lt;br /&gt;You can also &lt;A HREF="http://www.geocities.com/oosterwal/computer/dec2bin.zip"&gt;download a zip file&lt;/A&gt; that contains the listing given above as well as an executable file that demonstrates this routine.&lt;BR /&gt;&lt;BR /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-5133904383026307622?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.geocities.com/oosterwal/computer/dec2bin.html' title='Convert Floating Point Decimal Values to Floating Point Binary Representation'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/5133904383026307622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=5133904383026307622' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/5133904383026307622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/5133904383026307622'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2008/02/convert-floating-point-decimal-values.html' title='Convert Floating Point Decimal Values to Floating Point Binary Representation'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816646335787825774.post-6910267814974493315</id><published>2008-02-16T01:06:00.006-05:00</published><updated>2008-02-16T01:54:20.235-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='conversion'/><category scheme='http://www.blogger.com/atom/ns#' term='decimal'/><category scheme='http://www.blogger.com/atom/ns#' term='roman'/><title type='text'>Convert Decimal Values to Roman Numerals - Algorithm 1</title><content type='html'>&lt;br /&gt;Roman numerals follow a fairly strict rule in sequence in order to reduce ambiguity in numbers. To create Roman numerals we must first define which letters represent which values, and what exceptions there are to the basic rule.&lt;br /&gt;&lt;br /&gt;First, the following letters represent the associated values:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;I = 1&lt;br /&gt;&lt;br /&gt;V = 5&lt;br /&gt;&lt;br /&gt;X = 10&lt;br /&gt;&lt;br /&gt;L = 50&lt;br /&gt;&lt;br /&gt;C = 100&lt;br /&gt;&lt;br /&gt;D = 500&lt;br /&gt;&lt;br /&gt;M = 1000&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The basic rule states that numerals are read from left to right, larger valued letters precede smaller valued letters, and multiple letters in a row represent multiples of that value. For instance:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;I = 1&lt;br /&gt;II = 2&lt;br /&gt;III = 3&lt;br /&gt;VIII = 8&lt;br /&gt;CVIII = 108&lt;br /&gt;CCVIII = 208&lt;br /&gt;DCCVIII = 708&lt;br /&gt;MDCCVIII = 1708&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The single exception to the basic rule is that if a larger value letter is preceded by a single smaller value letter, then the combination represents the value of the larger value letter minus the value of the smaller value letter. This exception only holds true for the values 4, 9, 40, 90, 400, and 900, which are written as IV, IX, XL, XC, CD, and CM respectively.&lt;br /&gt;&lt;br /&gt;A seldom used convention of Roman numerals is that you can create values larger values by overscoring letters to represent the letter's normal value multiplied by 1000:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;_&lt;br /&gt;V = 5000&lt;br /&gt;_&lt;br /&gt;X = 10,000&lt;br /&gt;_&lt;br /&gt;L = 50,000&lt;br /&gt;_&lt;br /&gt;C = 100,000&lt;br /&gt;_&lt;br /&gt;D = 500,000&lt;br /&gt;_&lt;br /&gt;M = 1,000,000&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We won't bother with the larger values in this routine and limit our numbers to values between 1 and 3999.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;strong&gt;DECIMAL to ROMAN Algorithm 1&lt;/strong&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The following pseudo code should provide enough information to implement the algorithm in your language of choice:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-size:65%;"&gt;&lt;strong&gt;&lt;pre&gt;function roman(InputValue) as string&lt;br /&gt;&lt;br /&gt;dim InputValue as integer  ' Declare Variables&lt;br /&gt;dim RomanValue as string&lt;br /&gt;&lt;br /&gt;if (InputValue &gt; 3999) OR (InputValue &lt; 1)&lt;br /&gt; roman = "N/A"&lt;br /&gt; return&lt;br /&gt;endif&lt;br /&gt;&lt;br /&gt;RomanValue = ""&lt;br /&gt;&lt;br /&gt;While InputValue &gt; 999 (&lt;br /&gt;  RomanValue = RomanValue + "M" ' Concatenate the letters to the right side&lt;br /&gt;  InputValue = InputValue - 1000 ' Reduce the amount left in InputValue&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 899 (&lt;br /&gt;  RomanValue = RomanValue + "CM" ' Concatenate letters to the right side&lt;br /&gt;  InputValue = InputValue - 900&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 499 (&lt;br /&gt;  RomanValue = RomanValue + "D"&lt;br /&gt;  InputValue = InputValue - 500&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 399 (&lt;br /&gt;  RomanValue = RomanValue + "CD"&lt;br /&gt;  InputValue = InputValue - 400&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;While InputValue &gt; 99 (&lt;br /&gt;  RomanValue = RomanValue + "C"&lt;br /&gt;  InputValue = InputValue - 100&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 89 (&lt;br /&gt;  RomanValue = RomanValue + "XC"&lt;br /&gt;  InputValue = InputValue - 90&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 49 (&lt;br /&gt;  RomanValue = RomanValue + "L"&lt;br /&gt;  InputValue = InputValue - 50&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 39 (&lt;br /&gt;  RomanValue = RomanValue + "XL"&lt;br /&gt;  InputValue = InputValue - 40&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;While InputValue &gt; 9 (&lt;br /&gt;  RomanValue = RomanValue + "X"&lt;br /&gt;  InputValue = InputValue - 10&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 8 (&lt;br /&gt;  RomanValue = RomanValue + "IX"&lt;br /&gt;  InputValue = InputValue - 9&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 4 (&lt;br /&gt;  RomanValue = RomanValue + "V"&lt;br /&gt;  InputValue = InputValue - 5&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;If InputValue &gt; 3 (&lt;br /&gt;  RomanValue = RomanValue + "IV"&lt;br /&gt;  InputValue = InputValue - 4&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;While InputValue &gt; 0 (&lt;br /&gt;  RomanValue = RomanValue + "I"&lt;br /&gt;  InputValue = InputValue - 1&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;roman = RomanValue&lt;br /&gt;&lt;br /&gt;return&lt;/pre&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;This is not a particularly efficient algorithm.  In later articles additional algorithms will be discussed that show better ways to convert from Decimal Values to Roman Numerals and from Roman Numerals back to Decimal Values.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6816646335787825774-6910267814974493315?l=computeralgorithms.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.geocities.com/oosterwal/computer/roman.html' title='Convert Decimal Values to Roman Numerals - Algorithm 1'/><link rel='replies' type='application/atom+xml' href='http://computeralgorithms.blogspot.com/feeds/6910267814974493315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6816646335787825774&amp;postID=6910267814974493315' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6910267814974493315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816646335787825774/posts/default/6910267814974493315'/><link rel='alternate' type='text/html' href='http://computeralgorithms.blogspot.com/2008/02/convert-decimal-values-to-roman.html' title='Convert Decimal Values to Roman Numerals - Algorithm 1'/><author><name>Erik</name><uri>http://www.blogger.com/profile/14514993727423832898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
