WIP add main algorithm in java

clojure is too hard.