-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler21.cs
More file actions
60 lines (48 loc) · 897 Bytes
/
euler21.cs
File metadata and controls
60 lines (48 loc) · 897 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
namespace thing
{
class Program
{
static void Main()
{
List<int> numbers = new List<int>();
for (int i = 0; i < 10000; i++)
{
numbers.Add(i);
}
var sum = 0;
while (numbers.Count > 0)
{
Console.WriteLine(numbers.Count);
var candidate = numbers.ElementAt(0);
numbers.RemoveAt(0);
var partner = getSumOfDivisors(candidate);
if (!numbers.Contains(partner))
{
continue;
}
var partnersSod = getSumOfDivisors(partner);
if (partnersSod == candidate)
{
numbers.Remove(partner);
sum += candidate + partner;
}
}
Console.WriteLine(sum); //31626
}
static int getSumOfDivisors(int num)
{
var sum = 0;
for (int i = 1; i < (num / 2) + 1; i++)
{
if (num % i == 0)
{
sum += i;
}
}
return sum;
}
}
}