<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PracticalLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            AnyVsCount();

        }

        private static void AnyVsCount()
        {
            var stopwatch = new Stopwatch();

            var oddNumberSequence = (from value in GenerateLongRandomSequence()
                                     where value % 2 == 1
                                     select value);

            stopwatch.Start();
            var hasOdds = oddNumberSequence.Any();
            stopwatch.Stop();
            Console.WriteLine("Elapsed time for Any: {0}", stopwatch.Elapsed);
            stopwatch.Reset();

            stopwatch.Start();
            hasOdds = oddNumberSequence.Count() > 0;
            stopwatch.Stop();

            Console.WriteLine("Elapsed time for Any: {0}", stopwatch.Elapsed);
        }

        public static IEnumerable<int> GenerateLongRandomSequence()
        {
            var generator = new Random();

            return from n in Enumerable.Range(0, 5000000)
                   select generator.Next(0, 1500);
        }

    }
}<commit_msg>SinglDefault<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PracticalLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            // AnyVsCount();
            SingleFirstDefault();
        }

        private static void AnyVsCount()
        {
            var stopwatch = new Stopwatch();

            var oddNumberSequence = (from value in GenerateLongRandomSequence()
                                     where value % 2 == 1
                                     select value);

            stopwatch.Start();
            var hasOdds = oddNumberSequence.Any();
            stopwatch.Stop();
            Console.WriteLine("Elapsed time for Any: {0}", stopwatch.Elapsed);
            stopwatch.Reset();

            stopwatch.Start();
            hasOdds = oddNumberSequence.Count() > 0;
            stopwatch.Stop();

            Console.WriteLine("Elapsed time for Any: {0}", stopwatch.Elapsed);
        }

        private static void SingleFirstDefault()
        {
            var triples = from x in Enumerable.Range(1, 150)
                          let y = x + 1
                          let z = x + 2
                          select new { x, y, z };

            var perfectTriples = from point in triples
                                 where point.x * point.x + point.y * point.y == point.z * point.z
                                 select point;

            var only = perfectTriples.Single();
            Console.WriteLine("Only perfect triple: {0}", only);

            var oddSum = from point in triples
                         where (point.x + point.y + point.z) % 2 == 1
                         select point;

            var first = oddSum.First();
            Console.WriteLine("The first match of {0} is {1}", oddSum.Count(), first);

            var perfectSquares = from point in triples
                                 let product = point.x * point.y * point.z
                                 where Math.Sqrt(product) == Math.Floor(Math.Sqrt(product))
                                 select point;
            var sought = perfectSquares.FirstOrDefault();
            if (sought == null)
                Console.WriteLine("Not found");
            else
                Console.WriteLine("Found {0} matches. First match is {1}", perfectSquares.Count(), sought);

            // Use the perfect triples again for SingleOrDefault:
            var soughtSingle = perfectTriples.SingleOrDefault();
            if (soughtSingle == null)
                Console.WriteLine("Not found");
            else
                Console.WriteLine("Found {0}", soughtSingle);
        }


        public static IEnumerable<int> GenerateLongRandomSequence()
        {
            var generator = new Random();

            return from n in Enumerable.Range(0, 5000000)
                   select generator.Next(0, 1500);
        }

    }
}
{'fraction_non_alphanumeric': 0.09337701848818161, 'fraction_numerical': 0.011701380762930026, 'mean_word_length': 1.4848837209302326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6524760', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1010, 'n_words': 289}