What is the function of the fourth and fifth steps of the Paul Heckel's Diff Algorithm, and the result does not change after removal - diff

I learn the Paul Heckel's Diff Algorithm from https://gist.github.com/regexident/19b066f86c701fae256600f4ae656934
I can't understand the pass 4 and pass 5, and when I remove it, the result not change

Related

Create a specific number pattern using matlab / octave

How can I create a specific number pattern? Where the last number starts the 2nd pattern section.
Example:
I want to follow / repeat the pattern 1,5,4
1st pattern in section 1,5,4
2nd pattern in section 5,9,8
3rd pattern in section 9,13,12
final array would be = [1,5,4,5,9,8,9,13,12,...]
note: this is just a simple example the pattern will be about 100,000 + numbers
I know about repmat and cumsum but combining these two didn't work
PS: I'm using Octave 4.2.2 which is similar to Matlab
x=reshape([1;5;4]+[0:4:n*4],1,[])
When you take a look at your question, each row is [1;5;4] incremented by a multiple of 4. That is what above code does, adds [1;5;4] with a multiple of 4. Finally the result is reshaped to a vector.

hp prime calculator RPN mode x^y function wrong

x^y (x power y) key on HP prime calculator when running in RPN mode seems to have flipped x, y values on the stack.
In other words, for a normal HP RPN calculator: 3 enter 4 x^y will give 4^3 = 64. But HP prime gives 3^4 = 81.
Is this a bug or a feature?
It's a feature. Here's the source of your very understandable confusion:
On "old school" RPN calculators (includes the 15C), the stack had only 4 elements, from bottom to top, X, Y, Z, and T. "T" would replicate when the stack dropped to allow for calculations using a "constant."
Y^X on those calculators was labeled as such because you would first enter your base then the exponent followed by the operation, leaving the Y argument in the "Y" stack register and the "X" argument in the "X" stack register. Hence 3 Enter 4 "Y^X" would give 81.
On the new calculators, there is a massive stack (something I personally saw no use for--I never ran out of stack space doing calculations on the old stack EVER in decades of advanced calculations). It made the prior constant calculations impossible on the new calculators without programming. The elements are now simply numbered 1, 2, 3, 4, 5, etc. For entry order, they figured input order of variables should be alphabetic, hence x^y. Since there are no longer stack labels, there is no longer a contradictory model of a Y register and an X register as before, so 3 Enter 4 "X^Y" still gives 81, but there is no contradictory register entry here, just a memory of how an older machine labeled its registers. I don't think many would have mistaken things if it were still labeled "Y^X" as before, and I'm personally not fond of the change, but I can understand the motivation. It is not a bug.
Both hp 48sx and hp 50g return 81 for the op's exmaple. The keys are labeled y^x, not x^y. I'm not sure at what point HP changed this.

Basics on Matlab function Unique [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm studying the function unique, which looks simple at a first sight but I don't understand some properties.
I created a matrix A and tried to analyze the outputs:
A=[5 2 4 5;
1 1 3 4;
6 1 2 3]
[C0,IA0,IC0]=unique(A)
[Cr,IAr,ICr]=unique(A,'rows')
[Cf,IAf,ICf]=unique(A,'first')
In C0 the logic of the output is "create a vector in which there are values that appears at least one time"
But I don't know the meaning of IA0 and IC0. I just know the relation that C=A(IA0) and A=C(IC0). Are these 2 output created only to satisfy this two relation? So why should I be intersted in their outputs?
In Cr ('rows' example) the logic of the output is "give me back the rows of the original matrix A but sorted ascending. Also, if you find at least two or more rows that repeat with same values and order, show that row only once in Cr output"
The logic of IAr is very intuitive: "give me back the index that must follow the Cr output to order the rows." So in my example gives me back a vector like IAr=[2;1;3]. Thus the second row of the original matrix A must be the first in the Cr output, the first row in A matrix must be the second in Cr...
But I still don't understand the output ICr
In Cf ('first' example) gives me back the same output as C0. And it's not really clear to me how to use properly this function.
Can anyone gives me a simple explanation about how this function works?
Are there any simple practical examples in which I can take advantage of these other outputs?
Matlab is a generic tool. So asking "why" some functions give extra output just because it might be useful to someone for some reason is difficult to answer.
IA0 gives the indices of the last elements that might have been chosen by unique. IC0 contains indices to replicate A using only the unique elements. Why do they exist? You may not only be interested in unique values, but also where to find them in A.
You are misinterpreting how rows works. It simply treats the rows of your matrix as atomic and returns the unique rows. To get a better idea of how it works, run A(3,:) = A(2,:) before calling unique. Then the idea behind IA0 and IC0 is the same as in the previous case, except now with rows.
The first option only changes how Matlab chooses the indices of IA0. Again, the reason behind this is that Matlab is a generic tool. You might be interested in finding the latest repeated occurence of each value or in the first. It depends on what you want to do.

Extract data using Matlab

How could I correlate the first (also second and third, etc) line of each function together? I meant I want to pick up the value of the first line of function 1, first line of function 2 and so on... Specially number of these lines (between two #...#) are not always equal.
Let's say the values between (# -#) is one matrix. I see that the problem is I need to break them down into different matrix and then equalize all these matrix to the same size by adding NaN values and then reconstruct them again. That is what I think but I dont know how to ask Matlab do these tasks.
Would you please give me a help?
Thank you very much !!

How to exchange variables numbers

I'm asked to do a program that asks for two numbers, the first variable for example is 4 and the second is 5, i need the program to show the first variable as 5 and the second one as 4, so i need the variables to exchange their values
Thanks :DDDD
I think you are asking for number swapping logic.So you can use two logic to swap the number
1. By using 3rd variable.
2. Without using 3rd variable.
Their respective logic's are as follows.
Suppose you have x=4,y=5;
take 3rd variable like temp;
temp=x; x=y; y=temp;
and 2nd logic.
x = x+y; y=x-y; x=x-y;
Such questions are usually asked to reduce the space complexity and to do so we take the following approach:
a=a+b;
b=a-b;
a=a-b;
for example we take a=4 and b=5
a becomes 9
b becomes 4
a becomes 5
finally a=5 and b=4 (swapped)