Last active
December 10, 2018 09:53
-
-
Save mataprasad/a68762d0055e8688b6e846f72c742033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aptitute Test -- | |
https://www.wonderlic.com/ | |
class Class1 | |
{ | |
static int[,] RotateMatrixCounterClockwise(int[,] oldMatrix) | |
{ | |
int[,] newMatrix = new int[oldMatrix.GetLength(1), oldMatrix.GetLength(0)]; | |
int newColumn, newRow = 0; | |
for (int oldColumn = oldMatrix.GetLength(1) - 1; oldColumn >= 0; oldColumn--) | |
{ | |
newColumn = 0; | |
for (int oldRow = 0; oldRow < oldMatrix.GetLength(0); oldRow++) | |
{ | |
newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn]; | |
newColumn++; | |
} | |
newRow++; | |
} | |
return newMatrix; | |
} | |
public static void Test() | |
{ | |
//string[] test = new string[3] { "dog", "cat", "mouse" }; | |
var test = new int[] { 1, 2, 3, 4, 2 }; | |
int count = 0; | |
Dictionary<string, int> aa = new Dictionary<string, int>(); | |
foreach (var x in Subsets(test.Distinct().ToArray())) | |
{ | |
aa.Add(Newtonsoft.Json.JsonConvert.SerializeObject(x), x.Sum()); | |
//Console.WriteLine("[{0}]", string.Join(",", x)); | |
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(x)); | |
count++; | |
} | |
var b = aa.GroupBy(P => P.Value).Where(P => P.Count() > 1); | |
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(b,Newtonsoft.Json.Formatting.Indented)); | |
Console.WriteLine("----:" + (1 << test.Length) + ":---:" + count); | |
} | |
public static IEnumerable<T[]> Subsets<T>(T[] source) | |
{ | |
int max = 1 << source.Length; | |
for (int i = 0; i < max; i++) | |
{ | |
T[] combination = new T[source.Length]; | |
for (int j = 0; j < source.Length; j++) | |
{ | |
int tailIndex = source.Length - j - 1; | |
combination[tailIndex] = | |
((i & (1 << j)) != 0) ? source[tailIndex] : default(T); | |
} | |
yield return combination; | |
} | |
} | |
} | |
//============================================================== | |
class Program | |
{ | |
static void LineSeparator() | |
{ | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine(new String('-', 50)); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
} | |
static void Main(string[] args) | |
{ | |
LineSeparator(); | |
var input = new int[] { 9, 4, -3, -2, 1, -1, 5, 7, -9, -5 }; | |
var output = input.Where(P => P >= 0).ToList(); | |
output.AddRange(input.Where(P => P < 0).ToList()); | |
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(output)); | |
LineSeparator(); | |
for (int i = 1; i <= 5; i++) | |
{ | |
for (int k = 0; k < i - 1; k++) | |
{ | |
Console.Write(" " + (i - k)); | |
} | |
for (int j = 1; j <= (6 - i); j++) | |
{ | |
Console.Write(" " + j); | |
} | |
Console.WriteLine(); | |
} | |
LineSeparator(); | |
input = new int[] { -8, -5, -3, -1, 3, 6, 9 }; | |
output = input.OrderBy(P => Math.Abs(P)).ToList(); | |
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(output)); | |
LineSeparator(); | |
var TextString = "abcNjhgAhGjhfhAljhRkhgRbhjbevfhO"; | |
var SampleString = "NAGARRO"; | |
var searched = new List<char>(); | |
for (int i = 0; i < TextString.Length; i++) | |
{ | |
if (SampleString.Contains(TextString[i])) | |
{ | |
searched.Add(TextString[i]); | |
} | |
} | |
Console.WriteLine( | |
SampleString == new String(searched.Take(SampleString.Length).ToArray()) ? | |
"FOUND" : "NOT FOUND"); | |
LineSeparator(); | |
Class1.Test(); | |
LineSeparator(); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment