The primary task is to implement the core alogrithm of the Schelling Segregation as described above. In the task, it requires one to have capability of defining function types and also making use of recursive functions to properly address question's requirements.