It took a while to figure out because setting the scale factor k fucked up the integer operations for RANDU.
Also, I'm quite pleased with myself for coming up with the pseudocomment string at the top.
[ Registers: u - routine : execute i if sum of squares less than 1 i - routine : increment register x z - routine : iterator - execute u while n > m++ r - routine : RANDU PRNG m - variable: number of samples x - variable: number of samples inside circle s - variable: seed for r k - variable: scale for division n - variable: number of iterations (user input) ]c [lrx 2^ lrx 2^ + 1>i]su [lx 1+ sx]si [lu x lm 1+ d sm ln>z]sz [0k ls 65539 * 2 31^ % d ss lkk 2 31 ^ /]sr ? sn 5dksk 1 ss lzx lx lm / 4* p
Currently, the seed is hardcoded to 1. It would be a one-character change to read it from the input as well.
Name:
Alexander Dubček2015-03-17 3:32
[ Registers: f: routine - fibonacci step function z: routine - driver a: variable - first number b: variable - second number i: variable - iterator n: variable - number of steps (user input) ]c
[sa sb la lb + lb]sf [p lfx li 1+ d si ln>z]sz 1 1 ?sn lzx
$ echo 10 | dc fib.dc 1 1 2 3 5 8 13 21 34 55
Name:
Alexander Dubček2015-03-17 4:19
[ f: routine - print fizz b: routine - print buzz u: routine - print fizzbuzz c: routine - increment i m: routine - call c to set i for 3, 5, 15 p: routine - print fizz or buzz o: routine - just print the variable z: routine - iterator; call m, then print for i=0,1,2 divisors x: variable - garbage disposal i: variable - 3, 5, 15 n: variable - number of iterations ]c
[[Fizz]psx]sf [[Buzz]psx]sb [[FizzBuzz]psx]su [li 1 + si]sc [0si d 3 % 0=c d 5 % 0=c]sm [d 3 % 0=f d 5 % 0=b]sp [p]so [lmx li 2=u li 1=p li 0=o 1+ d ln >z]sz
Oh, and basically register k contains the kernel-macro that selects the value for each "pixel", so it would be easy to modify the code to generate different kind of demo.
Stack before k is x y t, and after k it must be a x y t, where x is x-coordinate, y is y-coordinate, t is time, and a is the value of the pixel [1-9].
Any of you who like doing "programs" with dc or any other stack based language should try IBNIZ http://pelulamu.net/ibniz/
Real time graphics&audio programming with language similar to dc (but with commands better suited for the task IMO). Very fun to fool around. Download&compile for your own system, the Javascript implementation is buggy (at least for me).