Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows:
3→10→5→16→8→4→2→1
الگوریتمی رو در نظر بگیرید که یک عدد به عنوان ورودی دریافت کرد (عدد صحیح ) اگر عدد زوج بود الگوریتم عدد را بر 2 تقسیم می کند و اگر فرد بود الگوریتم عدد رو ضرب در 3 و به علاوه 1 می کند الگوریتم باید این کار را تازمانی که عدد به 1 نرسیده ادامه دهد
مثال: اگر ورودی عدد 3 باشد خروجی مانند زیر است
3→10→5→16→8→4→2→1