Upload project.

This commit is contained in:
Stedos 2020-06-26 13:56:07 +01:00
parent 1e3503a70f
commit d5c5de41ca
14 changed files with 469 additions and 0 deletions

8
Anagram/Anagram.csproj Normal file
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

37
Anagram/Program.cs Normal file
View File

@ -0,0 +1,37 @@
using System;
namespace Anagram
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Check("rail safety", "fairy tales")); //Should return true
Console.WriteLine(Check("roast beef", "eat for BSE")); //Should return true (ignores spaces)
Console.WriteLine(Check("DeBiT CaRd", "BAD CREDIT")); //Should return true (ignores case)
Console.WriteLine(Check("empty", "light")); //Should return false (not an anagram)
Console.WriteLine(Check("a", "aa")); //Should return false (not of equal length)
Console.WriteLine(Check("William Shakespeara", "I am a weakish speller")); //Should return false (spelling error)
}
private static bool Check(string s1, string s2)
{
s1 = s1.Replace(" ", String.Empty).ToLower();
s2 = s2.Replace(" ", String.Empty).ToLower();
//If the string lengths aren't equal, they cannot be an anagram.
if (s1.Length != s2.Length)
return false;
while (s1.Length > 0)
{
if (!s2.Contains(s1[0]))
return false;
s2 = s2.Remove(s2.IndexOf(s1[0]), 1);
s1 = s1.Remove(0, 1);
}
return true;
}
}
}

11
Data-Import/CSVUtils.cs Normal file
View File

@ -0,0 +1,11 @@
using System.IO;
namespace Data_Import
{
public static class CSVUtils
{
public static void WriteCSV(string[] csv, string filename) => File.WriteAllLines(filename, csv);
public static string[] ReadCSV(string filename) => File.ReadAllLines(filename);
}
}

48
Data-Import/Car.cs Normal file
View File

@ -0,0 +1,48 @@
using System;
using System.Runtime.CompilerServices;
namespace Data_Import
{
class Car
{
private string registration;
public string Registration { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string Colour { get; set; }
public string FuelType { get; set; }
public bool HasValidRegistration()
{
//The order of these if statements could be improved, however they are written in this order for readability.
if (Registration.Length != 8)
return false;
if (!char.IsLetter(Registration[0]) || !char.IsLetter(Registration[1]))
return false;
if (!char.IsNumber(Registration[2]) || !char.IsNumber(Registration[3]))
return false;
if (Registration[4] != ' ')
return false;
if (!char.IsLetter(Registration[5]) || !char.IsLetter(Registration[6]) || !char.IsLetter(Registration[7]))
return false;
return true;
}
public string AsCSV()
{
return string.Format("{0},{1},{2},{3},{4}", Registration, Make, Model, Colour, FuelType);
}
public Car FromCSV(string csv)
{
var splitCSV = csv.Split(',');
Registration = splitCSV[0];
Make = splitCSV[1];
Model = splitCSV[2];
Colour = splitCSV[3];
FuelType = splitCSV[4];
return this;
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Data_Import</RootNamespace>
</PropertyGroup>
</Project>

62
Data-Import/Program.cs Normal file
View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Data_Import
{
class Program
{
static void Main(string[] args)
{
var carContext = GetCarsFromCSV("data.csv").ToList();
ExportCSVsByFuelType(carContext);
var validCars = GetValidCars(carContext);
Console.WriteLine("Valid Cars:\n");
foreach(var c in validCars)
{
Console.WriteLine(c.AsCSV());
}
Console.WriteLine();
var invalidCarCount = carContext.Count - validCars.Count();
Console.WriteLine(String.Format("Invalid Car Count:\n{0}", invalidCarCount));
}
private static void ExportCSVsByFuelType(List<Car> cars)
{
//Could use a map here?
List<string> petrolCars = new List<string>(), dieselCars = new List<string>();
foreach (var c in cars)
{
if (c.FuelType == "Petrol")
petrolCars.Add(c.AsCSV());
else if (c.FuelType == "Diesel")
dieselCars.Add(c.AsCSV());
}
CSVUtils.WriteCSV(petrolCars.ToArray(), "petrol.csv");
CSVUtils.WriteCSV(dieselCars.ToArray(), "diesel.csv");
}
private static IEnumerable<Car> GetValidCars(List<Car> cars)
{
foreach (var car in cars)
{
if (car.HasValidRegistration())
yield return car;
}
}
private static IEnumerable<Car> GetCarsFromCSV(string filename)
{
foreach(var carString in CSVUtils.ReadCSV(filename))
{
var c = new Car();
yield return c.FromCSV(carString);
}
}
}
}

41
Data-Import/data.csv Normal file
View File

@ -0,0 +1,41 @@
Car Registration,Make,Model,Colour,Fuel
B640 BBJ,Peugeot,106,Red,Petrol
NJ13 LXX,Ford,Fiesta,Blue,Petrol
B640BBJ,VW,Golf,Black,Diesel
LD57 RTE,Audi,A4,Grey,Petrol
RB65 ROB,Seat,Cupra,Black,Petrol
SK67 HSB,Nissan,Leaf,Green,Electric
NHZ 6842,Seat,Ibiza,Black,Petrol
NDR 543R,Volkswagen,Golf,Yellow,Diesel
SK67 HSB,Porsche,911,Red,Petrol
AD58 LDR,Mercedes,C Class,Silver,Petrol
NDJ64 XYZ,Fiat,500,White,Petrol
LT59 MAJ,Ford,Mondeo,Silver,Diesel
MD60XBA,Ford,Fiesta,Silver,Diesel
X201JKL,Jeep,Compass,Orange,Petrol
SL12 JBV,Hyundai,i40,Grey,Deisel
RB66 OLP,Audi,A1,White,petrol
SN18 DDF,Hyundai,i20,Green,Petrol
TR10 NNB,Renault,Megane,Blue,Petrol
PO13 DFS,BMW,M4,Green,Petral
KR09 RVN,Kia,C'eed,White,Petrol
KR59DFE,Vauxhall,Corsa,Orange,Diesel
X913 UOP,Toyota,Prius,Black,Hybrid
CY21 MSK,Tesla,Cybertruck,Silver,Electric
UL66 OPL,Ford,Mustang,Green,Diesel
UE13 URT,Audi,RS6,Blue,Desel
WE66 AFG,BMW,135i,Grey,Petrol
JO19 FRS,Pegeot,Partner,White,Diesel
JM13 LKO,Hyundai,i10,Black,Petrol
DF66 ORT,Citreon,Saxo,Mustard,Petrol
GL65 DOW,Suzuki,GSX100,Blue,Petrol
VB07 QKD,Tesla,Model 3,Red,Electric
NI55 SAN,Nissan,Juke,Yello,Petrol
XL13 PSR,Mini,Cooper,Red,Petrol
JW18 HSV,Nissan,Micra,Red,Petrol
FL61 JER,Ford,Mustang,Yellow,Petrol
DP67 IOA,Peugeot,3008,Black,Petrol
DL56 0PP,Audi,S4,Red,Diesel
WRI5 TYI,BMW,I3,White,Electric
QO59 OTL,BMW,Coupe 3,Black,Petrol
HJ66 NSF,Renault,Clio,Blue,Petrol
1 Car Registration Make Model Colour Fuel
2 B640 BBJ Peugeot 106 Red Petrol
3 NJ13 LXX Ford Fiesta Blue Petrol
4 B640BBJ VW Golf Black Diesel
5 LD57 RTE Audi A4 Grey Petrol
6 RB65 ROB Seat Cupra Black Petrol
7 SK67 HSB Nissan Leaf Green Electric
8 NHZ 6842 Seat Ibiza Black Petrol
9 NDR 543R Volkswagen Golf Yellow Diesel
10 SK67 HSB Porsche 911 Red Petrol
11 AD58 LDR Mercedes C Class Silver Petrol
12 NDJ64 XYZ Fiat 500 White Petrol
13 LT59 MAJ Ford Mondeo Silver Diesel
14 MD60XBA Ford Fiesta Silver Diesel
15 X201JKL Jeep Compass Orange Petrol
16 SL12 JBV Hyundai i40 Grey Deisel
17 RB66 OLP Audi A1 White petrol
18 SN18 DDF Hyundai i20 Green Petrol
19 TR10 NNB Renault Megane Blue Petrol
20 PO13 DFS BMW M4 Green Petral
21 KR09 RVN Kia C'eed White Petrol
22 KR59DFE Vauxhall Corsa Orange Diesel
23 X913 UOP Toyota Prius Black Hybrid
24 CY21 MSK Tesla Cybertruck Silver Electric
25 UL66 OPL Ford Mustang Green Diesel
26 UE13 URT Audi RS6 Blue Desel
27 WE66 AFG BMW 135i Grey Petrol
28 JO19 FRS Pegeot Partner White Diesel
29 JM13 LKO Hyundai i10 Black Petrol
30 DF66 ORT Citreon Saxo Mustard Petrol
31 GL65 DOW Suzuki GSX100 Blue Petrol
32 VB07 QKD Tesla Model 3 Red Electric
33 NI55 SAN Nissan Juke Yello Petrol
34 XL13 PSR Mini Cooper Red Petrol
35 JW18 HSV Nissan Micra Red Petrol
36 FL61 JER Ford Mustang Yellow Petrol
37 DP67 IOA Peugeot 3008 Black Petrol
38 DL56 0PP Audi S4 Red Diesel
39 WRI5 TYI BMW I3 White Electric
40 QO59 OTL BMW Coupe 3 Black Petrol
41 HJ66 NSF Renault Clio Blue Petrol

8
FizzBuzz/FizzBuzz.csproj Normal file
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

93
FizzBuzz/Program.cs Normal file
View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
foreach (int number in GetNumbers())
{
//Console.WriteLine("asdsaadas" + MultiplesOfThree.FirstOrDefault(f => f == number.ToString()));
if (MultiplesOfThree.FirstOrDefault(f => f == number.ToString()) != null && MultiplesOfFive.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetFizzBuzz());
continue;
}
if (MultiplesOfThree.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetFizz());
continue;
}
if (MultiplesOfFive.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetBuzz());
continue;
}
Console.WriteLine(number);
}
}
private static readonly List<string> MultiplesOfThree = new List<string> {
"3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36", "39", "42", "45", "48", "51", "54", "57", "60", "63", "66", "69", "72", "75", "78", "81", "84", "87", "90", "93", "96", "99"
};
private static readonly List<string> MultiplesOfFive = new List<string> {
"5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"
};
static List<int> GetNumbers()
{
List<int> numbers = new List<int>();
while (numbers.Count < 100)
{
Random rand = new Random();
int r = rand.Next(1, 101);
if (numbers.Count == 0)
{
if (r == 1)
numbers.Add(r);
}
else
if (r == numbers[numbers.Count - 1] + 1)
{
numbers.Add(r);
Console.WriteLine(r);
}
}
return numbers;
}
static string GetCharacter(Characters character)
{
if (character.ToString().ToCharArray()[0] > 'E' && character.ToString().ToCharArray()[0] < 'G') return "F";
if (character.ToString().ToCharArray()[0] > 'h' && character.ToString().ToCharArray()[0] < 'j') return "i";
if (character.ToString().ToCharArray()[0] > 'y' && character.ToString().ToCharArray()[0] < 123) return "z";
if (character.ToString().ToCharArray()[0] > 'A' && character.ToString().ToCharArray()[0] < 'C') return "B";
if (character.ToString().ToCharArray()[0] > 't' && character.ToString().ToCharArray()[0] < 'v') return "u";
return "Unknown";
}
static string GetFizz()
{
return GetCharacter(Characters.F) + GetCharacter(Characters.i) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
static string GetBuzz()
{
return GetCharacter(Characters.B) + GetCharacter(Characters.u) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
static string GetFizzBuzz()
{
return GetCharacter(Characters.F) + GetCharacter(Characters.i) + GetCharacter(Characters.z) + GetCharacter(Characters.z) + GetCharacter(Characters.B) + GetCharacter(Characters.u) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
}
enum Characters
{
F, i, z, B, u
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>IP_Filtering</RootNamespace>
</PropertyGroup>
</Project>

79
IP-Filtering/Program.cs Normal file
View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace IP_Filtering
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(IsInStringContext("192.168.0.1")); //Should return true
Console.WriteLine(IsInStringContext("192.168.0.2")); //Should return true
Console.WriteLine(IsInStringContext("192.168.0.3")); //Should return false
Console.WriteLine(IsInStringContext("192.168.1.133")); //Should return true (in range)
Console.WriteLine(IsInStringContext("192.168.4.54")); //Should return true (in range)
Console.WriteLine(IsInStringContext("192.168.4.53")); //Should return false (not in range)
Console.WriteLine(IsInStringContext("192.168.2.34")); //Should return true (in CIDR range)
Console.WriteLine(IsInStringContext("192.168.3.34")); //Should return false (not in CIDR range)
Console.WriteLine(IsInStringContext("192.168.3.212")); //Should return true (in CIDR range) !!
}
private static readonly List<string> StringDataContext = new List<string>{
"192.168.0.1", "192.168.0.2", "192.168.1.0 - 192.168.1.255", "192.168.2.0/24", "192.168.3.128/25", "192.168.4.54 - 192.168.4.62"
};
public static bool IsInStringContext(string ip)
{
//Check if it's explicitly in the data context
if (StringDataContext.Exists(d => d == ip))
return true;
var givenIPOctets = ip.Split('.');
//Next, check if it's in range
//For this, I am going to assume IP ranges can only be a range of the last octet
foreach (string address in StringDataContext.Where(sdc => sdc.Contains('-')))
{
string[] addresses = address.Replace(" ", "").Split('-');
string[] firstAddressOctets = addresses[0].Split('.');
string[] secondAddressOctets = addresses[1].Split('.');
//Make sure first three octets are the same
if (givenIPOctets[0] != firstAddressOctets[0] ||
givenIPOctets[1] != firstAddressOctets[1] ||
givenIPOctets[2] != firstAddressOctets[2])
{
continue;
}
int ipAddressLastOctet = int.Parse(givenIPOctets[3]);
int firstAddressLastOctet = int.Parse(firstAddressOctets[3]);
int secondAddressLastOctet = int.Parse(secondAddressOctets[3]);
if (ipAddressLastOctet >= firstAddressLastOctet && ipAddressLastOctet <= secondAddressLastOctet)
return true;
}
//Lastly, check if it's in CIDR range.
//Again, I'm going to assume IP ranges can only be part of the last octet.
foreach (string address in StringDataContext.Where(sdc => sdc.Contains('/')))
{
string[] ipAddress = address.Split('/');
string[] octets = ipAddress[0].Split('.');
if (givenIPOctets[0] != octets[0] ||
givenIPOctets[1] != octets[1] ||
givenIPOctets[2] != octets[2])
{
continue;
}
int maxOctet = (int)Math.Pow(2, 32 - int.Parse(ipAddress[1])) + int.Parse(octets[3]);
if (int.Parse(givenIPOctets[3]) >= int.Parse(octets[3]) && int.Parse(givenIPOctets[3]) <= maxOctet)
return true;
}
return false;
}
}
}

43
Technical-Test.sln Normal file
View File

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anagram", "Anagram\Anagram.csproj", "{4AAC9DCA-EB30-421B-BFB6-97EF640659C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IP-Filtering", "IP-Filtering\IP-Filtering.csproj", "{143C4099-6252-4F85-8F50-51E47B9E6E30}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data-Import", "Data-Import\Data-Import.csproj", "{E6047087-A0D6-407B-9F66-6F0489E70112}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzz", "FizzBuzz\FizzBuzz.csproj", "{B7D4A3B1-7B60-4A51-ADBE-75483C13CF58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4AAC9DCA-EB30-421B-BFB6-97EF640659C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AAC9DCA-EB30-421B-BFB6-97EF640659C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AAC9DCA-EB30-421B-BFB6-97EF640659C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AAC9DCA-EB30-421B-BFB6-97EF640659C2}.Release|Any CPU.Build.0 = Release|Any CPU
{143C4099-6252-4F85-8F50-51E47B9E6E30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{143C4099-6252-4F85-8F50-51E47B9E6E30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{143C4099-6252-4F85-8F50-51E47B9E6E30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{143C4099-6252-4F85-8F50-51E47B9E6E30}.Release|Any CPU.Build.0 = Release|Any CPU
{E6047087-A0D6-407B-9F66-6F0489E70112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6047087-A0D6-407B-9F66-6F0489E70112}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6047087-A0D6-407B-9F66-6F0489E70112}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6047087-A0D6-407B-9F66-6F0489E70112}.Release|Any CPU.Build.0 = Release|Any CPU
{B7D4A3B1-7B60-4A51-ADBE-75483C13CF58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7D4A3B1-7B60-4A51-ADBE-75483C13CF58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7D4A3B1-7B60-4A51-ADBE-75483C13CF58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7D4A3B1-7B60-4A51-ADBE-75483C13CF58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B7D8119F-AA55-41C2-BFFB-18AE7B433488}
EndGlobalSection
EndGlobal

12
Technical-Test/Program.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
namespace Technical_Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Technical_Test</RootNamespace>
</PropertyGroup>
</Project>