Last active
July 13, 2020 12:04
-
-
Save ianrussellsoftwarepark/2264a3e0d1a987abc6ef415f55097e16 to your computer and use it in GitHub Desktop.
Task 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created in Linqpad | |
void Main() | |
{ | |
// 'baaaa' = -1 | |
// 'dog' = 8 | |
// 'aabab' = 3 -> 'aa' + 'ba' + 'b' | |
// 'aabaa' = 0 -> 'aa' + 'baa' | |
// 'adoag' = 6 -> 'a' + 'd' + 'oa' + 'g' | |
calculate("baaaa").Dump(); | |
calculate("dog").Dump(); | |
calculate("aabab").Dump(); | |
calculate("aabaa").Dump(); | |
calculate("adoag").Dump(); | |
} | |
public int calculate(string word) | |
{ | |
if (word.Contains("aaa")) return -1; | |
if (!word.Contains("a")) return getCount(word); | |
return getCount(word.Replace("a", "")) - word.Count(c => c == 'a'); | |
} | |
public int getCount(string word) | |
{ | |
return (word.Count() + 1) * 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment