import 'dart:math'; class PseudoRandom { int a; int c; int m = 1 << 32; int s; int i; PseudoRandom([int prod = 1664525, int add = 1013904223]) { a = prod; c = add; s = Random().nextInt(m) * 2 + 1;//odd next();// a fast round i = a.modInverse(m);//4276115653 as inverse of 1664525 } int next() { return s = (a * s + c) % m; } int prev() { return s = (s - c) * i % m; } } class RingNick { List<double> walls = [ 0.25, 0.5, 0.75 ]; int position = 0; int mostEscaped = 1;//the lowest pair of walls 0.25 and 0.5 int leastEscaped = 2;//the highest walls 0.5 and 0.75 int theThird = 0;//the 0.75 and 0.25 walls bool right = true; PseudoRandom pr = PseudoRandom(); int _getPosition() => position; int _asMod(int pos) { return pos % walls.length; } void _setPosition(int pos) { position = _asMod(pos); } void _next() { int direction = right ? 0 : walls.length - 1;//truncate to 2 double wall = walls[_asMod(_getPosition() + direction)]; if(pr.next() > (wall * pr.m).toInt()) { //jumped _setPosition(position + (right ? 1 : walls.length - 1)); } else { //not jumped right = !right;//bounce } } void _prev() { int direction = !right ? 0 : walls.length - 1;//truncate to 2 double wall = walls[_asMod(_getPosition() + direction)]; if(pr.s > (wall * pr.m).toInt()) {// the jump over before sync //jumped _setPosition(position + (!right ? 1 : walls.length - 1)); } else { //not jumped right = !right;//bounce -- double bounce and scale before sync } pr.prev();//exact inverse } void next() { _next(); while(_getPosition() == mostEscaped) _next(); } void prev() { _prev(); while(_getPosition() == mostEscaped) _prev(); } } class GroupHandler { List<RingNick> rn; GroupHandler(int size) { if(size % 2 == 0) size++; rn = List<RingNick>(size); } void next() { for(RingNick r in rn) r.next(); } void prev() { for(RingNick r in rn.reversed) r.prev(); } bool majority() { int count = 0; for(RingNick r in rn) if(r._getPosition() == r.leastEscaped) count++;//a main cumulative return (2 * count > rn.length);// the > 2/3rd state is true } void modulate() { for(RingNick r in rn) if(r._getPosition() == r.leastEscaped) { r._setPosition(r.theThird); } else { //mostEscaped eliminated by not being used r._setPosition(r.leastEscaped); } } } class Modulator { GroupHandler gh = GroupHandler(55); int putBit(bool bitToAbsorb) {//returns absorption status gh.next(); if(gh.majority()) {//main zero state if(bitToAbsorb) { gh.modulate(); return 0;//a zero yet to absorb } else { return 1;//absorbed zero } } else { return -1;//no absorption emitted 1 } } int getBit(bool bitLastEmitted) { if(gh.majority()) {//zero gh.prev(); return 1;//last bit not needed emit zero } else { if(bitLastEmitted) { gh.prev(); return -1;//last bit needed and nothing to emit } else { gh.modulate(); gh.prev(); return 0;//last bit needed, emit 1 } } } } class StackHandler { List<bool> data = []; Modulator m = Modulator(); int putBits() { int count = 0; while(data.length > 0) { bool v = data.removeLast(); switch(m.putBit(v)) { case -1: data.add(v); data.add(true); break; case 0: data.add(false); break; case 1: break;//absorbed zero default: break; } count++; } return count; } void getBits(int count) { while(count > 0) { bool v; v = (data.length == 0 ? false : data.removeLast());//zeros out switch(m.getBit(v)) { case 1: data.add(v);//not needed data.add(false);//emitted zero break; case 0: data.add(true);//emitted 1 used zero break; case -1: break;//bad skip, ... default: break; } count--; } } }
Tag: Kodek
Statistics and Damn Lies
I was wondering over the statistics problem I call the ABC problem. Say you have 3 walls in a circular path, of different heights, and between them are points marked A, B and C. If in any ‘turn’ the ‘climber’ attempts to scale the wall in the current clockwise or anti-clockwise direction. The chances of success are proportional to the wall height. If the climber fails to get over a wall, they reverse direction. A simple thing, but what are the chances of the climber will be found facing clockwise just before scaling or not a wall? Is it close to 0.5 as the problem is not symmetric?
More interestingly the climber will be in a very real sense captured more often in the cell with the highest pair of walls. If the cell with the lowest pair of walls is just considered as consumption of time, then what is the ratio of the containment time over the total time not in the least inescapable wall cell?
So the binomial distribution of the elimination of the ’emptiest’ when repeating this pattern as an array with co-prime ‘dice’ (if all occupancy has to be in either of the most secure cells in each ‘ring nick’), the rate depends on the number of ring nicks. The considered security majority state is the state (selected from the two most secure cell states) which more of the ring nicks are in, given none are in the least secure state of the three states.
For the ring nick array to be majority most secure more than two thirds the time is another binomial or two away. If there are more than two-thirds of the time (excluding gaping minimal occupancy cells) the most secure state majority and less than two-thirds (by unitary summation) of the middle-security cells in majority, there exists a Jaxon Modulation coding to place data on the Prisoners by reversing all their directions at once where necessary, to invert the majority into a minority rarer state with more Shannon information. Note that the pseudo-random dice and other quantifying information remains constant in bits.
Dedicated to Kurt Godel … I am number 6. 😀