Distributed and Decentralized Algorithms for Functional Programmable Matter