Hearts cut the gap between themselves and Scottish Premiership leaders Celtic to three points with victory over Hamilton Academical.