-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquareRootCompare.cs
More file actions
59 lines (51 loc) · 1.6 KB
/
Copy pathsquareRootCompare.cs
File metadata and controls
59 lines (51 loc) · 1.6 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace codeWarsAreTheyTheSame
{
class Program
{
static void Main(string[] args)
{
//compare 2 lists of numbers - see if the first list has the square root numbers of the second list
int[] a = { 121, 144, 19, 161, 19, 144, 19, 11 };
int[] b = { 132, 14641, 20736, 361, 25921, 361, 20736, 361 };
Console.WriteLine(AreTheySame.comp(a, b));
}
}
class AreTheySame
{
public static bool comp(int[] a, int[] b)
{
if (a.Length == 0 || b.Length == 0)
return true;
List<double> firstList = (from item in a select Convert.ToDouble(item)).ToList();
List<double> secondList = (from item in b select Convert.ToDouble(item)).ToList();
firstList.OrderBy(x => x);
secondList.OrderBy(x => x);
for (int i = 0; i < secondList.Count; i++)
{
secondList[i] = Math.Sqrt(secondList[i]);
}
int count = 0;
foreach (var second in secondList)
{
foreach (var first in firstList)
{
if (second != first)
{
count++;
}
if (count == firstList.Count)
{
return false;
}
}
count = 0;
}
return true;
}
}
}