Hacker News new | ask | show | jobs
by seryoiupfurds 2204 days ago

    [Monte Carlo approximation of Pi.
    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

    $ dc pi.dc
    100000
    3.13372