Re: Base function
- To: mathgroup at smc.vnet.net
- Subject: [mg88173] Re: [mg88131] Base function
- From: danl at wolfram.com
- Date: Sun, 27 Apr 2008 04:58:16 -0400 (EDT)
- References: <200804260741.DAA08453@smc.vnet.net>
> Dear All,
>
> ((1*12 + 4)*11 + 4)*10 + 4
>
> 1804
>
> I need help with a function find the Calander "base"
>
> Cbase[1804,{12,11,10}]
>
> out put will be
> {1,4,4,4}
>
> Thanks All,
> Tomi
Here is an explicit loop approach.
calBase[m_, ll_] :=
Module[{rem = m, div = Apply[Times, ll]},
Append[Table[{quo, rem} = QuotientRemainder[rem, div];
div = div/ll[[j]]; quo, {j, Length[ll]}], rem]]
In[25]:= calBase[1804, {12, 11, 10}]
Out[25]= {1, 4, 4, 4}
While I doubt it matters for the application you intend, there are
probably asymptotically faster methods using a divide-and-conquer
strategy.
Daniel Lichtblau
Wolfram Research
- References:
- Base function
- From: haitomi <tpnycity@yahoo.com>
- Base function