solved ex2.pas but that's not the best solution I can came up with