Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike>Without writing all your code for you, here's a suggestion as to how you can break this down:</strike></p> <pre><code>char DecrementAlphaNumericChar(char input, out bool hadToWrap) { if (input == 'A') { hadToWrap = true; return 'Z'; } else if (input == '0') { hadToWrap = true; return '9'; } else if ((input &gt; 'A' &amp;&amp; input &lt;= 'Z') || (input &gt; '0' &amp;&amp; input &lt;= '9')) { hadToWrap = false; return (char)((int)input - 1); } throw new ArgumentException( "Characters must be digits or capital letters", "input"); } char DecrementAvoidingProhibited( char input, List&lt;char&gt; prohibited, out bool hadToWrap) { var potential = DecrementAlphaNumericChar(input, out hadToWrap); while (prohibited.Contains(potential)) { bool temp; potential = DecrementAlphaNumericChar(potential, out temp); if (potential == input) { throw new ArgumentException( "A whole class of characters was prohibited", "prohibited"); } hadToWrap |= temp; } return potential; } string DecrementString(string input, List&lt;char&gt; prohibited) { char[] chrs = input.ToCharArray(); for (int i = chrs.Length - 1; i &gt;= 0; i--) { bool wrapped; chrs[i] = DecrementAvoidingProhibited( chrs[i], prohibited, out wrapped); if (!wrapped) return new string(chrs); } return "-"; } </code></pre> <p>The only issue here is that it will reduce e.g. <code>A10</code> to <code>A09</code> not <code>A9</code>. I actually prefer this myself, but it should be simple to write a final pass that removes the extra zeroes.</p> <p>For a little more performance, replace the <code>List&lt;char&gt;</code>s with Hashset<code>&lt;char&gt;</code>s, they should allow a faster <code>Contains</code> lookup.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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