Programmatically creating multivariate functions in Mathematica

前端 未结 3 1843
别那么骄傲
别那么骄傲 2021-01-24 10:29

This is a split from discussion on earlier question.

Suppose I need to define a function f which checks if given labeling of a graph is a proper coloring. In other words

3条回答
  •  甜味超标
    2021-01-24 10:58

    I'm still puzzled by the difficulties that you seem to be having. Here's a function which checks that no 2 consecutive elements in a list are identical:

    f[l_List] := Length[Split[l]] == Length[l]
    

    No trouble with Part, no error messages for the simple examples I've tried so far including OP's 'test' cases. I also contend that this is more concise and more readable than either of the other approaches seen so far.

提交回复
热议问题