Algorithm experiment code written by Swift