给定一个列表,例如[1,2,3,7,2,5,8,9,3,4]我如何提取列表中的序列?
序列被定义为有序列表(通常我会说 n 元组,但在序言中我被告知元组被称为序列)。因此,我们希望在下一个元素小于前一个元素的位置处剪切列表。
因此对于列表[1,2,3,7,2,5,8,9,3,4]它应该返回:
[ [1,2,3,7], [2,5,8,9], [3,4] ] %ie we have cut the list at position 4 & 8.
对于本练习,您不能使用构造;或->
提前谢谢了!
结果示例:
例如1。
?-function([1,2,3,7,2,5,8,9,3,4],X): %so we cut the list at position 4 & 9
Run Code Online (Sandbox Code Playgroud)
X = [ [1,2,3,7], [2,5,8,9], [3,4] ]。
例如2。
?-function([1,2,3,2,2,3,4,3],X): %so we cut the list at position 3,4 & 8
X = [ [1,2,3], [2], [2,3,4], [3] ].
Run Code Online (Sandbox Code Playgroud)
希望这有助于澄清问题。如果您需要进一步说明,请告诉我!再次感谢您能够提供的任何帮助。
prolog ×1