-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageValidator.cs
More file actions
35 lines (29 loc) · 917 Bytes
/
MessageValidator.cs
File metadata and controls
35 lines (29 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Linq;
namespace Codewars.Solutions._6kyu
{
public class MessageValidator
{
public bool IsAValidMessage(string message)
{
if (message.Length > 0)
{
if (!char.IsDigit(message[0]) || char.IsDigit(message[^1]))
{
return false;
}
for (var i = 0; i < message.Length; i++)
{
var num = message.TakeWhile(d => char.IsDigit(d));
var msg = message[num.Count()..].TakeWhile(c => char.IsLetter(c));
if (msg.Count() != Convert.ToInt32(message[..num.Count()]))
{
return false;
}
message = message[(msg.Count() + num.Count())..];
}
}
return true;
}
}
}