package ru.lj.alamar.microbe;

import java.util.Collections;
import java.util.Random;

import ru.yandex.bolts.collection.Cf;
import ru.yandex.bolts.collection.ListF;

public class ChromosomeSelection {
    public static float taint = 0;
    public static float alive = 0;
    public static float total = 0;
    public static void main(String[] args) {
        Random r = new XorShiftRandom(12345);
        for (int i = 2; i < args.length; i++) {
            simulate(r, args[i], Integer.parseInt(args[1]), Integer.parseInt(args[0]));
        }
        System.err.println("total: " + (int)total + ", alive: " + (alive / total) + ", tainted: " + (taint / alive));
    }

    private static void simulate(Random r, String g, int steps, int generations) {
        --generations;
        for (int i = 0; i < steps; i++) {
            total++;
            ListF<String> doubled = Cf.arrayList(Cf.list((g + g).split("")));
            Collections.shuffle(doubled, r);
            String result = Cf.list(doubled.mkString("").substring(0, g.length()).split("")).sort().mkString("");
            if (result.indexOf('A') < 0) continue;
            if (result.indexOf('B') < 0) continue;
            System.out.println(result);
            if (generations > 0) simulate(r, result, steps / 2, generations);
            alive++;
            if (result.indexOf('-') >= 0) taint++;
        }
    }
}

@@ -220,20 +220,20 @@
  float t
-aint
+otal
  = 0;%0A  
@@ -286,34 +286,70 @@
 atic float t
-otal
+aint = 0;%0A    public static float alter
  = 0;%0A
+%0A
     public s
@@ -654,16 +654,32 @@
 / total)
+%0A               
  + %22, ta
@@ -697,16 +697,50 @@
 (taint /
+ alive) + %22, altered: %22 + (alter /
  alive))
@@ -1187,24 +1187,51 @@
 dexOf('A') %3C
+ 0 && result.indexOf('a') %3C
  0) continue
@@ -1418,24 +1418,24 @@
    alive++;%0A
-
             
@@ -1469,24 +1469,75 @@
 0) taint++;%0A
+            if (result.indexOf('a') %3E= 0) alter++;%0A
         %7D%0A  

Support neutral mutation for null hypothesis.