Formula Fields are excellent for running code at run-time.
However whatever is calculated in a formula field it will never get to the Database so a formula field will not be available for usage in Reports.
Also basing you trigger conditions on formula fields can create inconsistency in the execution of those triggers, because of the very nature of the formula field.
Also a good Idea to use in formula fields is to have a return.
Here is how a sample of groovy code can look in a formula field.
def x = 1
def z = 2
return x + z
output of this would be