Update Beast.java

Updated with a much simpler algorithm.