How to repeat x, n times? - vim

I need to remove n characters, starting from cursor. I tried to type x10, as to repeat x 10 times. I expected to delete 10 characters starting from cursor location, but that did not happen.
Any idea?

It's 10x, not x10.
Silly chars to ensure there are 30...

Related

baseurl64 buffer decoding

Can someone explain this behavior?
Buffer.from('5d9RAjZ2GCob-86_Ql', 'base64url').toString('base64url')
// 5d9RAjZ2GCob-86_Qg
Please take a close look at the last character l - g
Your string is 18 characters long, With 6 bits encoded in each character it means the first 16 characters represent 96 bits (12 bytes) and the last two represent one byte plus 4 unused bits. Only the first two bits of the last character are significant here. g is 100000, l is 100101. As the last 4 characters are not used, g is just the first choice for the two bits 1 0.
So for any character in the range between g and v, you would get a g when you convert it back to Base64Url.
See https://en.wikipedia.org/wiki/Base64#Base64_table_from_RFC_4648

what will be the dp and transitions in this problem

Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n.
Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can be empty). For example, if he erases substring 111 from string 111110 he will get the string 110. Vasya gets ax points for erasing substring of length x.
Vasya wants to maximize his total points, so help him with this!
https://codeforces.com/problemset/problem/1107/E
i was trying to get my head around the editorial,but couldn't understand it... can anyone tell an easy way to do it?
input:
7
1101001
3 4 9 100 1 2 3
output:
109
Explanation
the optimal sequence of erasings is: 1101001 → 111001 → 11101 → 1111 → ∅.
Here, we consider removing prefixes instead of substrings. Why?
We try to remove a consecutive prefix of a particular state which is actually a substring in the main string. So, our DP states will be start index, end index, prefix length.
Let's consider an example str = "1010110". Here, initially start=0, end=7, and prefix=1(the first '1' will be the only prefix now). we iterate over all the indices in the current state except the starting index and check if str[i]==str[start]. Here, for example, str[4]==str[0]. Now we divide the string into "010" with prefix=1(010) && "110" with prefix=2(1010110). These two are now two individual subproblems. So, when there remains a string with length 1, we return aprefix.
Here is my code.

Need to add 0 to match the length

I have unique identifiers for each row. For example 19Jan187938 or 19Jan206414 but there are some which are like 19Jan17333. I need to add a 0 before the number if it's 5 digits, so it becomes 19Jan017333.
I tried,
=TEXT(CONCATENATE(19,AB2,C2),"000000")
even with 11 0's, since the total length is 11. Nothing changes.
Try the following:
=CONCATENATE(LEFT(AB2,5),TEXT(RIGHT(AB2,LEN(AB2)-5),"000000"))
It will basically, take the first 5 characters and concatenate that with the remaining characters formatted as a six digit number with leading zeroes
If your identifier is on A1, you can try this:
=IF(LEN(A1)<11;CONCATENATE(LEFT(A1;5);RIGHT("000000"&MID(A1;6;5);6));A1)
See what happens.

Round up/off to nearest 5

I'm trying to round up a list of numbers to the nearest 5 and nearest 10.
example:
1562
1706
1665
1378
1439
I created this code to round up/off to nearest 5:
:exe "%s/\\d\\d\\d\\d/\\=substitute(submatch(0).'\\.0', '.*', (round(submatch(0)/5)*5), 'g')/g"
In the first part of the substitution I want to make a float from the submatch value adding .0 to the submatch value.
Expected result:
1560
1705
1665
1380
1440
However, it gives a trailing character error.
What did I wrong?
Since / is present in the replacement string as the division operator, you need to use another delimiter character for the :s command. As per documentation, this can be any other single-byte character, but not an alphanumeric character, '\', '"'' or '|'.
To round a number n to the nearest multiple of k you can do:
(n + k/2) / k * k
Putting this all together, the command can be:
:%s!\v\d{4}!\=(submatch(0) + 2) / 5 * 5!

vim shortcut to traverse the word from right to left

Vim shortcut to traverse the words in forward direction i.e left to right is w / W
What is the shortcut to go in the opposite direction?
Similarly x deletes character on which cursor is there. So continuously pressing it deletes characters from left to right. Is there a shortcut to delete characters from right to left i.e characters before the cursor.
b goes backwards to the previous beginning of a word.
X will delete the character before the cursor
db will delete from the cursor position to the previous beginning of a word (excluding the letter at the cursor). e.g. ([] is the cursor position)
first middle la[s]t " type b
first middle [l]ast " type b again
first [m]iddle last " type db
[m]iddle last
Of course b is just a movement command, so you can tack it on to any command that takes a movement, e.g. cb will cut/change to the beginning of the word, vb will highlight it, etc.

Resources