Skip to content

Instantly share code, notes, and snippets.

@SonnyRR
Created July 21, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SonnyRR/84714d7fe38e14152c19d53694e7594a to your computer and use it in GitHub Desktop.
Save SonnyRR/84714d7fe38e14152c19d53694e7594a to your computer and use it in GitHub Desktop.
namespace SandBox
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
public class EntryPoint
{
public static void Main()
{
string givenMessage = Console.ReadLine();
int[] emojiCodeArray = Console.ReadLine()
.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
Regex regex = new Regex(@"(?<=[\s])(?<emoji>:[a-z]{4,}:)(?=[\s,.!?])");
IList<Match> matchCollection = regex
.Matches(givenMessage)
.ToList();
int totalPower = 0;
foreach (var match in matchCollection)
{
string calcMatch = match.Value;
for (int i = 1; i < calcMatch.Length - 1; i++)
{
totalPower += calcMatch[i];
}
}
string emojiName = GetEmojiName(emojiCodeArray);
string matchesConcatenated = string.Join(string.Empty, matchCollection);
if (matchesConcatenated.Contains(emojiName))
{
totalPower *= 2;
}
if (matchCollection.Count > 0)
{
Console.WriteLine($"Emojis found: {string.Join(", ", matchCollection)}");
}
Console.WriteLine($"Total Emoji Power: {totalPower}");
}
private static string GetEmojiName(IEnumerable<int> inputArray)
{
if (inputArray == null)
{
throw new ArgumentNullException(nameof(inputArray));
}
var stringBuilder = new StringBuilder(inputArray.Count());
stringBuilder.Append(':');
foreach (var number in inputArray)
{
stringBuilder.Append((char)number);
}
stringBuilder.Append(':');
return stringBuilder.ToString().TrimEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment