Solved problem 106. Doesn't run that quickly but is also implemented without bit masks :S