!636 !standard functions !quicknew abstract class Predict { abstract String predict(List history); // it's passed in reverse } main { static class PLast extends Predict { String predict(List history) { return history.isEmpty() ? "" : history.get(0); } } psvm { // example line: 2015-08-12 05:29:10 - http://tinybrain.de:8080/tb/my-actions.php String src = loadSnippet("#2000518"); new List actions; for (String line : toLines(src)) { int i = line.indexOf(" - http:"); if (i >= 0) actions.add(line.substring(i+3).trim()); } //System.out.println(actions); new List predictors; predictors.add(new PLast); new Collector globalCollector; for (int splitPoint = 0; splitPoint < actions.size()-1; splitPoint++) { List history = actions.subList(splitPoint+1, actions.size()); String current = actions.get(splitPoint); //new Collector collector; for (Predict p : predictors) { String prediction = ""; try { prediction = p.predict(history); } catch (Throwable e) { // silent exception } int score = current.equals(prediction) ? 1 : 0; //collector.add(p, prediction, score, splitPoint); globalCollector.add(p, prediction, score, splitPoint); } } } static class Collector { new (Hash)Map scores; void add(Predict p, String prediction, int score, int splitPoint) { Integer score = scores.get(p); score = (score == null ? 0 : score) + score; scores.put(p, score); } } }