code snippet for algorithm study