Showing posts with label Rains of Reason. Show all posts
Showing posts with label Rains of Reason. Show all posts

01 April 2017

chessBoardCellColor

My solution:
bool chessBoardCellColor(string cell1, string cell2) 
{
    return (cell1[0] - 'A' % 2 + cell1[1] - '1' % 2) % 2 == (cell2[0] - 'A' % 2 + cell2[1] - '1' % 2) % 2;
}

Previous Next

alphabeticShift

My solution:
string alphabeticShift(string inputString) 
{
    return new string(inputString.ToCharArray().Select(x => x == 'z' ? 'a' : (char)(x + 1)).ToArray());
}

Previous Next

variableName

My solution:
bool variableName(string name)
{
    if (Regex.IsMatch(name, "^\\d"))
        return false;
    if (name.All(c => ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) || char.IsDigit(c) || c == '_'))
        return true;

    return false;
}

Previous Next

evenDigitsOnly

My solution:
bool evenDigitsOnly(int n)
{
    return n.ToString().All(c => int.Parse(c.ToString()) % 2 == 0);
}

Previous Next

Array Replace

My solution:
int[] arrayReplace(int[] inputArray, int elemToReplace, int substitutionElem)
{
    for (int i = 0; i < inputArray.Length; i++)
        if (inputArray[i] == elemToReplace)
            inputArray[i] = substitutionElem;

    return inputArray;
}

Previous Next