Python implementation in pure Java
