using System.Collections.Generic;
using System.Text.RegularExpressions;
private static int _minNumericEngineNumberLength = 4;
private static int _minAlphaNumericEngineNumberLength = 5;
private static int _minPartialMatchEngineNumberLength = 3;
private static string _alphanumericRegex = @"^([a-zA-Z0-9- ])*([0-9])+([a-zA-Z0-9- ])*$";
private static string _allNumbersCheckRegex = @"^([0-9])+$";
private static string _repeatedDigitsRegex = @"(\d)\1{2}";
private static string _spaceCharacterString = " ";
private static List<string> _emptyEngineNumberList = new List<string> { "ONOE", "NULL", "NONR", "NONL", "NONI", "NONEL", "NON", "NOEN", "NO", "NLI", "NILL", "NIL,", "NI", "N1", "N", "MOI", "0", "x", "silver", "-", "????", "?????", "//", "NIIL", "NILE", "1", "2", "4", "5", "6", ".", "20L4", "BIL", "BNIU", "BU", "BUK", "BUL", "INL", "JNI", "L400", "MI", "MIL", "MIT", "ML", "MNI", "MNO", "MO", "MOI", "MONE", "N", "N0NE", "none", "N1", "n123", "N22A2", "NA", "NA18", "NA7", "NEL", "NENO", "NI", "nii", "NIKL", "nil", "NIL,", "NILK", "nill", "NILLL", "NIN", "NINE", "NIOL", "NIONE", "NK", "NL", "NLI", "NLL", "NNIL", "NNOE", "NO", "NOE", "NOEL", "NOEN", "NOL", "NOL.", "NOLE", "NOME", "NON", "NONE", "NONE.", "NONEL", "NONI", "NONL", "NONO", "NONOE", "NONR", "NOT", "NUL", "NULL", "ONE", "ONO", "ONOE", "ONOE3", "SRT8", "TB48", "V8", "X", "XX", "XXX", "XXXX", "XXXXX", "XXXXXX", "XXXXXXX", "XXXXXXXX", "XXXXXXXXX", "XXXXXXXXXX", "NILL" };
public static void Main()
List<string> engineList = new List<string> { "3UR3229008", "5477", "550", "55593", "5700", "5780", "6", "63136", "65578", "68616", "69325", "69935", "7785", "86111", "8831", "88620", "90015", "BIL", "BNIU", "BU", "BUK", "BUL", "INL", "JNI", "L400", "MI", "MIL", "MIT", "ML", "MNI", "MNO", "MO", "MOI", "MONE", "N", "N0NE", "N1", "n123", "N22A2", "NA", "NA18", "NA7", "NAIL", "NC", "NEL", "NENO", "NI", "nii", "NIIL", "NIKL", "NIL", "NIL,", "nile", "NILK", "NILL", "NILLL", "NILS", "NIN", "NINE", "NIOL", "NIONE", "NK", "NL", "NLI", "nll", "NNIL", "NNOE", "NO", "NOE", "NOEL", "NOEN", "NOL", "NOL.", "NOLE", "NOME", "NON", "NONE", "NONE.", "NONE4", "NONEL", "NONI", "NONL", "NONO", "NONOE", "NONR", "NOT", "NU", "NUL", "NULL", "ONE", "ONO", "ONOE", "ONOE3", "SRT8", "TB48", "V8", "X", "XX", "XXX", "XXXXX" };
foreach (string engineNumber in engineList)
bool? isGcc = GetVehicleGccSpecOrNot(engineNumber);
Console.WriteLine("Engine number " + engineNumber + (!isGcc.HasValue ? "Not decided" : (isGcc.Value ? " is GCC " : " is Non-Gcc")));
public static bool? GetVehicleGccSpecOrNot(string engineNumber)
bool hasValidEngineNumber = !string.IsNullOrEmpty(engineNumber);
bool existsInInvalidEngineNumber = false;
if (hasValidEngineNumber)
engineNumber = engineNumber.Replace(_spaceCharacterString, string.Empty);
existsInInvalidEngineNumber = EngineNumberExistInBlockList(engineNumber.ToLower());
if (!existsInInvalidEngineNumber)
hasValidEngineNumber = ValidateEngineNumber(engineNumber);
isGccSpec = hasValidEngineNumber && !existsInInvalidEngineNumber;
private static bool EngineNumberExistInBlockList(string engineNumber)
foreach (string blockedItem in _emptyEngineNumberList)
if (blockedItem.Length < _minPartialMatchEngineNumberLength)
if (engineNumber == blockedItem)
else if (engineNumber.Contains(blockedItem))
private static bool ValidateEngineNumber(string engineNumber)
var alphanumericRegex = _alphanumericRegex;
Match match = Regex.Match(engineNumber, alphanumericRegex, RegexOptions.IgnoreCase);
if (!string.IsNullOrEmpty(engineNumber) && match.Success)
var onlyNumberRegex = _allNumbersCheckRegex;
Match onlyNumberMatch = Regex.Match(engineNumber, onlyNumberRegex, RegexOptions.IgnoreCase);
if (onlyNumberMatch.Success)
if (engineNumber.Length < _minNumericEngineNumberLength)
var repeatedRegex = _repeatedDigitsRegex;
Match repeatedRegexMatch = Regex.Match(engineNumber, repeatedRegex, RegexOptions.IgnoreCase);
if (repeatedRegexMatch.Success)
return !IsEngineNumberInSequence(engineNumber);
if (engineNumber.Length < _minAlphaNumericEngineNumberLength)
private static bool IsEngineNumberInSequence(string sequence)
int[] arr = sequence.Select(character => Convert.ToInt32(character.ToString())).ToArray();
for (int i = 2; i < arr.Length; i++)
if (arr[i - 1] == arr[i] - 1 && arr[i - 2] == arr[i] - 2)
else if (arr[i - 1] == arr[i] + 1 && arr[i - 2] == arr[i] + 2)