Re: Base function
- To: mathgroup at smc.vnet.net
- Subject: [mg88180] Re: Base function
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 27 Apr 2008 04:59:35 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fuumbc$88b$1@smc.vnet.net>
haitomi wrote:
> ((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}
Since the above (incomplete) assignment sounds like homework, I shall
suggest, without further explanation, one possible coding for such a
function.
cBase[d_Integer?NonNegative,
l : {a_, b_, c_} /; VectorQ[l, IntegerQ@# && Positive@# &]] :=
Module[{v = {e, f, g, h}},
v /. ToRules@
Reduce[c (a b e + b f + g) + h == d && And @@ Thread[0 <= v <= 9],
Integers]]
cBase[1804, {12, 11, 10}]
{1, 4, 4, 4}
Note that the code above does not attempt to handle in any specific way
cases where no solution or multiple solutions may arise.
Regards,
-- Jean-Marc