Commit 95d502ed authored by Elton (Eddie) Hartman's avatar Elton (Eddie) Hartman
Browse files

Problem 12 added more details to multithreaded solution.

parent 724e8bf7
......@@ -24,6 +24,10 @@ namespace ProjectEulerExercises.Problems
/// What is the value of the first triangle number to have over five hundred divisors?
/// </summary>
public class Problem12 : Problem {
//I put in this limit just to limit the number of tasks that can be running concurrently.
//I'd almost deem it unecessary if it weren't for the chance of tasks completing out of order since we're
// not guaranteed that the first answer is the correct one. You have to wait for the number of
// tasks in this limit to complete first.
const int TASK_NUMBER_LIMIT = 100;
/// <summary>
......@@ -79,7 +83,9 @@ namespace ProjectEulerExercises.Problems
while (tasks.Any(t => t.Status == TaskStatus.RanToCompletion) || tasks.Count > TASK_NUMBER_LIMIT) {
Task<HashSet<long>> complete = Task.WhenAny<HashSet<long>>(tasks).Result;
HashSet<long> result = complete.Result;
Console.WriteLine("Tasks: " + tasks.Count);
//Uncomment to see how the number of tasks grows and shrinks
//Console.WriteLine("Tasks: " + tasks.Count);
if (result.Count > number) {
var completedTasks = Task.WhenAll<HashSet<long>>(tasks).Result;
found = true;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment