No repeats please - Formula


I’m sorry for this but i can’t figure out with the formula to calculate permutation, as i can find which case is.
Can someone explain this in order to think to a method for coding?

Never had permutations in math?

yes, but i was trying to solve some cases in order to find if my thought was right.
For example in the set [aabb] i solved with result 6 , instead in the program if i run to test the result it return 8. I can’t understand why…

because every letter is unique so you have for aabb:

a1 b1 a2 b2
a1 b2 a2 b1
a2 b1 a1 b2
a2 b2 a1 b1
b1 a1 b2 a2
b1 a2 b2 a1
b2 a1 b1 a2
b2 a2 b1 a1

Yes, i can do it by hand but which formula? permutation with repetition or without. Because i can retrieve this result with any of the formula.