[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] recursion



wow thank you!!
lots to study here...
best,

Jonah



On Sat, Dec 28, 2019 at 4:57 PM <daniel-mayer@xxxxxxxx> wrote:
Hi and welcome,

e.g.

(
~collatz = { arg start, limit = 1000;
var num = start, col = [start], count = 1;
while { (num != 1) and: { count <= limit } }{
num = num.even.if { num.div(2) }{ num * 3 + 1 };
col = col.add(num);
count = count + 1;
};
col
}
)

~collatz.(23)

-> [ 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 ]

Greetings

Daniel

-----------------------------
http://daniel-mayer.at
-----------------------------