Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. array2<int> rooms;
  2.  
  3. # Each room is represented by the maximum number of people that it can seat
  4. rooms = [2, 3, 4, 5];
  5.  
  6.  
  7. # People are represented by a list of indexes of the rooms where they sit (ten people in this case)
  8. array10<int> people;
  9.  
  10. function respectCapacity? (people, roomNumber, capacity) {
  11. # Make sure each room does not have more peopl in it than its capacity
  12. uses = people.countBy(function^ (allocatedRoom) {
  13. return allocatedRoom == roomNumber;
  14. });
  15.  
  16. return uses <= capacity;
  17. };
  18.  
  19. function wishes? (people) {
  20. # People who want to be in the same room together
  21.  
  22. firstWish = people[1] == people[2];
  23. secondWish = (people[6] == people[7]) && (people[7] == people[8]);
  24. thirdWish = people[0] == people[4];
  25.  
  26. return firstWish && secondWish && thirdWish;
  27. };
  28.  
  29. people.each(function^ (roomIndex, personNumber) {
  30. invariant roomIndex.between?(0, rooms.count);
  31. invariant people.wishes?;
  32.  
  33. invariant people.respectCapacity?(roomIndex, rooms[roomIndex]);
  34. });
  35.  
  36. expose people;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement