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

namespace Library
{
    public abstract class Matrix
    {
        public readonly int Size;
        public int[,] Data { get; private set; }
        public HashSet<Range> RowRangeSet, ColRangeSet;

        protected Matrix(int size, HashSet<Range> rSet, HashSet<Range> cSet)
        {
            this.Size = size;
            this.RowRangeSet = rSet;
            this.ColRangeSet = cSet;
            this.Data = new int[size, size];
        }

        protected Matrix(int size, HashSet<Range> rSet, HashSet<Range> cSet, int[,] data)
        {
            this.Size = size;
            this.RowRangeSet = rSet;
            this.ColRangeSet = cSet;
            this.Data = data;
        }

        public Range FindRowRange(int row)
        {
            return
                this
                .RowRangeSet
                .First(r => Enumerable.Range(r.Begin, r.Count).Any(i => i == row));
        }

        public Range FindColRange(int col)
        {
            return
                this
                .ColRangeSet
                .First(c => Enumerable.Range(c.Begin, c.Count).Any(i => i == col));
        }

        public bool Check(int[] unit)
        {
            var set = new HashSet<int>(unit);
            return set.Count == this.Size;
        }

        public bool CheckRow(int row)
        {
            var unit = 
                Enumerable
                .Range(0, this.Size)
                .Select(col => this.Data[row, col])
                .ToArray();
            return this.Check(unit);
        }

        public bool CheckCol(int col)
        {
            var unit =
                Enumerable
                .Range(0, this.Size)
                .Select(row => this.Data[row, col])
                .ToArray();
            return this.Check(unit);
        }

        public bool CheckBox(int row, int col)
        {
            var rowRange = this.FindRowRange(row);
            var colRange = this.FindColRange(col);
            var unit = 
                from r in Enumerable.Range(rowRange.Begin, rowRange.Count)
                from c in Enumerable.Range(colRange.Begin, colRange.Count)
                select this.Data[r, c];
            return this.Check(unit.ToArray());
        }

        public bool IsSolved()
        {
            bool isSolved =
                Enumerable
                .Range(0, this.Size)
                .All(index => this.CheckRow(index) && this.CheckCol(index));

            foreach (var rowRange in this.RowRangeSet)
                foreach (var colRange in this.ColRangeSet)
                    foreach (var row in Enumerable.Range(rowRange.Begin, rowRange.Count))
                        foreach (var col in Enumerable.Range(colRange.Begin, colRange.Count))
                            if (isSolved)
                                isSolved = isSolved && this.CheckBox(row, col);
                            else
                                break;
            return isSolved;
        }
        public Result SetValue(int val, int row, int col)
        {
            this.Data.SetValue(val, row, col);

            var isValidRow = this.CheckRow(row);
            var isValidCol = this.CheckCol(col);
            var isValidBox = this.CheckBox(row, col);
            var isSolved = isValidRow && isValidCol && isValidBox;
            if (isSolved)
                isSolved = this.IsSolved();
            return new Result(isValidRow, isValidCol, isValidBox, isSolved);
        }

        public class Range
        {
            public int Begin, Count;
            public Range(int begin, int count)
            {
                this.Begin = begin;
                this.Count = count;
            }
        }
        public class Result
        {
            public readonly bool VaildRow, ValidCol, ValidBox, IsSolved;
            public Result(bool vr, bool vc, bool vb, bool isSv)
            {
                this.VaildRow = vr;
                this.ValidCol = vc;
                this.ValidBox = vb;
                this.IsSolved = isSv;
            }
        }
    }
}
<commit_msg>add set.All(i => i != 0) into Matrix.Check<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library
{
    public abstract class Matrix
    {
        public readonly int Size;
        public int[,] Data { get; private set; }
        public HashSet<Range> RowRangeSet, ColRangeSet;
        
        protected Matrix(int size, HashSet<Range> rSet, HashSet<Range> cSet)
        {
            this.Size = size;
            this.RowRangeSet = rSet;
            this.ColRangeSet = cSet;
            this.Data = new int[size, size];
        }
        
        protected Matrix(int size, HashSet<Range> rSet, HashSet<Range> cSet, int[,] data)
        {
            this.Size = size;
            this.RowRangeSet = rSet;
            this.ColRangeSet = cSet;
            this.Data = data;
        }
        
        public Range FindRowRange(int row)
        {
            return
                this
                .RowRangeSet
                .First(r => Enumerable.Range(r.Begin, r.Count).Any(i => i == row));
        }
        
        public Range FindColRange(int col)
        {
            return
                this
                .ColRangeSet
                .First(c => Enumerable.Range(c.Begin, c.Count).Any(i => i == col));
        }
        
        public bool Check(int[] unit)
        {
            var set = new HashSet<int>(unit);
            return set.Count == this.Size && set.All(i => i != 0);
        }
        
        public bool CheckRow(int row)
        {
            var unit = 
                Enumerable
                .Range(0, this.Size)
                .Select(col => this.Data[row, col])
                .ToArray();
            return this.Check(unit);
        }
        
        public bool CheckCol(int col)
        {
            var unit =
                Enumerable
                .Range(0, this.Size)
                .Select(row => this.Data[row, col])
                .ToArray();
            return this.Check(unit);
        }
        
        public bool CheckBox(int row, int col)
        {
            var rowRange = this.FindRowRange(row);
            var colRange = this.FindColRange(col);
            var unit = 
                from r in Enumerable.Range(rowRange.Begin, rowRange.Count)
                from c in Enumerable.Range(colRange.Begin, colRange.Count)
                select this.Data[r, c];
            return this.Check(unit.ToArray());
        }
        
        public bool IsSolved()
        {
            bool isSolved =
                Enumerable
                .Range(0, this.Size)
                .All(index => this.CheckRow(index) && this.CheckCol(index));

            foreach (var rowRange in this.RowRangeSet)
                foreach (var colRange in this.ColRangeSet)
                    foreach (var row in Enumerable.Range(rowRange.Begin, rowRange.Count))
                        foreach (var col in Enumerable.Range(colRange.Begin, colRange.Count))
                            if (isSolved)
                                isSolved = isSolved && this.CheckBox(row, col);
                            else
                                break;
            return isSolved;
        }
        
        public Result SetValue(int val, int row, int col)
        {
            this.Data.SetValue(val, row, col);

            var isValidRow = this.CheckRow(row);
            var isValidCol = this.CheckCol(col);
            var isValidBox = this.CheckBox(row, col);
            var isSolved = isValidRow && isValidCol && isValidBox;
            if (isSolved)
                isSolved = this.IsSolved();
            return new Result(isValidRow, isValidCol, isValidBox, isSolved);
        }
        
        public class Range
        {
            public int Begin, Count;
            public Range(int begin, int count)
            {
                this.Begin = begin;
                this.Count = count;
            }
        }
        
        public class Result
        {
            public readonly bool VaildRow, ValidCol, ValidBox, IsSolved;
            public Result(bool vr, bool vc, bool vb, bool isSv)
            {
                this.VaildRow = vr;
                this.ValidCol = vc;
                this.ValidBox = vb;
                this.IsSolved = isSv;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09230948768817832, 'fraction_numerical': 0.0009335978527249387, 'mean_word_length': 1.259425257052465, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6854140', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2280, 'n_words': 568}