Skip to content

Instantly share code, notes, and snippets.

@MuffinTheMan
Last active December 30, 2015 09:08
Show Gist options
  • Save MuffinTheMan/7806903 to your computer and use it in GitHub Desktop.
Save MuffinTheMan/7806903 to your computer and use it in GitHub Desktop.
Prolog predicate to get an element from a 2-dimensional list at some (Row, Column).
% Get an element from a 2-dimensional list at (Row,Column)
% using 0-based indexing.
nth0_2(Row, Column, List, Element) :-
nth0(Row, List, SubList),
nth0(Column, SubList, Element).
% Example use:
%
% ?- nth0_2(2, 1, [[1,0], [2,9], [3,4]], El).
% El = 4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment