John, I came to 12 as the correct answer. 24 is indeed the number of permutations. But there are more then 6 positions where SJ stand next to eachother. You counted these: SJPM, PSJM, PMSJ, JSPM, PJSM, PMJS but you should also include these positions: SJMP, MSJP, MPSJ, JSMP, MJSP, MPJS

Incorrect John. The actual answer can be solved through the formula I just derived. n! - ((n + 1 - m) (n-m)! M!) = x. In this situation, n is the size of the group m is the size of the two who cannot stand next to each other and x is the number of situations that they form a line in which they are not next to each other. In the beginning of the equation n! Stands for the total number of situations a group can form a line. From that you subtract the number of times that they stand next to each other in said line. In this section (n + 1 - m) accounts for how many ways within the group 2 people can line up. (Ex: AB is the group that cannot stand by each other so ABCD CABD CDAB.) Now to account for how many times the group can align with them as a group of 1 you use (n - m)! Because this essentially pairs them as one and accounts for the alignment of the other people in the situation. Finally to account for how the two may align amongst themselves when standing next to each you may use m!. So the number of times in which they would stand next to each otherwould be 12 of the 24 total possible choices in this situation. There may be a way to simplify this answer, but I did not look into that aspect.

The strategy here is to count:
Number of ways = Total number of ways that PMSJ can stand together - Number of ways that SJ stand next to eachother
The total number of ways that PMSJ can stand next to each other is equal to 4! = 4321 = 24.
The number of ways that SJ will end up standing next to eachother is 6: (SJPM, PSJM, PMSJ, JSPM, PJSM, PMJS)
So, 24 - 6 = 18 ways.

Incorrect John. The actual answer can be solved through the formula I just derived. n! - ((n + 1 - m) (n-m)! M!) = x. In this situation, n is the size of the group m is the size of the two who cannot stand next to each other and x is the number of situations that they form a line in which they are not next to each other. In the beginning of the equation n! Stands for the total number of situations a group can form a line. From that you subtract the number of times that they stand next to each other in said line. In this section (n + 1 - m) accounts for how many ways within the group 2 people can line up. (Ex: AB is the group that cannot stand by each other so ABCD CABD CDAB.) Now to account for how many times the group can align with them as a group of 1 you use (n - m)! Because this essentially pairs them as one and accounts for the alignment of the other people in the situation. Finally to account for how the two may align amongst themselves when standing next to each you may use m!. So the number of times in which they would stand next to each otherwould be 12 of the 24 total possible choices in this situation. There may be a way to simplify this answer, but I did not look into that aspect.