clear all freq = 0; total = 100000; for i = 1:total seating_arrangement = randperm(8); couple_count = 0; for j = 1:7 if (seating_arrangement(j+1) == 1 && seating_arrangement(j) == 2) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 2 && seating_arrangement(j) == 1) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 3 && seating_arrangement(j) == 4) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 4 && seating_arrangement(j) == 3) couple_count = couple_count + 1; continue; end %{ if (seating_arrangement(j+1) == 5 && seating_arrangement(j) == 6) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 6 && seating_arrangement(j) == 5) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 7 && seating_arrangement(j) == 8) couple_count = couple_count + 1; continue; end if (seating_arrangement(j+1) == 8 && seating_arrangement(j) == 7) couple_count = couple_count + 1; continue; end %} end if (couple_count >= 2) freq = freq + 1; end end prob = freq / total