Computing H-Partitions in ASP and Datalog