Advertisement
FubFubFub

Day 4

Dec 4th, 2022
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.58 KB | Source Code | 0 0
  1. % The pair assignments
  2. elf_pair(2,4,6,8).
  3. elf_pair(2,3,4,5).
  4. elf_pair(5,7,7,9).
  5. elf_pair(2,8,3,7).
  6. elf_pair(6,6,4,6).
  7. elf_pair(2,6,4,8).
  8.  
  9. % If the start section of an elf is equal or higher than the start section of the other elf, and the end section of that elf is equal or lower than the end section of the other elf, then we have a complete overlap.
  10. complete_overlap(A, B, C, D) :- A >= C, B =< D.
  11. complete_overlap(A, B, C, D) :- C >= A, D =< B.
  12.  
  13. % Solve the puzzle
  14. solve(Count) :- findall(A, (elf_pair(A, B, C, D), complete_overlap(A, B, C, D)), Overlaps), length(Overlaps, Count).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement