{
   "labels" : [
      "collatzproblem",
      "notenumbers",
      "tonality"
   ],
   "is_private" : null,
   "id" : "1-4Vx",
   "code" : "//series of numbers: Collatz-scale: http://oeis.org/A070165\r\n//from 1 to 100\r\n//while number>1\r\n//if even: divide by 2, else multiply by 3 and add 1 \r\n//remember highest value, remember longest series, both with their startnumber\r\n//startnumber->cutoff, number-> frequency, pan mid\r\n//startnumber->cutoff, highest value -> frequency, pan right\r\n//startnumber->cutoff, longest series -> cutoff, pan left\r\n//There seemd to be some tonality in the numbers when used as MIDI-notenumbers\r\n//To find that out you can count the occurrences of all the numbers wrapped between 0 en 11\r\nServer.default.boot;\r\n(\r\nSynthDef(\\beep, { |freq=440, cutoff=1000, pan=0|\r\n\tOut.ar(0, (Pan2.ar(LPF.ar(VarSaw.ar(freq, width: 0.01), cutoff), pan))*0.4 )}).send(s);\r\n)\r\n(\r\nvar highest=1,  longest=1, starthighest=1, startlongest=1;\r\nvar numberbeep, highestbeep, longestbeep;\r\nu=Array.new(12);  //array to store the numbers, wrapped to 0..11\r\n{for(0, 12, {u.add(0)})}.value;\r\n\r\nnumberbeep=Synth(\\beep, [\\freq, 200, \\cutoff, 200, \\pan, 0]);\r\nlongestbeep=Synth(\\beep, [\\freq, 200, \\cutoff, 200, \\pan, -1]);\r\nhighestbeep=Synth(\\beep, [\\freq, 200, \\cutoff, 200, \\pan, 1]);\r\n\r\nRoutine({\r\n\tfor (1, 100, { arg startnumber;\r\n\t\tvar number, length=1, maximum;\r\n\t\tnumber=startnumber;\r\n\t\tmaximum=startnumber;\r\n\t\tu[startnumber%12]=u[startnumber%12]+1;\r\n\t\t\r\n\t\t(number.asString+\" \").post;\r\n\t\tnumberbeep.set(\\cutoff, 100*startnumber);\r\n\t\twhile ( {number>1},{\r\n\t\t\tif (number.asInteger.even, {number=(number/2)}, {number=3*number+1});\r\n\t\t\tlength=length+1;\r\n\t\t\tif (number>maximum, {maximum=number});\r\n\t\t\tnumberbeep.set(\\freq, (32+(number%96)).midicps); //frequency as MIDI-notenumber between 32 and 128, that is 8 octaves\r\n\t\t\tlongestbeep.set(\\freq, (32+(length%96)).midicps);\r\n\t\t\thighestbeep.set(\\freq, (32+(maximum%96)).midicps);\r\n\t\t\tu[number%12]=u[number%12]+1; //count the occurrences of this number wrapped between 0 and 11\r\n\t\t\t0.1.wait;\r\n\t\t});\r\n\t\tif(length>longest, {longest=length; startlongest=startnumber});\r\n\t\tif (maximum>highest, {highest=maximum; starthighest=startnumber});\r\n\t\tlongestbeep.set(\\cutoff, 100*longest);\r\n\t\thighestbeep.set(\\cutoff, highest*2);\r\n\t\t\t(\"length: \" + length.asString).post;\r\n\t\t\t(\" maximum: \" + maximum.asString).postln;\r\n\t});\r\n\tpostf(\"longest series % at % \\n\", longest, startlongest);\r\n\tpostf(\"highest value % at % \\n\", highest, starthighest);\r\n\tnumberbeep.set(\\freq, 33.midicps, \\cutoff, 10000);\r\n\tlongestbeep.set(\\freq, ((32+longest)%96).midicps, \\cutoff, 100*startlongest);\r\n\thighestbeep.set(\\freq, ((32+highest)%128).midicps, \\cutoff, 100*starthighest);\r\n\t10.wait;\t\r\n\tnumberbeep.free;\r\n\thighestbeep.free;\r\n\tlongestbeep.free;\r\n}).play;\r\n)\r\n\r\n(\r\n/*This shows the Collatz-scale: The fourth step, which coincidentally is a C, is dominant and the 10th, F# follows. There is quite some A, B flat, C#, E and G and very little E flat. A flat, B, D, and F are almost absent. So I guess the Collatz scale is: C, C#, E, F#, G, A, B flat, C and you can use E flat as some kind of Blue note or something.*/\r\n\r\nu.plot(bounds: Rect(10, 100, 400, 400));//show as graph \r\n\r\nfor(0, 12, {arg i;   //show as list\r\n\tif( (u[i] > 0), {(i.asString+\" \").post; u[i].postln})\r\n\t}\r\n\t);\r\n)\r\nnumberbeep.set(\\freq, (32+(0%96)).midicps); \r\n{VarSaw.ar(440, [0.1, 1], 0.05, 1, 0)}.scope",
   "name" : "The Collatz Scale",
   "author" : "henklass",
   "ancestor_list" : [],
   "description" : "Some time ago a did a thing on a series of numbers, that, as I learned later, was officially called the Collatz problem and it can be found on the Online Encyclopedia of Integer Sequences: http://oeis.org/A070165 . One day I was playing with those numbers on a keyboard and I had the impression, that some notes occur more frequent than others. This implies some kind of tonality. So I rewrote the code to use notenumbers in stead of frequencies. And here is the result. The fourth step, which coincidentally is a C, is dominant and the 10th, F# follows. There is quite some A, B flat, C#, E and G and very little E flat. A flat, B, D, and F are almost absent. So I guess the Collatz scale is: C, C#, E, F#, G, A, B flat, C and you can use E flat as some kind of Blue note or something."
}
