The swarm behaviour can be fully determined by attractants (food pieces) which change the directions of swarm propagation. If we assume that at each time step the swarm can find out not more than p – 1 attractants, then the swarm behaviour can be coded by p-adic integers. The main task of any swarm is to logistically optimize the road system connecting the reachable attractants. In the meanwhile, the transporting network of the swarm has loops (circles) and permanently changes, e.g. the swarm occupies some attractants and leaves the others. However, this complex dynamics can be effectively coded by p-adic integers. This allows us to represent the swarm behaviour as a calculation on p-adic valued strings.