27 April 2017

Metro Card

My solution:
int[] metroCard(int lastNumberOfDays) 
{
    return lastNumberOfDays == 28 || lastNumberOfDays == 30 ? new [] { 31 } : new [] { 28, 30, 31 };
}

Previous Next

Will You?

My solution:
bool willYou(bool young, bool beautiful, bool loved) 
{
    return (young && beautiful && !loved) || ((!young || !beautiful) && loved);
}

Previous Next

Tennis Set

My solution:
bool tennisSet(int score1, int score2) 
{
    return (Math.Min(score1, score2) < 5 && Math.Max(score1, score2) == 6) || ((Math.Min(score1, score2) == 5 || Math.Min(score1, score2) == 6) && Math.Max(score1, score2) == 7);
}

Previous Next

Arithmetic Expression

My solution:
bool arithmeticExpression(int A, int B, int C) 
{
    return A + B == C || A - B == C || A * B == C || A / B == C && A % B == 0;
}

Previous Next

Is Infinite Process?

My solution:
bool isInfiniteProcess(int a, int b) 
{
    return a > b || Math.Abs(a - b) % 2 == 1;
}

Previous Next

Extra Number

My solution:
int extraNumber(int a, int b, int c) 
{
    return (a == b) ? c : (a == c) ? b : a;
}

Previous Next

Knapsack Light

My solution:
int knapsackLight(int value1, int weight1, int value2, int weight2, int maxW) 
{
    if (weight1 + weight2 <= maxW)
        return value1 + value2;
    else if (weight1 > maxW && weight2 > maxW)
        return 0;
    else if (weight1 > maxW)
        return value2;
    else if (weight2 > maxW)
        return value1;
    else
        return value1 > value2 ? value1 : value2;
}

Previous Next