Scala version of pa1 - q1, q2 for algo2-003.