Skip to content

Instantly share code, notes, and snippets.

@ridomin
Created October 5, 2022 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridomin/c43ac0fca67438d64c6f802dd1c40055 to your computer and use it in GitHub Desktop.
Save ridomin/c43ac0fca67438d64c6f802dd1c40055 to your computer and use it in GitHub Desktop.
IsPrime.cs
using System;
using System.Collections.Generic;
using System.Linq;
var number = 45673;
var multiples = Multiples(number);
Console.WriteLine($"{number} is " +
$"{(multiples.Any() ? "not " : "")}prime");
foreach (var multiple in multiples)
{
Console.WriteLine(multiple);
}
IEnumerable<string> Multiples(int number)
{
return from n1 in Enumerable.Range(2, number/ 2)
from n2 in Enumerable.Range(2, n1)
where n1 * n2 == number
select $"{n1} x {n2} => {number}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment