Alex traveled at 20 miles per hour for 4.5 hours, so 20 * 4.5 = <<20*4.5=90>>90 miles on flat ground.
He traveled 12 miles per hour uphill for 2.5 hours, so 12 * 2.5 = <<12*2.5=30>>30 miles uphill.
He traveled downhill 24 miles per hour for 1.5 hours = 24 * 1.5 = <<24*1.5=36>>36 miles downhill.
Before his tire punctured, he traveled 90 + 30 + 36 = <<90+30+36=156>>156 miles.
So as the next town is 164 miles from where he began, Alex had to walk for 164 - 156 = <<164-156=8>>8 miles.
#### 8