fork(1) download
  1. #include <algorithm>
  2. #include <array>
  3. #include <iostream>
  4. #include <numeric>
  5. #include <random>
  6. #include <vector>
  7.  
  8. constexpr std::size_t seq_len = 16;
  9. constexpr std::size_t num_balls = 52;
  10.  
  11. int main() // this is not generalized for an odd sequence length
  12. {
  13. auto generator = std::mt19937{ std::random_device{}() };
  14.  
  15. auto balls = std::array<int, num_balls>{};
  16. std::iota(balls.begin(), balls.end(), 1);
  17. std::shuffle(balls.begin(), balls.end(), generator);
  18.  
  19. auto sequence = std::vector<int>{ balls.begin(), balls.begin() + seq_len / 2 };
  20.  
  21. std::shuffle(balls.begin(), balls.begin() + seq_len/2, generator);
  22. sequence.insert(sequence.end(), balls.begin(), balls.begin() + seq_len/2);
  23.  
  24. for (auto ball : sequence)
  25. std::cout << ball << ' ';
  26. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
43 18 22 34 9 10 47 46 10 43 9 34 22 18 46 47