Advertisement
Guest User

Untitled

a guest
Jul 7th, 2019
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1.         static List<String> PossibleCommands(int lines) {
  2.             List<string> outputList = new List<string>();
  3.             Rec(outputList, lines, "", -1);
  4.             return outputList;
  5.         }
  6.  
  7.         static void Rec(List<string> outputList, int linesLeft, string stringAcc, int last = -1) {
  8.             // recursion bottom
  9.             if (linesLeft == 0) {
  10.                 outputList.Add(stringAcc.Substring(0, stringAcc.Length - 1));
  11.                 return;
  12.             }
  13.  
  14.             // dj, d2j, ...
  15.             for (int i = 1; i < linesLeft; i++) {
  16.                 // dNj
  17.                 Rec(outputList, linesLeft - i - 1, stringAcc + $"d{i}j ", i + 1);
  18.                 if (i == 1) {
  19.                     // dj
  20.                     Rec(outputList, linesLeft - i - 1, stringAcc + "dj ", 2);
  21.                 }
  22.             }  
  23.  
  24.             // dd
  25.             Rec(outputList, linesLeft - 1, stringAcc + "dd ", 1);
  26.  
  27.             // dot command
  28.             if (last > 0 && linesLeft >= last) {
  29.                 string add = ". ";
  30.                 Rec(outputList, linesLeft - last, stringAcc + add, last);
  31.             }
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement