Fouriest transform of Integers

February 01 2013 John May 1827
Maple 16

8

Today's SMBC strip by Zach Weinersmith is a silly math joke but it was pretty much begging for implementation.

So, here is a simple brute force Maple program to compute the Fouriest transform of an integer.

fouriest := proc(n::posint, ob::posint:=10)
local b,f,cap,i,rdx,fc;
    b := ob:
    f := nops(select(`=`, convert(n, base, ob),4));
    if f > 0 then
        cap := ceil( exp(ln(n)/f) );
    else
        cap := n-1;
    end if;
for i from 5 to n-1 while i < cap do rdx := convert(n, base, i); fc := nops(select(`=`, rdx, 4)); if fc > f then f := fc; b := i; # new cap is largest base where n has more than f digits cap := ceil( exp(ln(n)/f) ); end if; end do: return cat(`#msub(mo(`,cat(`"`,ListTools:-Reverse(convert(n, base, b))[],`"`),`),mo("`,b,`"))`); end proc:

Try it on his example: fouriest(624);

or on random examples: n := rand(); fouriest(n);

Enjoy.

Please Wait...