Split a list in half

后端 未结 7 1379
滥情空心
滥情空心 2020-12-19 03:25

I need to define divide so that List [1,2,3,4,5] divides into:

a = [1,2,3}

b = [4,5]

I\'m getting an error that says \"

相关标签:
7条回答
  • 2020-12-19 04:19

    Surely the effect of this code (lengthIs(L2, M) < lengthIs(L1,N)/2 -> ...) isn't what you expect: it doesn't compare numbers, but terms. You should write it this way:

    lengthIs(L2, M), lengthIs(L1, N), M < N/2 -> ...
    

    Another typo like mistake: the first clause of lengthIs/2 should read

    lengthIs([],0).
    
    0 讨论(0)
提交回复
热议问题