|
yes no doubt about that , but both takes very long time to calculate numbers with big values such as i posted earlier
|
|
|
|
|
To go further, change the code to print each solution in order and look at changes between solutions.
Try 3, 4, 150
Try 3, 4, 151
Try 3, 4, 153
And look at each set of answer, you should see a repeating patern. This what Harold is speaking about in http://www.codeproject.com/Messages/5156686/Re-Fastest-way-to-count-nested-loops.aspx[^]
And when you have a repeating pattern, you can know very fast the number of solutions without loop at all.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
That looks like Bézout's identity[^], the result depends on what algebraic structure you want to use, which is a bit unclear here. What size of integer do you want to consider?
You can see there what form the pairs of (i,j) take if they are solutions (called (x,y) on the wiki page). x increments in steps of b/gcd(a,b) and y decrements in steps of a/gcd(a,b). k can also go negative though. The problem then is counting how many of those things are in the valid range of your integer type. It has some weird edge cases but obviously you can do it without counting every possibility explicitly.
|
|
|
|
|
You don't need any code to solve this!
When (x,y) is a solution to number1 *x + number2*y = final number ,
then so is (x+k*number2, y-k*number1) whatever the value of k.
So the number of solutions is either zero or infinite, depending on the given values.
Then, if you want to limit the solution to some range of values, you can easily figure which values of k are acceptable once you have a first solution (x,y).
|
|
|
|
|
hello everyone... first of all im reading a book about algorithms analysis and im in the topic called counting the primitive operation of an algorithm
and the algorithm is finding the largest element in an array ....
and it comes up to this formula:
the best case is :
2 + 1 + n + 4(n - 1) + 1 = 5n
and the worst case is
2 + 1 + n + 6(n - 1) + 1 = 7n - 2
my question is how does he come up to those answet ? sorry guys im not very good at math.. and im still working on my algebra skills
thanks guys for the help
this.is.the psuecode.that.have been used for the example.in the book
Algorithm arrayMax(A, n):
Currentmax = A[0]
for (i = 1; i < n - 1; i++) do:
If CurrentMax < A[i] do:
CurrentMax = A[i]
return CurrentMax
|
|
|
|
|
Basic algebra:
Member 11897566 wrote: 2 + 1 + n + 4(n - 1) + 1 = 5n
2 + 1 + n + 4(n - 1) + 1
== 2 + 1 + 1 + n + 4(n - 1)
== 4 + n + 4n - 4
== 4 - 4 + 5n
== 5n
Member 11897566 wrote: 2 + 1 + n + 6(n - 1) + 1 = 7n - 2
2 + 1 + n + 6(n - 1) + 1
== 2 + 1 + 1 + n + 6(n - 1)
== 4 + n + 6n - 6
== 4 - 6 + 7n
== -2 + 7n
== 7n - 2
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi Homer, thanks for the reply and for the effort to answer it. it makes a little more sense to me right now..
last request for you is can you please tell me what topic is this in algebra so that i could study it more...
very much thanks..
|
|
|
|
|
I'm not sure it really qualifies as its own topic. Rearranging expressions containing constants and variables is the most basic part of algebra, from which all other topics flow. This is usually covered fairly early on in any high-school maths course.
Here's a basic introduction to algebra[^] which might help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Member 11897566 wrote: last request for you is can you please tell me what topic is this in algebra so that i could study it more...
Myself I doubt there is any point.
You are never going to use this as a professional programmer.
If you want to become a theoretical computer theory professor specializing in this then be assured.
1. You need to learn a lot more math including algebra
2. The field has been very well studied for a very, very long time so think long an hard if this particular aspect is what you want to specialize in.
|
|
|
|
|
How can this be done?
Polynomial
Please, any assistance would be appreciated :/
modified 24-Mar-16 13:07pm.
|
|
|
|
|
Look up GF(2k) multiplication and division. Various implementations are also easily findable with google once you know that keyword.
|
|
|
|
|
Thank you! Found several pages of information. Now just have to study it
|
|
|
|
|
Not sure what you want to do. Do you have more details ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Here is the algorithm I'm stuck on (and sorry it's not in proper pseudocode):
a = number to be converted
b = base to be converted from
c = base to be converted to
d = number of places in a (can use builtins such as len(str(a))
e = a - (a modulo (d * b)) to establish top digit
f = e floor divided by c to establish number of digits in
output number (works even if c > b)
g = e modulo c for first digit or output number
...and this is where I get stuck
Please help.
|
|
|
|
|
Help with what? What is the assignment?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Where did you find this ?
Google not working ?
What test dataset have you tried ?
What is your language ?
You are wrong at step e ...
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi!! I got some information related on this as below but I was wondering what sort of problems exactly does this Fiestel Cipher Algorithm solves? Any ideas and resources specifically on problems aim to solve would be appreciated. Cheers!!
Related infos but did not exactly get regarding problems aim to solve:
• A Feistel network is a symmetric structure used in the construction of block ciphers. A block cipher is a deterministic algorithm operating on fixed-length groups of bits, called blocks. Block ciphers are important elementary components in the design of many cryptographic protocols, and are widely used to implement encryption of bulk data.
• Data Encryption Standard (DES) was the result of a research project lead by Horst Cipher in IBM which resulted in a cipher known as Lucifer.
• As with most encryption schemes, DES expects two inputs - the plaintext to be encrypted and the secret key. The manner in which the plaintext is accepted, and the key arrangement used for encryption and decryption, both determine the type of cipher it is. DES is therefore a symmetric, 64 bit block cipher as it uses the same key for both encryption and decryption and only operates on 64 bit blocks of data at a time5 (be they plaintext or ciphertext).
|
|
|
|
|
It does not solve problems, it is an algorithm for encrypting and decrypting information to allow for secure storage. transmission etc.
|
|
|
|
|
But surely storing and transmitting data securely is a problem that needs to be solved, and an encryption algorithm is a solution to that problem?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Recently, a question on QA here about implementing a Rock-Scissors-Paper (RSP) game [^], to which I responded, left me with a curiosity to see how efficiently/tersely I could implement the possible analysis of the result of game play.
Which got me interested in the more general question of how, given a complex matrix of values and criteria which can be expressed in typical De Morgan table form can be ... possibly ... analyzed by code in such a way that either an optimal implementation of the matrix (code-generation) is generated, or, some set of heuristics is generated that the programmer can interpret and use to write optimized code.
To use the RSP possible outcomes as a simple example, and excluding the obvious condition that if two "players" select the same "object," the game is a tie:
assume 0 => Rock , 1 => Scissors, 2 => Paper
0 1 true ... rock breaks scissors => player1 wins
1 2 true
2 0 true
0 2 false ... paper covers rock => player1 loses
1 0 false
2 1 false
Of course, it's straightforward to write a simple switch statement, or if/else/ chain to "solve" this.
"Eyeballing" such a table, and looking for "patterns" in the outcomes, the mind may naturally think about various boolean operations like XOR, or using modulo some number, looking for "heuristics;" look for "threshold" values that can "prune" the possible comparison matrix.
Looking further than this simple example, one can think about the complexity of an airfare reservations system where there might be twenty different factors resulting in the selection of the final airfare price from some list of pricing levels.
And, of course, the programmer will (hopefully) have (or create somehow) some clear description of the "business rules" that describe the calculation process.
Let's say the outcome in the airfare scenario is a matrix of 1000 combinations (to be conservative). To our brains it's pretty easy to look at the criteria and use the business rules to select the criterion (like passenger Age) that may have the most "impact" on the matrix of combinations: i.e., you'd want to first "prune" the matrix by a switch statement using Age as the selector.
And, it would be logical, as you eyeball the criteria to consider those with the fewest number of "states" and use testing those in the "outer" switch statements to reduce computation.
However, an interesting complication may be that some criterion with only one, or a few states may be, in practice, rarely of predictive value: that, imho, takes you into the analysis of the criterion based on context (world-knowledge, statistics of use, etc.). I want to exclude that from this post.
Then there are the interactions of variables; in the airfare scenario a discount for early booking may not apply to the fare calculation for accompanied children between age 5~11, for example. While some variables may be inherently "binary," such as, perhaps, the need for a wheelchair, many variables may have a number of "levels," like, for example, age broken out by infant, child, teen, adult, senior.
I'm sure that Decision Table theory which has been around for so long has generated some algorithms/heuristics for analyzing complex boolean matrices and optimizing code.
Appreciate your thoughts !
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 1-Nov-15 2:33am.
|
|
|
|
|
Problems of this sort I usually approach by first doing some data / frequency analysis.
Then start "slicing" (usually) from the variable that has the least unique values for a given context.
e.g. If I wanted to select all males in California, would I first slice on "gender" or on "State" (of residence)? The point is, it's hard to generalize on strategies and it all "depends". (This also applies to complex SQL queries which the "optimizer" isn't getting quite right since the optimizer depends on an a particular "execution plan").
|
|
|
|
|
I don't use a standard way to deal with this problem.
My solution is always context dependent and language dependent. No heuristics will do it for me.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
I know the brute force method. can someone help me find a good solution!!
Input Format
The first line contains an integer, T, which is the number of test cases. T test cases follow, each having a structure as described below:
The first line contains two space-separated integers, R and C, indicating the number of rows and columns in the grid G, respectively.
This is followed by R lines, each with a string of C digits, which represent the grid G.
The following line contains two tab-separated integers, r and c, indicating the number of rows and columns in the pattern grid P.
This is followed by r lines, each with a string of c digits, which represent the pattern P.
Constraints
1≤T≤5
1≤R,r,C,c≤1000
1≤r≤R
1≤c≤C
example
INPUT
2
10 10
7283455864
6731158619
8988242643
3830589324
2229505813
5633845374
6473530293
7053106601
0834282956
4607924137
3 4
9505
3845
3530
15 15
400453592126560
114213133098692
474386082879648
522356951189169
887109450487496
252802633388782
502771484966748
075975207693780
511799789562806
404007454272504
549043809916080
962410809534811
445893523733475
768705303214174
650629270887160
2 2
99
99
output
Yes
No
pls help!!
|
|
|
|
|
Member 12083453 wrote: I know the brute force method. can someone help me find a good solution!! Solution to what problem ?
You describe the data used, but not the problem you try to solve.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|