Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstddef>
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6. #include <cmath>
  7.  
  8. typedef std::vector<int> seq;
  9. void Print(std::vector<seq> v);
  10.  
  11. void CreateEmptyList(int n, int length, std::vector<seq>& list){
  12. seq zero_sequence;
  13. for(int i=0; i < length; i++){
  14. zero_sequence.push_back(0);
  15. }
  16. int total = std::pow(n, length);
  17. for(int i=0; i < total; i++){
  18. list.push_back(zero_sequence);
  19. }
  20. }
  21.  
  22. void CreateList(int n, int length, std::vector<seq>& list){
  23. CreateEmptyList(n, length, list);
  24. int total = std::pow(n, length);
  25. for(int i = 1; i < list.size(); i++){
  26. list[i][length-1] = list[i-1][length-1]+1; //the next in the list = prevoius one + 1 (increment)
  27. for(int j = 0; j < length-1; j++){ // copy other number from the previous
  28. list[i][j] = list[i-1][j];
  29. }
  30. for(int j = length-1; j >= 0 ; j--){ // check backwards
  31. if(list[i][j] >= n){ //if the digit exceeds n
  32. list[i][j-1] = list[i][j-1]+1; //carry over
  33. list[i][j] = 0; // reset the last to zero
  34. }
  35. }
  36. }
  37. }
  38.  
  39. // void GetParts(std::vector<int> possible; std::vector<int>& attempt, int length, int n){
  40. // int part = 0;
  41. // std::vector<bool> result;
  42. // int black, white;
  43. // int hash;
  44. // result.assign(std::pow(n, length), 0);
  45. // for(int i=0; i < list.size(); i++){
  46. // give_feedback2(guess, possible, black, white);
  47. // hash = black*(num)+white;
  48. // if(result[hash] == false){
  49. // result[hash] = true;
  50. // part++;
  51. // }
  52. // return part;
  53. // }
  54. // }
  55.  
  56. void Print(std::vector<seq> v){
  57. std::cout << "Print start: " << '\n';
  58. for (int j = 0; j < v.size(); j++){
  59. for(int i = 0; i < v[1].size(); i++){
  60. std::cout << v[j][i];
  61. }
  62. std::cout << '\n';
  63. }
  64. }
  65.  
  66. int main(){
  67. int length, n;
  68. std::cout << "Please enter length and n" << '\n';
  69. std::cin >> length >> n;
  70. std::vector<seq> list, list1;
  71. CreateList(n , length, list); // insert your function here
  72. Print(list);
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement