score:3
judging from your sql query, i think this is what you want:
var lotterynumbers = new int[] { ... };
var results =
from j in jogos
where lotterynumbers.contains(j.n1) &&
lotterynumbers.contains(j.n2) &&
lotterynumbers.contains(j.n3) &&
lotterynumbers.contains(j.n4) &&
lotterynumbers.contains(j.n5) &&
lotterynumbers.contains(j.n6) &&
lotterynumbers.contains(j.n7) &&
lotterynumbers.contains(j.n8) &&
lotterynumbers.contains(j.n9) &&
lotterynumbers.contains(j.n10) &&
lotterynumbers.contains(j.n11) &&
lotterynumbers.contains(j.n12) &&
lotterynumbers.contains(j.n13) &&
lotterynumbers.contains(j.n14) &&
lotterynumbers.contains(j.n15)
select j;
or in fluent syntax
var results =
jogos.where(j =>
lotterynumbers.contains(j.n1) &&
lotterynumbers.contains(j.n2) &&
lotterynumbers.contains(j.n3) &&
lotterynumbers.contains(j.n4) &&
lotterynumbers.contains(j.n5) &&
lotterynumbers.contains(j.n6) &&
lotterynumbers.contains(j.n7) &&
lotterynumbers.contains(j.n8) &&
lotterynumbers.contains(j.n9) &&
lotterynumbers.contains(j.n10) &&
lotterynumbers.contains(j.n11) &&
lotterynumbers.contains(j.n12) &&
lotterynumbers.contains(j.n13) &&
lotterynumbers.contains(j.n14) &&
lotterynumbers.contains(j.n15));
although this assumes you don't have duplicates in either lotterynumbers
or in j.n1 .. j.n15
. otherwise you'd probably get unexpected results.
score:32
two ways to solve your problem.
represent a winning combination as a set of fifteen integers:
hashset<int>
you have a sequence of winning games:
ienumerable<hashset<int>>
and a specific hashset<int>
. you wish to know if the specific set exactly matches any of the winning sets.
method one
static bool didiwin(ienumerable<hashset<int>> winningnumbers, hashset<int> mynumbers)
{
return winningnumbers
.where(winningnumber => mynumbers.setequals(winningnumber))
.any();
}
or even
static bool didiwin(ienumerable<hashset<int>> winningnumbers, hashset<int> mynumbers)
{
return winningnumbers
.any(winningnumber => mynumbers.setequals(winningnumber));
}
method two
static bool didiwin(ienumerable<hashset<int>> winningnumbers, hashset<int> mynumbers)
{
return false;
}
method two is a lot faster. however, it gives the incorrect result on average one time out of every three million winning numbers. this demonstrates that sometimes you can get a big performance win by being willing to accept a tiny amount of inaccuracy.
:-)
Source: stackoverflow.com
Related Query
- How to know if I Won the lottery In C#
- How do I find the text within a div in the source of a web page using C#
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How does linq actually execute the code to retrieve data from the data source?
- How can I write the following code more elegantly using LINQ query syntax?
- How to code the partial extensions that Linq to SQL autogenerates?
- How to know which Linq statement produced the SQL on hand during runtime?
- How can we express the following code using query expression?
- How to change the precision and the scale of decimal globally through code first?
- How to swap the data source associated with a Linq query?
- How to write this code using the Linq Extension Method-Syntax?
- How can a ForEach loop in LINQ know about the values in the prior iteration of the loop?
- How does Linq know the name of an element?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Don't know how to generate the query I need using Entity Framework 4
- How do I determine the source of unpredictable LINQ query results?
- How does VS Code metrics do the math
- How would you write this C# code (that uses the yield keyword) succinctly in Ruby?
- How can I know the index of a XML Tag
- How to simplify the code Using LINQ
- How to write the same code using Lambda Expression
- How to write aggregate query in LINQ reusing part of the select code
- How to execute code as a part of the LINQ query
- How to know if the user has permission on a parent node of a tree?
- How can I get data from the Entity Framework if I only know the table name and the column name from which to get the data?
- How do I remove duplicate code in the query?
- How can i make this code more optimized - How can i replace the forloop.?
- how to know if a string contains any of the strings on a list?
- How I can improve the code using lambda expressions?
More Query from same tag
- Date range falling between two dates in a LINQ query
- 'object' does not contain a definition for 'type'
- System.Linq.Expressions.Expression for .OrderBy function
- LINQ aggregate items in a list, concatenate a property
- LINQ to XML optional element query
- Method that return a query from a query in argument
- Include datatable in existing linq query
- LINQ - select by property name
- Entity Framework ExecuteSQLCommand returning XML string
- How to write extension method on ef
- How do I rewrite this SQL query in LINQ format?
- Non-static Expression<Func<X>> with access to 'this'
- Format exception - RavenDB LINQ query
- How to retrieve Stored Procedure schema using Linq to SQL?
- Accessing one item in a group
- Linq date format
- Combine two sequences with different types
- A valid delegate for IssuerSigningKeyResolver
- Why Linq Query Return Duplicate column record
- NOT IN for LINQ?
- Searching for records in several tables using EF TPT
- read from csv to object[] C#
- c# Understanding AsEnumerable in LINQ query
- List of all LINQ query expression keywords?
- unable to update table data in linq
- return different linq to sql result sets into single object(json format)?
- minimum value in dictionary using linq
- How do I remove the Where condition of my lambda expression?
- Get top 5 records based on average c# linq lazy loading
- LINQ with SQLite (linqtosql)