Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The examples you show make this considerably more complex than necessary, at least IMO.</p> <p>What you're really looking at is a 3 digit, base 3 number. You can just count from 0 to 3<sup>3</sup> = 27, then convert each number to base 3 (using 'A', 'B' and 'C' as your digits instead of '0', '1' and '2').</p> <p>In C++, the conversion could look something like this:</p> <pre class="lang-c prettyprint-override"><code>std::string cvt(int in) { static const int base = 3; static const int digits = 3; std::string ret; for (int i = 0; i&lt;digits; i++) { ret.push_back('A' + in % base); in /= base; } return std::string(ret.rbegin(), ret.rend()); } </code></pre> <p>With the conversion in place, producing all the combinations becomes utterly trivial:</p> <pre><code>for (int i = 0; i &lt; 27; i++) std::cout &lt;&lt; cvt(i) &lt;&lt; "\t"; </code></pre> <p>I believe converting that to Delphi should be barely short of purely mechanical -- assignments change from <code>=</code> to <code>:=</code>, <code>%</code> becomes <code>mod</code>, the integer division changes to <code>div</code>, the <code>for</code> loop changes to something like <code>for i = 0 to 27 do</code>, and so on. The most tedious (but ultimately quite simple) part will probably be dealing with the fact that in C++, <code>char</code> is simply a small integer type, on which you can do normal integer math. At least if memory serves, in Pascal (or a derivative like Delphi) you'll need <code>ord</code> to convert from a character to an ordinal, and <code>chr</code> to convert back from ordinal to character. So the <code>'A' + in % base;</code> will end up something more like <code>chr(ord('A') + in mod base);</code></p> <p>Like I said though, it seems like nearly the entire translation could/should end up almost completely mechanical, with no requirement for real changes in how the basic algorithms work, or anything like that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload