The programs are as follows:

Factors

- Code: Select all
`≪ RECT @dup factors toElements 2. / { } 1. ROT START DUP 1. 4. ROLL START PICK3 + NEXT NIP NIP NEXT≫`

This takes the result of factors (or FACTORS) and returns it as a string of factors, instead of pairs of factors and exponents.

UnitDivs

- Code: Select all
`≪ divs @dupdup reverse 2 ≪ gcd≫ DOLIST ≪ 1 ==≫ select≫`

This returns the unitary divisors of a number: if a number n has a divisor d, and the GCD of d and n/d is 1, that is a unitary divisor.

Digits

- Code: Select all
`≪ split≫`

This takes a number and splits it into an array of its component digits.

Question: What is the best way to handle something like -1.42e-13, which becomes [NaN 1 4 2 NaN NaN 13]? How do I get rid of the NaNs?

DblFact

- Code: Select all
`function (x) {`

var d = 1;

if (x < 2) return d;

var i = x;

while (i > 0) {

d = d * i;

i = i - 2;

}

return d;

}

I found an iOS calculator for free that had this function (press ! twice), and had to have it. It computes n*(n-2)*(n-4)...

Diffs

- Code: Select all
`≪ @dup tail 0 + - @dup size 1 - resize≫`

Computes successive differences of a vector: start with a range of 1 to 10, square it, and get the successive differences of -3 -5 -7 -9 etc. to -19, run it again and the differences are all 2.

PartConj

- Code: Select all
`≪ @dup 'v' @var_store [] 'a' @var_store 1 at 1 - 0 @swap FOR x v ≪ x > ≫ map total a @swap + 'a' @var_store NEXT a≫`

This computes the conjugate of a partition: if a partition is described by a Ferrers diagram:

11 = 5 3 1 1 1

XXXXX

XXX

X

X

X

The conjugate is as if you are reading down instead of across:

5 2 2 1 1

Like most of my code, this doesn't do any checking of the input.

Question: Why does the variable a stick around after the program has run. How do I use a local variable?

cool

- Code: Select all
`≪ 'age' @var_store "Nxt" age nextPrime @tag "Prv" age prevPrime @tag "Divs" age ndivs @tag "Phi" age phi @tag "Rdcl" age radical @tag "sigma" age 1 sigma @tag "Hex" age toHex @tag "Oct" age toOct @tag "Ulam" age Ulam @drop @tag age Factors≫`

I wrote a function to figure out my age in days, and this function displays some cool things about the resulting number (like, with the factors, how old I would be if years were 253 days long or something like that.

Now, I rewrote this as

- Code: Select all
`≪ →n ≪ "Nxt" n nextPrime @tag "Prv" n prevPrime @tag "Divs" n ndivs @tag "Phi" n phi @tag "Rdcl" n radical @tag "sigma" n 1 sigma @tag "Hex" n toHex @tag "Oct" n toOct @tag "Ulam" n Ulam @drop @tag n Factors ≫ ≫`

Question: why doesn't this work? I wanted to use a local variable n instead of one that hangs around after the program has run (age in the first example).

Dave Motto