K version of algorithmn | ScratchStats