Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. public List<String> BinaryToUnary(List<string> value)
  2. {
  3. var temp = new List<string>();
  4. var temp2 = new List<string>();
  5. var temp3 = new List<string>();
  6. string hold = "";
  7. int count = 1;
  8.  
  9.  
  10. TxtToDisPlay = "Major Step 1: replace All 1 with 0l userInput " + string.Join("", value) + "nn";
  11.  
  12. foreach (var x in value)
  13. {
  14. if (x.Equals("1"))
  15. {
  16. temp.Add("0l");
  17. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + x + " = " + "0l" + "n";
  18. }
  19. else
  20. {
  21. temp.Add(x);
  22. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + x + " = " + x + "n";
  23. }
  24. count++;
  25. }
  26. TxtToDisPlay = TxtToDisPlay + "nnMajor Step 2: Replace all l0 with 0ll userInput = " + string.Join("", temp) + " nn";
  27.  
  28. foreach (var x in string.Join("", temp))
  29. {
  30. hold = hold + x;
  31. if (hold.Equals("l0"))
  32. {
  33. temp2.Add("0ll");
  34. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + "0ll" + "n";
  35. hold = "";
  36. }
  37. if (hold.Equals("0"))
  38. {
  39. temp2.Add(hold);
  40. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "n";
  41. hold = "";
  42. }
  43. count++;
  44. }
  45. if (hold.Equals("l"))
  46. {
  47. temp2.Add("l");
  48. }
  49.  
  50.  
  51. hold = "";
  52.  
  53. foreach (var y in string.Join("", temp2))
  54. {
  55. if (temp2.Count == 1)
  56. {
  57. temp3.Add("l");
  58. break;
  59. }
  60.  
  61. hold = hold + y;
  62. if (hold.Equals("l0"))
  63. {
  64. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + "0ll" + "n";
  65. temp3.Add("0ll");
  66. hold = "";
  67. }
  68. if (hold.Equals("0") || hold.Equals("ll"))
  69. {
  70. if (hold.Equals("ll"))
  71. {
  72. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "n";
  73. temp3.Add("l");
  74. hold = "l";
  75. }
  76. else
  77. {
  78. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "n";
  79. temp3.Add(hold);
  80. hold = "";
  81. }
  82.  
  83. }
  84. }
  85. if (value.Count == 3 && hold.Equals("l"))
  86. {
  87. temp3.Add("l");
  88. temp3.Add("l");
  89. }
  90. else if (value.Count == 3 || hold.Equals("l"))
  91. {
  92. temp3.Add("l");
  93.  
  94. }
  95.  
  96. TxtToDisPlay = TxtToDisPlay + "nnMajor Step 3 : get rid of the 0 from userInput = " + string.Join("", temp3) + " nn";
  97. var answer = new List<string>();
  98. foreach (var x in temp3)
  99. {
  100. if (x.Contains("0ll"))
  101. {
  102. foreach (var y in x.Where(y => y.Equals('l')))
  103. {
  104. answer.Add("l");
  105. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + "x = l so " + "Add l To new Array result = " + string.Join("", answer) + "n";
  106. }
  107. }
  108. else if (x.Contains("l"))
  109. {
  110. TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + "Add l To new Array result = " + string.Join("", answer) + "n";
  111. answer.Add(x);
  112. }
  113. count++;
  114. }
  115.  
  116. return answer;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement