Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AE9B5417C362D8F0
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- #include <map>
- using namespace std;
- bool isl(char a)
- {
- return a >= 'A' && a <= 'F';
- }
- bool lexco(char a, char b)
- {
- if(isl(a) && !isl(b))
- {
- return true;
- }
- else if(!isl(a) && isl(b))
- {
- return false;
- }
- else {
- return a < b;
- }
- }
- // THIS CODE iterates from lowest lexicographical F to highest, starting from ABCDEF0123456789 all the way up.
- int main()
- {
- string chars = "ABCDEF0123456789";
- // We are making an array with the letters so that we can use the next_permutation method on it
- vector<char> perm;
- perm.push_back('A');
- perm.push_back('B');
- perm.push_back('C');
- perm.push_back('D');
- perm.push_back('E');
- perm.push_back('F');
- perm.push_back('0');
- perm.push_back('1');
- perm.push_back('2');
- perm.push_back('3');
- perm.push_back('4');
- perm.push_back('5');
- perm.push_back('6');
- perm.push_back('7');
- perm.push_back('8');
- perm.push_back('9');
- do
- {
- //This loop turns the array into a string, a push_back every character onto the string 'news'
- string news = "";
- for(int i=0;i<perm.size();++i)
- {
- news.push_back(perm[i]);
- }
- string S = "AE9B5417C362D8F0";
- string basic = "ABCDEF0123456789";
- string currF = news;
- //here I load the map so that it maps the function correctly
- // the string called 'basic' is the characters in order
- // this is supposed to represent ABCDEF0123456789 -> f
- map<char,char> currMap;
- for(int j=0;j<currF.size();++j)
- {
- currMap[basic[j]] = currF[j];
- }
- //Soon we will iterate 50 times to apply f in repetition
- // We set the initial F^k to S, it represents f^0 (function not yet applied)
- string currFk = S;
- bool goodF = true;
- // This variable F1 represents F^1, we just store it so we can print it at the end if it's the right answer
- string F1 = "";
- // Now we apply the first 50 times.
- for(int j=0;j<50;++j)
- {
- //This builds a string by mapping the currFk using the currMap we built
- string newS = "";
- for(int k=0;k<S.length();++k)
- {
- newS.push_back(currMap[currFk[k]]);
- }
- // Update currFK with the new one
- currFk = newS;
- // Check if it does not satisfy the 2nd condition, it should not equal S
- if(currFk == S)
- {
- // If it does, we flag 'goodF' to false, so we can just skip it once this block of code ends.
- goodF = false;
- break;
- }
- // We note down F1 if j happens to be in the first iteration, since we'll need it later
- if(j == 0)
- {
- F1 = currFk;
- }
- }
- // So if this is a 'goodF' (meaning that it satisfies the 2nd condition)
- if(goodF)
- {
- // 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])
- int sz = 10000;
- // currR1 is originally S, this represents F^0 (no function applied)
- string currR1 = S;
- for(int j=0;j<sz;++j)
- {
- // Apply the function, and place it in variable 'newS'
- string newS = "";
- for(int k=0;k<S.length();++k)
- {
- newS.push_back(currMap[currR1[k]]);
- }
- // Update currR1 with the new string with the function applied.
- currR1 = newS;
- // If J > 50, we want to see if we should be checking the first condition yet, or not
- if(j>=50)
- {
- // If we find a k such that currR1 == S , then we have found a solution
- if(currR1 == S)
- {
- cout << "F is " << currF << " -> F(S) = " << F1 << " / found at F^" << j+1 << endl;
- //We only need the first one since we are iterating from lowest lexicographical F to higher, so we return now.
- return 0;
- }
- }
- }
- }
- }
- while(next_permutation(perm.begin(),perm.end(),lexco));
- }
Add Comment
Please, Sign In to add comment