fs = require('fs');

function frequencies(data,k){

  freq = {};

  for(var i = 0; i < data.length-k; i++){
    
    curr = data.substring(i, i+k);
    
    if(freq[curr] > 0){
      freq[curr] = freq[curr] + 1;
    }
    else{
      freq[curr] = 1;
    }      
  }

  return freq;
}

function runClumps(k, L, t, data) {

  clumps = [];

  for(i = 0; i < (data.length-L); i++) {

    windowedData = data.substring(i, i+L);
    freq = frequencies(windowedData, k);

    for(var x in freq) {

      // correct t number, and unique
      if(freq[x] == t && clumps.indexOf(x) == -1) {
        clumps.push(x);
      }
    }
  }
  
  return clumps;  
}

function processFile(err, file) {

  lines = file.toString().split("\n");
  params = lines[1].split(" ");

  data = lines[0].toString();

  k = parseInt(params[0]),
  L = parseInt(params[1]),
  t = parseInt(params[2]);

  matches = runClumps(k, L, t, data);
  console.log(matches.join(" "));  
}

file = process.argv[2];
fs.readFile(file, processFile);
@@ -321,21 +321,218 @@
 %0A%0A  
-clumps = %5B%5D;%0A
+winners = %5B%5D;%0A%0A  // seeded with the 0th...%0A  potentials = frequencies(data.substring(0, L), k);%0A%0A  for(var x in potentials) %7B%0A    if(freq%5Bx%5D %3E= t) %7B%0A      winners.push(x);%0A    %7D%0A  %7D%0A%0A  // starts on the 1st move
 %0A  f
@@ -534,25 +534,25 @@
 e%0A  for(i = 
-0
+1
 ; i %3C (data.
@@ -574,28 +574,51 @@
  %7B%0A%0A    
-windowedData
+//decrement the lost value%0A    drop
  = data.
@@ -632,152 +632,331 @@
 ng(i
+-1
 , i+
-L
+k-1
 );%0A    
-freq = frequencies(windowedData, k);%0A%0A    for(var x in freq) %7B%0A%0A      // correct t number, and unique%0A      if(freq%5Bx%5D =
+potentials%5Bdrop%5D--;%0A    if(potentials%5Bdrop%5D %3C 1) %7B%0A      delete potentials%5Bdrop%5D;%0A    %7D%0A%0A    //increment the new value%0A    add = data.substring(L+i-k, L+i);%0A    %0A    if(potentials%5Badd%5D == null)%7B%0A      potentials%5Badd%5D = 1;%0A    %7D    %0A    else %7B%0A      potentials%5Badd%5D++;%0A      if(potentials%5Badd%5D %3E
 = t && 
-clump
+winner
 s.in
@@ -961,17 +961,19 @@
 indexOf(
-x
+add
 ) == -1)
@@ -987,21 +987,24 @@
     
-clump
+winner
 s.push(
-x
+add
 );%0A 
@@ -1036,13 +1036,14 @@
 urn 
-clump
+winner
 s;  

make the algo 'dynamic programming'/online