Intelligence is the wrong word in this case. These are complicated emergent behaviours that arise from extremely simple rules applied locally and iteratively by each individual. There's no planning, forethought, or central driving will at play here.
If this is intelligence, then so is bone growth, which follows a similarly simple algorithm, is also honed by evolution, and is also inspiring real-world applications, e.g.:
http://www.engineering.com/DesignSoftware/DesignSoftwareArti...
https://www.fastcodesign.com/1671102/a-3-d-printed-house-tha...