Guest User

Untitled

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