From 3caa298fc0f881aeaab514c835ff20a2201bc329 Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Wed, 27 Feb 2013 14:41:01 +0100 Subject: add cycle statistics function diff --git a/cacount.cpp b/cacount.cpp index 7c052d3..3b385ab 100644 --- a/cacount.cpp +++ b/cacount.cpp @@ -1,10 +1,13 @@ -#include #include +#include +#include + #include #include #include #include -#include +#include + using namespace std; @@ -26,14 +29,17 @@ State update(State s) { typedef array Trans; +void iterState(function f) { + for (State s=0; s f) { while (times--) - for (State s=0; s cyc; + // how big is the basin of attraction? + iterState([&](int s) { cyc[c[s]].basin++; }); + // how long is the cycle, what is the actual minimal state + for (auto i : cyc) { + Stat &s = cyc[i.first]; + State cur, start; + cur = start = c[i.first]; + do { + s.len++; + s.minState = min(s.minState, cur); + cur=update(cur); + } while (cur != start); + } + // print it + for (auto i : cyc) { + Stat &s = i.second; + cout << s.minState << "\t" + << bitset(s.minState) << "\t" + << s.len << "\t" + << s.basin << endl; + } +} + void print(Trans &t) { for (auto s : t) cout << bitset(s) << endl; @@ -75,7 +110,7 @@ int main(int argc, char **argv) { Trans &t = *(new Trans); init(t); Trans &c(*findCycle(t)); - print(c); + cycleStat(c); } return 0; } -- cgit v0.10.1