Guest User

The Beauty of Backwards NumCheck

a guest
Mar 7th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. private static String BackwardsNumCheck(ulong Num, String currentEnum)
  2.         {
  3.             Num = Num > 9 ? 9 : Num; //if num is greater than 9, then we just default to greatest possible number
  4.             List<char> test = new List<char>(); //turn it into a list for reversing
  5.             //potential for doing incrementation loop here with a carry boolean
  6.  
  7.             //just fuckin do it backwards lul
  8.             //enumerate through initial string and go from there
  9.  
  10.             bool carry = false; // this will tell the below loop whether it needs to add 1 to the next number or not, thus saving an entire loop over of the stringset
  11.             foreach (char c in currentEnum.Reverse()) //reverse the string in so that we don't need to do recursive calling
  12.             {
  13.                 uint bar = uint.Parse(c.ToString()); //convert the char to an integer we can work with
  14.                 if (carry)
  15.                 {
  16.                     bar++; //if carry bit is present, add 1
  17.                     carry = false;
  18.                 }
  19.                 test.Add(((bar > Num ? Convert.ToChar(bar + 1) : c) > Num ? (carry = true) : carry = false) ? '1' : Convert.ToChar(bar+1)); //if the char is greater than num, increment it, otherwise put the regular char in
  20.             }
  21.             //reverse the reversed string for checking if it contains the sequences
  22.             test.Reverse();
  23.             //compile list into a full string
  24.             String foo = "";
  25.             foreach (char c in test) //sequence the string
  26.             {
  27.                 foo += c;
  28.             }
  29.            
  30.             return foo; //return string that is proper way around
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment