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

[sc-users] recursion



Hi all,

I am a super n00b to Supercollider, and I feel like I'm asking a very dumb question....but here goes....!...?

I'm trying to get SC to perform the operations of the Collatz conjecture: if the number is even, divide by 2, or odd multiply by 3 and add 1, repeat until you reach 1 (which will continue outputting the sequence 4, 2, 1 according to the rules of the conjecture)

I was able to do this very easily in Max but I feel a little clueless in SC, I thought it'd be simple to code some recursion into a function but I was mistaken? or don't know enough....

I've tried a few versions of something along the lines of:

(
~collatz = {
arg fund;
fund = if(fund % 2 == 0, {fund = fund / 2},{fund = fund * 3 + 1});
fund.postln;
}.value(51);
)

I can get it to output a few numbers in the series, but only if I include more than one instance/evaluation of the argument. Ideally I'd be able to give the function a random number and it'd spit out all the values until it reaches 1.

Anyhow, any help appreciated!!

thankssssss!

Jonah