Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cstddef>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cmath>
- typedef std::vector<int> seq;
- void Print(std::vector<seq> v);
- void CreateEmptyList(int n, int length, std::vector<seq>& list){
- seq zero_sequence;
- for(int i=0; i < length; i++){
- zero_sequence.push_back(0);
- }
- int total = std::pow(n, length);
- for(int i=0; i < total; i++){
- list.push_back(zero_sequence);
- }
- }
- void CreateList(int n, int length, std::vector<seq>& list){
- CreateEmptyList(n, length, list);
- int total = std::pow(n, length);
- for(int i = 1; i < list.size(); i++){
- list[i][length-1] = list[i-1][length-1]+1; //the next in the list = prevoius one + 1 (increment)
- for(int j = 0; j < length-1; j++){ // copy other number from the previous
- list[i][j] = list[i-1][j];
- }
- for(int j = length-1; j >= 0 ; j--){ // check backwards
- if(list[i][j] >= n){ //if the digit exceeds n
- list[i][j-1] = list[i][j-1]+1; //carry over
- list[i][j] = 0; // reset the last to zero
- }
- }
- }
- }
- // void GetParts(std::vector<int> possible; std::vector<int>& attempt, int length, int n){
- // int part = 0;
- // std::vector<bool> result;
- // int black, white;
- // int hash;
- // result.assign(std::pow(n, length), 0);
- // for(int i=0; i < list.size(); i++){
- // give_feedback2(guess, possible, black, white);
- // hash = black*(num)+white;
- // if(result[hash] == false){
- // result[hash] = true;
- // part++;
- // }
- // return part;
- // }
- // }
- void Print(std::vector<seq> v){
- std::cout << "Print start: " << '\n';
- for (int j = 0; j < v.size(); j++){
- for(int i = 0; i < v[1].size(); i++){
- std::cout << v[j][i];
- }
- std::cout << '\n';
- }
- }
- int main(){
- int length, n;
- std::cout << "Please enter length and n" << '\n';
- std::cin >> length >> n;
- std::vector<seq> list, list1;
- CreateList(n , length, list); // insert your function here
- Print(list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement