Almost working AI: solution doesn't print last line