Guest User

day10 puzzle

a guest
Dec 10th, 2015
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include "boost/scoped_array.hpp"
  3. #include "boost/scoped_ptr.hpp"
  4. #include "boost/shared_ptr.hpp"
  5. #include "boost/weak_ptr.hpp"
  6. #include "boost/make_shared.hpp"
  7. #include "boost/smart_ptr/enable_shared_from_this.hpp"
  8. #include "boost/lexical_cast.hpp"
  9. #include "boost/optional.hpp"
  10. #include "boost/none.hpp"
  11. #include <map>
  12. #include <algorithm>
  13. #include <vector>
  14. #include <sstream>
  15. #include <iomanip>
  16. #include <string>
  17. #include <list>
  18. #include <bitset>
  19. #include <thread>
  20. #include <utility>
  21. #include <initializer_list>
  22. #include <memory>
  23. #include <netinet/in.h>
  24. #include <functional>
  25. #include <chrono>
  26. #include <cstring>
  27. #include <ctime>
  28. #include <set>
  29. #include <memory>
  30. #include <iostream>
  31. #include <atomic>
  32. #include <thread>
  33. #include <mutex>
  34.  
  35. #include <iostream>
  36. #include <chrono>
  37. #include <thread>
  38. #include <chrono>
  39. #include <map>
  40. #include <tuple>
  41. #include <utility>
  42. #include <set>
  43. #include <initializer_list>
  44. #include <algorithm>
  45. #include <vector>
  46. #include <string>
  47. #include <chrono>
  48.  
  49. using namespace std;
  50.  
  51. std::string evaulateString(std::string str)
  52. {
  53.     std::string evaulatedStr;
  54.     for (auto i = size_t{0}; i < str.size();)
  55.     {
  56.         auto currentChar = str.at(i);
  57.         auto currentCounter = int {0};
  58.         while (str.at(i) == currentChar)
  59.         {
  60.             ++currentCounter;
  61.             ++i;
  62.             if (i == (str.size()))
  63.             {
  64.                 break;
  65.             }
  66.         }
  67.         if (currentCounter)
  68.         {
  69.             evaulatedStr += static_cast<char>(currentCounter+48);
  70.         }
  71.         evaulatedStr += currentChar;
  72.     }
  73.     return evaulatedStr;
  74. }
  75.  
  76. int elvesLookElvesSay(std::string str, int iteration = 0)
  77. {
  78.     if (iteration == 40)
  79.     {
  80.         return str.size();
  81.     }
  82.     else
  83.     {
  84.         return elvesLookElvesSay(std::move(evaulateString(str)), ++iteration);
  85.     }
  86. }
  87.  
  88.  
  89. int main()
  90. {
  91.     for (auto i = 0; i < 100; ++i)
  92.     {
  93.         std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
  94.         auto res = elvesLookElvesSay("1321131112");
  95.         std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
  96.         cout << res << " and it took: " << " (" << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms)" << std::endl;
  97.     }
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment