27namespace swift::sample
32 for (
int i = 1; i <= 100; ++i)
39 for (
int i = 0; i <
samples; ++i)
42 means.
push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
45 int stdDev = std::sqrt(std::accumulate(means.
cbegin(), means.
cend(), 0,
46 [&](
int a,
int n) { return a + (n - mean) * (n - mean); }) /
48 qDebug() <<
"randomElements";
49 qDebug() <<
"means:" << means;
50 qDebug() <<
"mean of the means:" << mean;
51 qDebug() <<
"std deviation of the means:" << stdDev;
55 for (
int i = 0; i <
samples; ++i)
58 means.
push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
61 int stdDev = std::sqrt(std::accumulate(means.
cbegin(), means.
cend(), 0,
62 [&](
int a,
int n) { return a + (n - mean) * (n - mean); }) /
64 qDebug() <<
"sampleElements";
65 qDebug() <<
"means:" << means;
66 qDebug() <<
"mean of the means:" << mean;
67 qDebug() <<
"std deviation of the means:" << stdDev;
70 QStringList src {
"a1",
"a2",
"a3",
"b1",
"b2",
"b3",
"c1",
"c2",
"c3" };
71 std::shuffle(src.
begin(), src.
end(), std::mt19937(
static_cast<unsigned>(std::time(
nullptr))));
73 qDebug() <<
"topologicallySortedInsert";
78 return a[0] == b[0] && a[1] < b[1];
80 for (
const auto &s : src)
84 qDebug() << count <<
"comparisons";
86 qDebug() <<
"topologicalSort";
89 qDebug() << count <<
"comparisons";
Derived sampleElements(int n) const
Copy n elements from the container, randomly selected but evenly distributed.
Derived randomElements(int n) const
Copy n elements from the container at random.
Generic sequential container with value semantics.
void push_back(const T &value)
Appends an element at the end of the sequence.
const_iterator cbegin() const
Returns const iterator at the beginning of the sequence.
void clear()
Removes all elements in the sequence.
const_iterator cend() const
Returns const iterator one past the end of the sequence.
static int samples()
Run the samples.
void topologicalSort(I begin, I end, F comparator)
Topological sorting algorithm.
void topologicallySortedInsert(C &container, T &&value, F comparator)
Insert an element into a sequential container while preserving the topological ordering of the contai...
QList< T >::iterator begin()
QList< T >::iterator end()