  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Algorithm - Choose next query based on previous one  » algorithm » Algorithm - Choose next query based on previous one

By : jemeri
Date : December 01 2020, 05:00 PM
I hope this helps . You have to decide if the question should be asked or not. This is one way. I haven't provided the QuestionContext, it's your job to decide how to store the answers and decide if the question is available based on that.
I was tempted to go with the next() question method, but sometimes you need a little more context(i.e. if you own a smartphone & smartphone is from Apple, ask what version of iOS is running). code :
``````interface Question {
public boolean isAvailable(QuestionContext ctx);
// ... rest of the methods
}

public class Questionnaire implements QuestionContext {
private Question[] qs;

// constructors, getters, etc.

for (Question q : qs) {
if (q.isAvailable(this)) {
}
}
}
}
`````` ## How to choose a range for a loop based upon the answers of a previous loop?

By : user4853632
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further nice question. Here's at least a start for what I think you should do for this:
code :
``````Sub findMin()
Dim lowest As Integer
Dim middle As Integer
Dim highest As Integer
lowest = 999
middle = 999
hightest = 999

Dim i As Integer
i = 1
Do While i < 9
If (retVal(i) < retVal(lowest)) Then
highest = middle
middle = lowest
lowest = i
Else
If (retVal(i) < retVal(middle)) Then
highest = middle
middle = i
Else
If (retVal(i) < retVal(highest)) Then
highest = i
End If
End If
End If
i = i + 1
Loop
End Sub

Function retVal(num As Integer) As Double
retVal = 0.245 * Math.Sqr(num) * num - 0.67 * Math.Sqr(num) + 5 * num + 12
End Function
`````` ## Algorithm to choose multiple discrete parameters based on input vector

By : Aliaksei Belski
Date : March 29 2020, 07:55 AM
To fix the issue you can do This is a classic classification (data mining) problem and it's up to you to pick which algorithm to use. The most common approaches are:
KNN (k-nearest-neighbor) Bayes classifier SVM (support vector machine) Decision trees ## How to choose execute from 2 queries depending of the result of a previous query in SQLite

By : user2409028
Date : March 29 2020, 07:55 AM
To fix this issue I have 3 queries in SQLite:
code :
``````SELECT id_asiento AS ID
FROM ASIENTOS_DIARIO
WHERE (SELECT COUNT(id_asiento) FROM ASIENTOS_DIARIO WHERE id_paquete = 1) > 0
UNION ALL
SELECT id_cta AS ID
FROM CUENTASXPAQ
WHERE (SELECT COUNT(id_asiento) FROM ASIENTOS_DIARIO WHERE id_paquete = 1) = 0
`````` ## choose parser based on previous results

By : Sze LIM
Date : March 29 2020, 07:55 AM
seems to work fine I'm parsing several outputs and these files have two different headers: , I think in pyparsing one would just write:
code :
``````oneParserToRuleThemAll = header1 + parser1 | header2 + parser2
``````
``````foo_parser = ...
bar_parser = ...

variable_parser = Forward()
switch_parser = Literal("foo") | Literal("bar")
def select_variable_parser(tokens):
if tokens == "foo":
variable_parser <<= foo_parser
if tokens == "bar":
varaible_parser <<= bar_parser
switch_parser.setParseAction(select_variable_parser)
parser = switch_parser + variable_parser
``````
``````parser = "foo" + foo_parser | "bar" + bar_parser
`````` ## Fast algorithm for generating all combinations (n choose k) based on an initial input

By : Ðêýâä ÐêšÏgñèr
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I think the biggest problem you're going to encounter is not calculation but disk write speed or memory size. By the way, it seems you wrongly determined number of combinations for n = 250 and k = 6. Did you use uint64_t? My number is 244 140 625 000 000.
So for this number you need ~1.4 Petabyte (~1400 Tb) of memory. This is your main problem. If you have that much big hard drive, you'd better use memory mapping, when write. You may consider using several threads to write: each will write its own chunk of memory.
code :
``````int main()
{
const constexpr uint8_t N = 250;
const constexpr uint8_t K = 6;
const constexpr uint64_t CombinationsCount = std::pow(N, K);
using TCombination = std::array<uint8_t, K>;

std::cout << CombinationsCount << std::endl;

std::ofstream file("output.txt");
TCombination c;
for (uint64_t i = 0; i < CombinationsCount; ++i)
{
auto I = i;
for (auto j = 0; j < K; ++j)
{
c[j] = I % N;
I /= N;
file << (int)c[j];
}
file << std::endl;
}

}
``````
``````const constexpr uint8_t N = 250;
const constexpr uint8_t K = 6;
const constexpr uint64_t CombinationsCount = std::pow(N, K);
using TCombination = std::array<uint8_t, K>;

void Generate(uint64_t start, uint64_t size, const char* fileName)
{
std::ofstream file(fileName);
TCombination c;
for (uint64_t i = start; i < start + size; ++i)
{
auto I = i;
for (auto j = 0; j < K; ++j)
{
c[j] = I % N;
I /= N;
file << (int)c[j];
}
file << std::endl;
}
}

int main()
{
std::cout << CombinationsCount << std::endl; 