What do the vimdiff key input sequences stand for? - input

I am recently started to use vimdiff. And I love it.
And I found some pretty short key input sequences as shown below:
But, the character key and the meaning is not that easy to remember.
I guess the key sequence should have reasons why it is for example the c key shold stand for change and d key should stand for difference and so on...
] + c : first diff part downward
[ + c : first diff part upward
d + o : bring text in the opposite part to the cursor position.
d + p : paste current cursor position text into the opposite part.
z + o / z + space : unfold folded text in the cursor position.
z + c : fold unfolded text in the cursor position.
What whould the key inputs above stand for?
How do you remember these key sequences?

Related

Just want to check if the way i have used the assignment expression in python 3.8 program is correct or not

According to Heron's formula for finding area of a triangle , if the sides of a triangle are a, b & c is :
s = (a+b+c) / 2
area =sqrt( s * (s-a) * (s-b) * (s-c)) # sqrt means square root
so for finding the area of the triangle using Heron's formula in Python, if I write code like this, will it be a valid practise? I have used assignment expression while calculating the area.
a = int(input("Enter value of first side")) # Assuming value is integer
b = int(input("Enter value of second side")) # Assuming value is integer
c = int(input("Enter value of third side")) # Assuming value is integer
area = ((s := (a+b+c) /2) *(s -a)*(s-b)*(s-c))**0.5
print("Area of the triangle is", area)
Yes, program counts correct. There is a one drawback in input: I recommend to add '\n' in input because it is uncomfortable to enter values without any space near text. In this code I fixed that. But you need to add checking if sides can make triangle.
a = int(input("Enter value of first side")) // Assuming value is integer
b = int(input("Enter value of second side")) // Assuming value is integer
c = int(input("Enter value of third side")) // Assuming value is integer
area = ((s := (a+b+c) /2) *(s -a)*(s-b)*(s-c))**0.5
print("Area of the triangle is", area)

What does CAST(SUBSTRING()AS INTEGER)=x do?

I am having an exam on SQL which I have rarely ever worked on. While going through the study material I encountered this example:
DELETE FROM table_name WHERE
CAST (SUBSTRING (attribute_name from x for y) AS INTEGER) =z;
Now, I am guessing that this would delete a specific line, where an attribute name would be specified in the code, but am unsure.
The substring() function extracts part of string (from the column attribute_name) from the position numbered x for y characters (or until position x + y - 1). For instance 1 to 3 would be the first three characters.
This is then converted to an integer and compared to another value.
Rows where the comparison returns "true" are deleted.

Repeating numbers with modulo -1 to 1 using positive and negative numbers

Repeating numbers with modulo
I know I can "wrap" / loop numbers back onto themselves like 2,3,1,2,3,1,...
by using modulo.
Example code below.
a=[1:8]'
b=mod(a,3)+1
But how can I use modulo to "wrap" numbers back onto themselves from -1 to 1 (-1,-.5,0,.5,1). Some test numbers would be a=[1.1,-2.3,.3,-.5] it would loop around and the values would be between -1 to 1.
I guess a visual example would be bending an x,y plane from -1 to 1 into a torus (how it loops back onto itself).
I was thinking of how a sin wave goes 0,1,0,-1 and back again but I wasn't sure how I could implement it.
PS: I'm using Octave 4.2.2
This can be accomplished by offsetting the value before taking the modulo, then reversing the offset after.
For example, if the target range is [a,b) (the half-open interval such that b is not part of the interval), then one can do:
y = mod( x - a, b - a ) + a;
For example:
a = -1;
b = 1;
x = -10:0.01:10;
y = mod( x - a, b - a ) + a;
plot(x,y)

Decrypt the message by factoring n or without factoring n in RSA

An RSAcryptosystem has public key n = 18721 and e = 25. Messages are encrypted crypted one letter at a time, converting letters to numbers by A = 2, B = 3 c _ 27. Oscar intercepts the message "365, 18242, 4845, 18242, 17173, 16;134:"" from Alice to Bob.
(la) Decrypt the message by factorizing n.
(lb) Decrypt the message assuming that you cannot factorize n.
can any body teach me too step by step how to decrypt message and also what is p&q
Your questions can be answered by reading the wikipedia page on RSA.
1a
When you factor n, you find integers p and q such that n = p * q. You calculate Y = (p - 1)(q - 1). Then you can find the private key exponent d, which is calculated as d = 1/e mod Y.
To decrypt one of the values c in the intercepted message, you simply calculate m = c^d mod n, where m is the decrypted message. This works because (m^e)^d mod n is equal to 1.
I'll leave the actual calculations to you. If you get stuck, the wiki page has some good examples.
1b
If you cannot factorize n, then you can't decrypt the message. If it were possible to decrypt the message using only the public key (n,e), then why would anyone use RSA?
1a. is answered correctly by the upvoted answer
1b.
Knowing that each message chunk is only 1 character Oscar can encrypt each character of the alphabet with the same e and n and compare them.
a = 2^25 mod 18721 = 6400
b = 3^25 mod 18721 = 18718
c = 4^25 mod 18721 = 17173
...
The upvoted answer is true for encryptions of more than one character but not the case when each character is individually encrypted.
For the 1b approach the phrase Rainbow Table might be revealing (though intentionally somewhat over-specific/misleading).
It was pretty fun. I'll tell you that your 2nd and 4th letters are 'E'; and that I'm pretty sure you typoed the last value (134). It's either 1375 (which makes the most sense to me) or 13444 (the closest string match, and also sort of makes sense).
#bkjvbx's answer is right in the case of RSA as used in the wild; but since this (presumably) homework assignment is using raw RSA on remarkably scoped inputs it's a whole different beast.

search any word inside a string in million rows

I have a set of 50k values say X. each value i want to compare with a set of 10k values say Y. if X is present any where in the string Y it matches.
So each value in X i want to check across each value in Y and assign X if it matches.
what would be the best method to complete this task. It is required for a data mining project.
I loaded the data into MS Access database.
then using a vba program
take each X . Update Y if it matches (Like '%X%') but it is a never ending process. The columns are indexed but no effect.
Is there any algorithm or steps to reduce it into step-by-step process and complete the mapping faster?
Please let me know if there is any other options available other than the answers given below. I ll explain the scenario bit more
Table1.Data
sentense1
sentense2
sentense3
sentense4
sentense5
sentense6
-
-
-
Sentense100k
Table2.Phrase (Means multiple words)
Phrase1
Phrase2
Phrase3
Phrase4
Phrase5
-
-
-
Phrase 100k
Want to check Phrase1 has any Match in Sentense1 to Sentense100k Exact Match of Phrase, anywhere Match of Phrase, Maximum Words in Phrase1 Match in Sentense etc.. and create a map based on best Match(ideally exact phrase available anywhere in the sentense)
Table3 Output
Data Best Possible Phrase Second Best Phrase(Optional)
Sentense1 Phrase1000 Phrase50k
Sentense2 Phrase10 Phrase70k
Please let me know any tool,logic to perform this. The logic what i tried in SQL
1.
Select A.Data,B.Phrase from Table1 A left join Table2 B on A.Data Like '%' + B.Phrase + '%'
2.
Check for any word in phrase available in sentense. So replaced all spaces with % like word1%word2%word3. then did query as
A.Data Like '%' + B.Phrase + '%' which is
A.Data Like '%word1%word2%word3%'
But it takes days to complete the task for this much data.
Any readily usable tools, indexing methods,queries would really help. The answers given below seems too technical for me to adapt. Please guide
You can build a suffix tree in linear time (you can look up suffix trees online), out of the concatenation of all strings in X and Y, with special unique symbols that end each string.
Then for each string Xi in X, you look it up in the suffix tree (linear time in length of Xi) and assign Xi to each string in Y that is somewhere in the subtree rooted at the end of Xi.
This is linear time in the number of strings in Y that Xi is assigned to.
Thus you get an optimal O(N + k) time algorithm, where:
N is the total length of all the strings in X and Y,
and k is the total number of matches between query strings in X and target strings in Y.