home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.magick      Meh.. another magic/spellcasting forum      90,437 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 90,212 of 90,437   
   Street to All   
   Memory Magick (1/3)   
   10 Jul 25 23:25:15   
   
   From: street@shellcrash.com   
      
   https://github.com/alt-magick/Mnemonica   
      
   Mnemonica   
      
   This program has three modes.   
      
   Run program.exe mnemonica.txt as an example. mnemonica.txt is the   
   Mnemonica card stack   
      
   You can devide the text file into sections with the # string. Right now   
   mnemonica.txt is devided into four sections. Instead of restarting the   
   program from the beginning, you can jump to one of those sections by   
   typing part or all of the section name   
      
   The next part of the program gives you the history of the stack as   
   hints. You still work through all 52 cards, but you can decide how many   
   of the cards before it to show, and of course reshuffle if you want.   
      
   There is also a more advanced exercise where you are given random   
   numbers between 1-52. You then try to match the number with a card in   
   the Mnemonica order.   
      
   Here is the source code. You might need to format it for Usenet:   
      
   #include    
   #include    
   #include    
   #include    
   #include    
   #include    
   #include    
   #include    
   #include    
      
   #ifdef _WIN32   
   #define CLEAR_COMMAND "cls"   
   #else   
   #define CLEAR_COMMAND "clear"   
   #endif   
      
   using namespace std;   
      
   void clearScreen() {   
       std::system(CLEAR_COMMAND);   
   }   
      
   bool checkForMenuOrQuit(const std::string& input) {   
       if (input == "menu") return true;   
       if (input == "quit") {   
           std::cout << "\033[37mExiting...\n";   
           exit(0);   
       }   
       return false;   
   }   
      
   std::string toLower(const std::string& str) {   
       std::string result = str;   
       std::transform(result.begin(), result.end(), result.begin(), ::tolower);   
       return result;   
   }   
      
   int findNearestSection(const vector& answers, int currentLine, const   
   string& searchTerm) {   
       int n = answers.size();   
       int bestLine = -1;   
       int bestDistance = n + 1;   
      
       string searchTermLower = toLower(searchTerm);   
      
       for (int i = 0; i < n; ++i) {   
           if (!answers[i].empty() && answers[i][0] == '#') {   
               string lineLower = toLower(answers[i]);   
               if (lineLower.find(searchTermLower) != string::npos) {   
                   int distance = abs(i - currentLine);   
                   if (distance < bestDistance) {   
                       bestDistance = distance;   
                       bestLine = i;   
                   }   
               }   
           }   
       }   
      
       return bestLine;   
   }   
      
   double similarityPercentage(const std::string& s1, const std::string& s2) {   
       const size_t len1 = s1.size();   
       const size_t len2 = s2.size();   
      
       std::vector> dp(len1 + 1, std::vector(len2 + 1));   
      
       for (size_t i = 0; i <= len1; ++i) dp[i][0] = i;   
       for (size_t j = 0; j <= len2; ++j) dp[0][j] = j;   
      
       for (size_t i = 1; i <= len1; ++i) {   
           for (size_t j = 1; j <= len2; ++j) {   
               dp[i][j] = std::min({   
                   dp[i - 1][j] + 1,   
                   dp[i][j - 1] + 1,   
                   dp[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1)   
                   });   
           }   
       }   
      
       int maxLen = std::max(len1, len2);   
       return 100.0 - (static_cast(dp[len1][len2]) / maxLen * 100.0);   
   }   
      
   bool runSimilarityQuiz(const std::string& answersFileName) {   
       ifstream answersFile(answersFileName);   
       if (!answersFile) {   
           cerr << "\033[37mError opening answers file.\n";   
           return false;   
       }   
      
       vector answers;   
       string line;   
       while (getline(answersFile, line)) {   
           answers.push_back(line);   
       }   
       answersFile.close();   
      
       vector questionIndices;   
       vector questionDisplayNumbers;   
       int displayLineNumber = 1;   
      
       for (int i = 0; i < answers.size(); ++i) {   
           if (answers[i].empty() || answers[i][0] == '#') continue;   
           questionIndices.push_back(i);   
           questionDisplayNumbers.push_back(displayLineNumber++);   
       }   
      
       if (questionIndices.empty()) {   
           cerr << "\033[37mNo valid questions found in the file.\n";   
           return false;   
       }   
      
       int questionNumber = 0;   
       int fileLineIndex = questionIndices[0];   
       int planetNumber = 0;   
      
       while (true) {   
           if (fileLineIndex >= answers.size() || questionNumber >=   
   questionIndices.size()) {   
               // User finished all questions   
               std::cout << "\033[37mYou remembered everything!\n";   
      
               std::cout << "\nJump to: \n\n> ";   
               std::string jumpInput;   
               std::getline(std::cin, jumpInput);   
               if (checkForMenuOrQuit(jumpInput)) return true;   
               if (jumpInput.empty()) {   
                   // Exit the quiz normally   
                   break;   
               }   
      
               int foundLine = findNearestSection(answers, 0, jumpInput);   
               if (foundLine != -1) {   
                   std::cout << "\n\033[36m" << answers[foundLine] <<   
   "\033[37m\n\n";   
                   for (int i = 0; i < questionIndices.size(); ++i) {   
                       if (questionIndices[i] >= foundLine) {   
                           questionNumber = i;   
                           fileLineIndex = questionIndices[i];   
                           break;   
                       }   
                   }   
                   planetNumber = 0;   
      
                   // Continue quiz from jump position   
                   continue;   
               }   
               else {   
                   std::cout << "\n\033[37mNo matching section found.\n\n";   
                   // Loop back to jump prompt   
                   continue;   
               }   
           }   
      
           if (!answers[fileLineIndex].empty() && answers[fileLineIndex][0] ==   
   '#') {   
               std::cout << "\n\033[36m" << answers[fileLineIndex] <<   
   "\033[37m\n\n";   
               fileLineIndex++;   
               continue;   
           }   
      
           if (fileLineIndex != questionIndices[questionNumber]) {   
               fileLineIndex++;   
               continue;   
           }   
      
           int displayLineIndex = questionDisplayNumbers[questionNumber];   
           if (planetNumber > 25) planetNumber = 0;   
      
           std::cout << "\033[37mLine " << displayLineIndex << "\n\n> ";   
           std::string userAnswer;   
           std::getline(std::cin, userAnswer);   
      
           if (checkForMenuOrQuit(userAnswer)) return true;   
      
           double similarity = similarityPercentage(userAnswer, ans   
   ers[fileLineIndex]);   
      
           if (similarity > 75) {   
               std::cout << "\n\033[32m" << answers[fileLineIndex] <<   
   "\n\nCorrect!\n\n\033[37m";   
               questionNumber++;   
               planetNumber++;   
               fileLineIndex++;   
           }   
           else {   
               std::cout << "\033[31m\nThe answer was: \n\n" << ans   
   ers[fileLineIndex] << "\n"   
                   << "\033[37m\nJump to: \n\n> ";   
               std::string searchTerm;   
               std::getline(std::cin, searchTerm);   
               std::cout << "\n";   
               if (checkForMenuOrQuit(searchTerm)) return true;   
      
               if (searchTerm.empty()) {   
                   questionNumber++;   
                   if (questionNumber < questionIndices.size())   
                       fileLineIndex = questionIndices[questionNumber];   
               }   
      
   [continued in next message]   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca