Hailstone sequence
Hey all, so I'm kind of a beginner when it comes to max but I've gotten an assignment for college that I'm really struggling with. Find below the task:
The Hailstone sequence works in the following way. Starting with a positive whole number n, form a sequence so that:
H(n) = n/2 if n is even
H(n) = 3n + 1 if n is odd
The sequence ends when the algorithm yields 1.
Create a patcher that stores the first 10 values of the Hailstone sequence and then uses these to create MIDI pitches. You should be able to choose the value n and then listen to the result.
Creating the algorithm is ok as I understand the logic but storing the values is where I'm finding difficulty.
If anyone would have any suggestions on how to implement this id love to hear form you. Cheers
Did you search the forum with a good query like… "Hailstone"?
You may find some interesting post.
You might take a look at the coll object I suppose.
This doesn't store anything, but maybe it helps?
Sorry for the late reply, I was using it for a college assignment which did not allow outsourcing code so I ran into some problems there, oops. I implemented the coll object which was the missing link. Thanks for the help anyway :)
glad to hear that some people still write their own code. :)
i would do it like that:
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 18 78 63 9109513 uzi 100000;
#P newex 106 128 53 9109513 gate;
#P newex 106 224 53 9109513 != 1;
#P message 247 91 50 9109513 451;
#P button 149 77 26 0;
#P newex 158 176 50 9109513 i;
#P number 231 243 76 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 231 176 256 9109513 expr (($i1&1)!=1) * ($i1/2) + ($i1&1) * (($i1*3)+1);
#P connect 0 0 5 0;
#P connect 0 0 2 1;
#P connect 0 0 1 0;
#P connect 6 0 2 0;
#P connect 3 0 6 1;
#P connect 5 0 6 0;
#P connect 4 0 2 1;
#P connect 2 0 0 0;
#P window clipboard copycount 8;
but the better learning lesson would be to use a bunch of single function math and logic objects such as +, *, ==, or &.
all hail,
110