Created
December 16, 2023 15:46
-
-
Save bennotti/e51b3e565c5790e881c76170db555c42 to your computer and use it in GitHub Desktop.
Combinação 6 numeros C#
This file contains hidden or 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
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var data = new List<int> { 14, 07, 50, 17, 04, 05, 12, 03 }; | |
| var valorPorAposta = 5; | |
| var result = Combinations(data).ToList(); | |
| var qntJogos = 0; | |
| foreach (var item in result | |
| .Where(p => p.Length == 6) | |
| .Select(p => p.OrderBy(x => x).ToList() ) | |
| .Select(p => $"[{string.Join(", ", p)}]") | |
| .Distinct() | |
| ) { | |
| Console.WriteLine(item); | |
| qntJogos++; | |
| } | |
| Console.WriteLine($" Qnt Jogos: {qntJogos} "); | |
| Console.WriteLine($" R$: {qntJogos * valorPorAposta} "); | |
| Process.GetCurrentProcess().WaitForExit(); | |
| } | |
| public static IEnumerable<T[]> Combinations<T>(IEnumerable<T> source) | |
| { | |
| if (null == source) | |
| throw new ArgumentNullException(nameof(source)); | |
| T[] data = source.ToArray(); | |
| return Enumerable | |
| .Range(0, 1 << (data.Length)) | |
| .Select(index => data | |
| .Where((v, i) => (index & (1 << i)) != 0) | |
| .ToArray()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment