Guest User

Untitled

a guest
Nov 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. //AE9B5417C362D8F0
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. bool isl(char a)
  13. {
  14. return a >= 'A' && a <= 'F';
  15. }
  16.  
  17.  
  18. bool lexco(char a, char b)
  19. {
  20. if(isl(a) && !isl(b))
  21. {
  22. return true;
  23.  
  24. } else if(!isl(a) && isl(b))
  25. {
  26. return false;
  27. }
  28. else {
  29. return a < b;
  30. }
  31. }
  32.  
  33. // THIS CODE iterates from lowest lexicographical F to highest, starting from ABCDEF0123456789 all the way up.
  34. int main()
  35. {
  36. string chars = "ABCDEF0123456789";
  37.  
  38. // We are making an array with the letters so that we can use the next_permutation method on it
  39. vector<char> perm;
  40. perm.push_back('A');
  41. perm.push_back('B');
  42. perm.push_back('C');
  43. perm.push_back('D');
  44. perm.push_back('E');
  45. perm.push_back('F');
  46. perm.push_back('0');
  47. perm.push_back('1');
  48. perm.push_back('2');
  49. perm.push_back('3');
  50. perm.push_back('4');
  51. perm.push_back('5');
  52. perm.push_back('6');
  53. perm.push_back('7');
  54. perm.push_back('8');
  55. perm.push_back('9');
  56.  
  57. do
  58. {
  59.  
  60. //This loop turns the array into a string, a push_back every character onto the string 'news'
  61. string news = "";
  62. for(int i=0;i<perm.size();++i)
  63. {
  64. news.push_back(perm[i]);
  65. }
  66.  
  67.  
  68. string S = "AE9B5417C362D8F0";
  69. string basic = "ABCDEF0123456789";
  70.  
  71. string currF = news;
  72.  
  73. //here I load the map so that it maps the function correctly
  74. // the string called 'basic' is the characters in order
  75. // this is supposed to represent ABCDEF0123456789 -> f
  76. map<char,char> currMap;
  77. for(int j=0;j<currF.size();++j)
  78. {
  79. currMap[basic[j]] = currF[j];
  80. }
  81.  
  82. //Soon we will iterate 50 times to apply f in repetition
  83. // We set the initial F^k to S, it represents f^0 (function not yet applied)
  84. string currFk = S;
  85. bool goodF = true;
  86.  
  87. // This variable F1 represents F^1, we just store it so we can print it at the end if it's the right answer
  88. string F1 = "";
  89.  
  90. // Now we apply the first 50 times.
  91. for(int j=0;j<50;++j)
  92. {
  93. //This builds a string by mapping the currFk using the currMap we built
  94. string newS = "";
  95. for(int k=0;k<S.length();++k)
  96. {
  97. newS.push_back(currMap[currFk[k]]);
  98. }
  99.  
  100. // Update currFK with the new one
  101. currFk = newS;
  102.  
  103. // Check if it does not satisfy the 2nd condition, it should not equal S
  104. if(currFk == S)
  105. {
  106. // If it does, we flag 'goodF' to false, so we can just skip it once this block of code ends.
  107. goodF = false;
  108. break;
  109. }
  110.  
  111. // We note down F1 if j happens to be in the first iteration, since we'll need it later
  112. if(j == 0)
  113. {
  114. F1 = currFk;
  115. }
  116.  
  117. }
  118.  
  119. // So if this is a 'goodF' (meaning that it satisfies the 2nd condition)
  120. if(goodF)
  121. {
  122. // We will apply the function f, sz times (note we are starting from f^0, not f^50 [we are doing some work over again])
  123. int sz = 10000;
  124.  
  125. // currR1 is originally S, this represents F^0 (no function applied)
  126. string currR1 = S;
  127. for(int j=0;j<sz;++j)
  128. {
  129. // Apply the function, and place it in variable 'newS'
  130. string newS = "";
  131. for(int k=0;k<S.length();++k)
  132. {
  133. newS.push_back(currMap[currR1[k]]);
  134. }
  135.  
  136. // Update currR1 with the new string with the function applied.
  137. currR1 = newS;
  138.  
  139. // If J > 50, we want to see if we should be checking the first condition yet, or not
  140. if(j>=50)
  141. {
  142. // If we find a k such that currR1 == S , then we have found a solution
  143. if(currR1 == S)
  144. {
  145. cout << "F is " << currF << " -> F(S) = " << F1 << " / found at F^" << j+1 << endl;
  146.  
  147. //We only need the first one since we are iterating from lowest lexicographical F to higher, so we return now.
  148. return 0;
  149. }
  150. }
  151. }
  152. }
  153.  
  154.  
  155. } while(next_permutation(perm.begin(),perm.end(),lexco));
  156. }
Add Comment
Please, Sign In to add comment