static void
Main(string[] args)
{
Console.Write("N:
");
int n = int.Parse(Console.ReadLine());
if (!doit(n, 1))
Console.WriteLine("CANNOT
DO...");
else
Console.WriteLine("the
order of commands is reversed...because they are not a part of the objective of
the function...");
}
// (N & 3) == 0
// the two last bits of N are 0
// n % 4 == 0
// simply faster...
// (n & 1) == 0 ==> the
same...
private static bool doit(int n, int step)
{
if (step == 3)
return n == 42;
if (((n & 1) == 0) && (doit(n >> 1,
step + 1)))
{
Console.WriteLine("devide
be 2");
return true;
}
if ((n % 3 == 0 || (n & 3) == 0) &&
(doit(n - (n % 10) * (n / 10 % 10), step + 1)))
{
Console.WriteLine("substract
miltiply of two last digits");
return true;
}
if ((n % 5 == 0) && (doit(n - 42, step + 1)))
{
Console.WriteLine("substract
42");
return true;
}
return false; } |