Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. same_Diagonal([[0,11,54,45],[16,1,6,9],[35,7,1,5],[27,3,9,1]])[0,11,54,45]
  2. [16,1,6,9]
  3. [35,7,1,5]
  4. [27,3,9,1]
  5.  
  6. [1,6,9]
  7. [7,1,5]
  8. [3,9,1]
  9.  
  10. [1,5]
  11. [9,1]
  12.  
  13. withoutHead([[0,11,54,45],[16,1,6,9],[35,7,1,5],[27,3,9,1]],X).
  14.  
  15. X = [[1, 6, 9], [7, 1, 5], [3, 9, 1]].
  16.  
  17. % withoutHead(+ ListOfList, -ListOfList)
  18. % parameter1: the ListOfList is input
  19. % parameter2: the ListOfList process output
  20. withoutHead([HeadRow|TailRow],Squares):-
  21. maplist(removeHead,TailRow,Squares).
  22.  
  23. % removeHead(+List, -List)
  24. % parameter1: the List is each row
  25. % parameter2: the List is tail of each row
  26. removeHead([Head|Tail], Tail).
  27.  
  28.  
  29. same_Diagonal([HeadRow|TailRow]):-
  30. withoutHead([HeadRow|TailRow],[[Diagonal|Tail]|Back]),
  31. same_Diagonal(Back).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement