need help with script

I need a script that is gonna assigned material id to a editpoly that as multisubobj
base on is geometry.
for example triangle id 1
sqare id 2
more then 4 edge id 3
less then 3 edges id 1