// title: The quest for the prime numbers // author: henklass // description: // The search for prime numbers from 1 to 100 is represented by sound. Channel 1: the numbers, channel 0: the divisors. In the center: a fm-sound with a carrier that is related to the number and a modulator that is related to the divisor. A harmonic sound means the carrier is a multiple of the modulator, so the number is a multiple of the divisor. Therefor a harmonic sound means: not a prime number. When a new prime number is encountered, the list of prime numbers is played. // code: //Prime numbers Server.default.boot; ( //maximum number ~max=100; //synthdefs: 2 filtered sawteeth for number and divisor SynthDef ( \gsaw, {arg g; Out.ar(1, RLPF.ar ( Saw.ar(20*g), 10000*(1-(g/~max)), 0.2, 0.2) ) }).add; SynthDef ( \dsaw, {arg d, g; Out.ar(0, RLPF.ar( Saw.ar(20*d), 10000*d/sqrt(g), 0.2, 0.2) // the square root is important: if you search for the divisors of a number, // don't search beyond the square root of the number. There won't be any. ) }).add; //a fm-sound with carrier 20*number and modulator 20*divisor, modulation index = 10 SynthDef (\fm, {arg m, c; Out.ar(0, Pan2.ar(SinOsc.ar(20*c+(SinOsc.ar(20*m, 0, 200*m, 0))), 0) ) }).add; ) ( r=Routine({ var number, divisor; //the list of prime numbers l=Array.newClear(indexedSize: 0); for (2, ~max,{arg number; x=Synth(\gsaw, [\g, number]); //play the number divisor=2; p=true; //prime number? while ({((divisor <= (number.sqrt)).and(p == true))}, { y=Synth(\dsaw, [\d, divisor, \g, number]); //play the divisor z=Synth(\fm, [\m, divisor, \c, number]); //play the fm sound of number and divisor 1.wait; //1 second should be enough to hear if a sound is harmonic // harmonic sound means: not a prime number y.free; z.free; if( number.mod(divisor) == 0, {p = false} ); //not a prime number divisor = divisor + 1; } ); x.free; if (p == true){ //primenumber! l=l.add(number); //add primenumber to the list for (1, l.size, { arg i; //play the list of prime numbers z=Synth(\fm, [\m, l.size, \c, l[i]]); 0.1.wait; z.free; }); } }); }); ) r.play;