|
Hi guys.
My google foo seems to have left me this morning as well as my cognitive abilities.
Lets say I have a list of 3 numbers, say (31549, 20468, 17625), that together add up to 69642. Say I have another list of numbers, (10211,8821,6894,6497,6482,5623,5594,5132,4471,4326,3245,2346), that also add up to 69642. I need to select the numbers from the second list that add up to the individual numbers in the first list.
In my example the result I would expect would be
10211 + 5623 + 6894 + 8821 = 31549
3245 + 6497 + 5132 + 5594 = 20468
21346 + 6482 + 4326 + 4471 = 17625
Hope someone has some ideas to help.
Thanks in advance
Everyone dies - but not everyone lives
|
|
|
|
|
Create an array of the second numbers. Take each of the first set in turn and loop through the second arraylooking for the combination that sums to the selected number. You will need to loop through the array taking each number in turn and adding one or more of the others looking for a combination that makes the sum.
|
|
|
|
|
Ah! the brute force approach. Sometimes the obvious escapes you. Many thanks for kickstarting my brain this morning.
Much appreciated
Everyone dies - but not everyone lives
|
|
|
|
|
|
Anyone here understand the following question?
SET sum TO 0
FOR i=1 to size
FOR j=1 to size
sum=sum +1
H
Any help is appreciated! TY
modified 18-Apr-17 9:14am.
|
|
|
|
|
Yes. Probably most of us. But ...
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hiya. I am not requesting answers, Nor is it my " homework ", all i'm enquiring about is just brief guidance on how to logically approach the question. All the tutorials on you tube seem irrelevant to this type of scenario. Does anyone know any GOOD sources that may aid me in this question?
|
|
|
|
|
Perhaps you should think "a little bit" logical.
The answer to the question comes from the difference of the both code-snippets.
Perhaps you try to imagine what the both double-loops are doing in the code-part 1 and what the difference is to code-part 2.
One part of "your" solution is to realize how much total loops are done in each code-part (and of course the understanding how to find it out) ...
So ... if you want further help : give me/us the answer to my last sentence ...
|
|
|
|
|
Pick an arbitrary time to complete operation "sum = sum + 1" and proceed from there.
It's all relative.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I worked out the answers to be O(N) for A and 0(N^2) For B. Any ideas how i could use this to now to calculate how long it would take the algorithm to solve a problem with the size of 1 million operations
|
|
|
|
|
On which hardware, implemented in which language?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Update: the answer to A was wrong and i changed it.
All i know is that it's capped at 1 million operation per second, the rest is unknown to me.
|
|
|
|
|
Member 13133031 wrote: All i know is that it's capped at 1 million operation per second, the rest is unknown to me. You stated in the original question that "size" becomes one million "operations".
SET sum TO 0
FOR i=1 to 10
FOR j=1 to size
sum=sum +1
In that case, the word "operation" is confusing. If you increase the iterations, you'll be executing more instructions.
Since you can count the instructions, you can calculate how long it takes if you know the instructions per second. Shouldn't be too hard to implement this in a BASIC-language and simply see what happens if you change the "size".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i have script for encrypt dan decrypt...
Public Shared Function Decrypt(ByRef Msg As String, ByRef Key As String) As String
Dim str As String
Dim builder As New StringBuilder
Try
Dim num5 As Integer = (Msg.Length - 1)
Dim i As Integer = 0
Do While (i <= num5)
Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3 - num2)
builder.Append(Strings.Chr(charCode))
i += 1
Loop
str = builder.ToString
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim exception As Exception = exception1
Throw New Exception(("Public Function Decrypt(ByRef Msg As String, ByRef Key As String) As String Error : " & ChrW(13) & ChrW(10) & exception.Message.ToString & ChrW(13) & ChrW(10)))
Finally
builder.Length = 0
End Try
Return str
End Function
Public Shared Function Encrypt(ByRef Msg As String, ByRef Key As String) As String
Dim str As String
Dim builder As New StringBuilder
Try
Dim num5 As Integer = (Msg.Length - 1)
Dim i As Integer = 0
Do While (i <= num5)
Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3 + num2)
builder.Append(Strings.Chr(charCode))
i += 1
Loop
str = builder.ToString
Catch exception1 As Exception
ProjectData.SetProjectError(exception1)
Dim exception As Exception = exception1
Throw New Exception(("Public Function Encrypt(ByRef Msg As String, ByRef Key As String) As String Error : " & ChrW(13) & ChrW(10) & exception.Message.ToString & ChrW(13) & ChrW(10)))
Finally
builder.Length = 0
End Try
Return str
End Function
what algorithm is used?
Please advise...
|
|
|
|
|
91191109 wrote: what algorithm is used? It's your code, you tell us.
|
|
|
|
|
Look at MFunction.GetKey(Key, i) - that's what encrypts a single byte.
|
|
|
|
|
91191109 wrote: Dim num3 As Integer = Strings.Asc(Conversions.ToChar(Msg.Substring(i, 1)))
Dim num2 As Integer = Strings.Asc(MFunction.GetKey(Key, i))
Dim charCode As Integer = (num3 + num2)
builder.Append(Strings.Chr(charCode))
Even without seeing the implementation of MFunction.GetKey , it's obvious that this is a variant of the Caesar cipher[^] - possibly a Running key cipher[^].
In other words, an extremely poor algorithm, which will be broken in seconds by a determined hacker.
Unless you are a team of encryption specialists, each with multiple PHDs in the field, then you should never try to implement your own encryption algorithm. There are plenty of perfectly good built-in encryption algorithms; pick one of those instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
... and now you've done his homework.
Actually, not sure about the joke icon.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
How can a find a minimum in right sub tree using recursion
|
|
|
|
|
I'm sorry ... what do you mean ...?
You should give an Example ...
modified 22-Mar-17 9:14am.
|
|
|
|
|
Just recursively trace down the left branches in the right sub tree. The left element is always lowest.
|
|
|
|
|
To begin, I have the set of K values S={v_1, ..., v_K}. I want to pick the smallest value, replace it with another value, and again pick the smallest -- do this K times. So, initially, my best set B is empty, and I want to perform :
Step 1. Find minimum of S. Say it has index n. B=[B, v_n] (i.e., append v_n to B)
Step 2. Update S by replacing v_n with another value (not important how that other value is computed).
Repeat Steps 1 and 2 till B has K values.
I believe a reasonable way to do this is to first construct a min-heap from the initial S (KlogK complexity), and then I can (take out the root + insert new element) for (K-1) times. Assuming taking out root and insertion both are logK complexity, total complexity would be KlogK + 2(K-1)log(K) = (3K-2)logK.
As a next step, once I have the set B, I want to compute some function f(b) for each b in B, and repeat the above procedure with the set {f(b)} instead of the set S. In other words, taking the set {f(b)} as S now, I would like to perform the above described procedure. Brute force way -- I could first use up (3K-2)logK units of time to find B, then compute the set {f(b)}, and then use another (3K-2)logK units of time on {f(b)}. But, it is quite apparent I can do better by pipelining. Essentially, as soon as I start getting entries of B, I can compute f(.) for the available entries, and do some of the sorting operations.
Can you suggest a good/optimal way for the overall problem ?
|
|
|
|
|
i need co-occurrence matrix algorithm in any language. plz share ur results with me.
|
|
|
|
|
|
If you google for it, you will find many examples. Try googling for co occurence matrix python to get started.
This space for rent
|
|
|
|