Created
October 5, 2022 21:13
-
-
Save ridomin/c43ac0fca67438d64c6f802dd1c40055 to your computer and use it in GitHub Desktop.
IsPrime.cs
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
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