private IEnumerable <(IEnumerable <Position> positions, IEnumerable <Value> values)> HiddenSubsetStep( Grid input, Dictionary <Value, IEnumerable <Position> > house, Dictionary <Position, int> positions, Candidates values, int startingIndex, int depth) { if (positions.Count > depth || values.Count() + house.Count - startingIndex <= depth || positions.Keys.Any(pos => (input.GetCandidates(pos) & values) == 0)) { yield break; } if (values.Count() == depth) { if (positions.Keys.Any(pos => (input.GetCandidates(pos) & ~values) != 0)) { yield return(positions.Keys.ToList(), values.ToValues()); } yield break; } for (int i = startingIndex; i < house.Keys.Count; i++) { var value = house.Keys.ElementAt(i); foreach (var pos in house[value]) { if (!positions.ContainsKey(pos)) { positions[pos] = i; } } var valuesNew = values | value.AsCandidates(); foreach (var item in HiddenSubsetStep(input, house, positions, valuesNew, i + 1, depth)) { yield return(item); } foreach (var pos in house[value]) { if (positions[pos] == i) { positions.Remove(pos); } } } }
public int GetFirstCandidate() { if (Candidates.Count() > 0) { return(Candidates[0]); } else { return(-1); } }
public int GetCandidate(int index) { if (index >= 0 && index < Candidates.Count()) { return(Candidates[index]); } else { return(-1); } }
public override string ToString() { var result = new StringBuilder(); result.Append("SudokuElement : [Number="); result.Append(Number); result.Append("; Candidates={"); if (Candidates.Count() > 0) { foreach (int num in Candidates) { result.Append(num); result.Append(", "); } result.Remove(result.Length - 2, 2); } result.Append("}; FontColor="); result.Append(FontColor.ToString()); result.Append("]"); return(result.ToString()); }
private void Vote() { var answer = MessageBox.Show( Language.AreYouVote, Language.Question, MessageBoxButton.YesNo, MessageBoxImage.Question); if (answer == MessageBoxResult.No) { return; } int numberOfVotes = Candidates.Count(x => x.IsChecked); int?candidateIndex = numberOfVotes == 1 ? Candidates.IndexOf(Candidates.Single(x => x.IsChecked)) : (int?)null; mainViewModel.VoteService.SaveVote(_person, candidateIndex); mainViewModel.OpenResultView(); }
public void Candidates_Count_should_depend_on_selected_candidates(Candidates candidates, int expected) { var actual = candidates.Count(); actual.Should().Be(expected); }
public int GetCandidatesSize() => Candidates.Count();
public void TestNew() { Assert.Equal(9, tgt.Count()); Assert.Equal("1-2-3-4-5-6-7-8-9", tgt.ToString()); }