Skip to content

Instantly share code, notes, and snippets.

@ianrussellsoftwarepark
Last active July 13, 2020 12:04
Show Gist options
  • Save ianrussellsoftwarepark/2264a3e0d1a987abc6ef415f55097e16 to your computer and use it in GitHub Desktop.
Save ianrussellsoftwarepark/2264a3e0d1a987abc6ef415f55097e16 to your computer and use it in GitHub Desktop.
Task 1
// 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