[Israel.pm] What does this code do?
Shlomi Fish
shlomif at iglu.org.il
Sun May 2 04:53:51 PDT 2004
On Wednesday 28 April 2004 22:50, Moshe Kaminsky wrote:
> * Shlomi Fish <shlomif at iglu.org.il> [27/04/04 17:36]:
> > Hi all!
>
> Hi,
>
> > I wrote the code below to verify the correctness of a solution to my
> > sister's homework. Who can guess what it does?
>
> Much the same as:
>
> perl -e '$N = shift; $num_true_cases=exp(log(3)*$N)-3*exp(log(2)*$N)+3;
> printf "%d\n", $num_true_cases'
>
Right. This can be deduced from a mathematical analysis of the problem, and it
was the solution that I reached. However, I wanted to verify its correctness
against a dumb counting of the cases.
BTW, there's no need to use exp() and log() in this case. You could have
written it as:
perl -e '$N = shift; $num_true_cases=3**$N-3*(2**$N)+3; printf "%d\n",
$num_true_cases'
With "**" which is the power operator.
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://shlomif.il.eu.org/
Quidquid latine dictum sit, altum viditur.
[Whatever is said in Latin sounds profound.]
More information about the Perl
mailing list