Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Couples Seated in a Row

By: a guest on Jun 5th, 2011  |  syntax: MatLab  |  size: 1.50 KB  |  views: 41  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. clear all
2.
3. freq = 0;
4. total = 100000;
5. for i = 1:total
6.     seating_arrangement = randperm(8);
7.     couple_count = 0;
8.     for j = 1:7
9.         if (seating_arrangement(j+1) == 1 && seating_arrangement(j) == 2)
10.             couple_count = couple_count + 1;
11.             continue;
12.         end
13.         if (seating_arrangement(j+1) == 2 && seating_arrangement(j) == 1)
14.             couple_count = couple_count + 1;
15.             continue;
16.         end
17.
18.         if (seating_arrangement(j+1) == 3 && seating_arrangement(j) == 4)
19.             couple_count = couple_count + 1;
20.             continue;
21.         end
22.         if (seating_arrangement(j+1) == 4 && seating_arrangement(j) == 3)
23.             couple_count = couple_count + 1;
24.             continue;
25.         end
26.         %{
27.         if (seating_arrangement(j+1) == 5 && seating_arrangement(j) == 6)
28.             couple_count = couple_count + 1;
29.             continue;
30.         end
31.         if (seating_arrangement(j+1) == 6 && seating_arrangement(j) == 5)
32.             couple_count = couple_count + 1;
33.             continue;
34.         end
35.         if (seating_arrangement(j+1) == 7 && seating_arrangement(j) == 8)
36.             couple_count = couple_count + 1;
37.             continue;
38.         end
39.         if (seating_arrangement(j+1) == 8 && seating_arrangement(j) == 7)
40.             couple_count = couple_count + 1;
41.             continue;
42.         end
43.         %}
44.     end
45.     if (couple_count >= 2)
46.         freq = freq + 1;
47.     end
48. end
49. prob = freq / total
clone this paste RAW Paste Data
Top