Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

bjorklund

By: a guest on Mar 19th, 2011  |  syntax: Smalltalk  |  size: 0.53 KB  |  views: 202  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (
  2.  ~bjorklund = {
  3.     arg steps,numBeats;
  4.     var beat = Array(steps);
  5.     var remainder = steps-numBeats;
  6.     var remaindersToPop = numBeats;
  7.  
  8.     //initialize array
  9.     steps.do{|i| if (i < numBeats) { beat.add([1]); } {beat.add([0]); }};
  10.  
  11.     //transform the array
  12.     while ({ remainder > 0 } , {
  13.         remaindersToPop = min(remaindersToPop,remainder);
  14.         remaindersToPop.do { |i| beat[i] = [beat[i],beat.pop].flatten; };
  15.         remainder = beat.size - remaindersToPop;
  16.     });
  17.  
  18.     beat.flatten;
  19.  
  20.  };
  21.  
  22. )