Find the optimum sequence of keyboard hits to produce the most repeated characters - sequence

You are provided with four possible operations that can be done on the editor (each operation requires one keyboard hit).
A
Ctrl+A
Ctrl+C
Ctrl+V
Now you can hit the keyboard N times and you need to find the maximum number of A's that can be printed. Also print the sequence of keyboard hits.

Googled for the answer:
http://podlipensky.com/post/2011/02/07/Sundays-puzzle.aspx

Off of the top of my head...
A single A followed by iterations of Ctrl+A Ctrl+C Ctrl+V Ctrl+V, where each iteration doubles the size of the text, starting at 1 character, then 2, then 4, then 8, etc.
So given N keystrokes, you can produce at most 2(N-1)/4 characters.
I suspect that this is not the optimal (minimal) number of keystrokes, though. (I have not yet read the answer posted by #David.)

Related

I would like to MOVE just one line in Vim

yy and p should copy and paste 1 line of text.
But I have to go back and delete the original line.
:2,5m10
should move lines from 2 to 5 to line 10. however I need to enable :set number
to see what lines I am moving
I would like to move just 1 line of text, sort of like yy+p and not use :2,3m10
to move just one line.
Is there something like mm+p ?
so it copies the current line into buffer and deletes the line and you p paste it where you want ?
:3m . moves line 3 to your current line.
Above line does the function I want. Can I set a key mapping so
that "mm" replaces ":3m." ? I find it easier to type. TIA
What you're describing is the default behaviour when using dd -it deletes a
line into the buffer and p will paste it.
So dd and p works.
If you're new to vim, then it might seem a little strange that 'yanking' (with
y) and 'deleting' (with d) both copy to the buffer, given the 'cut', 'copy'
and 'paste' behaviours of most other editors.
You can read more about it with :help change.txt and in particular :help registers.
Also, since you say you need to enable :set number, I wonder if you've come
across :set relativenumber? This is very useful - in the example below, the
numbers would look this way if the your cursor was on the line with
'demonstrate':
3 This is just
2 a small
1 example to
0 demonstrate
1 how relative
2 numbers can
3 be useful
Thus if you wanted to move the line 'a small' below the line with 'numbers
can', you could use the relative line numbers to know that 2k would put the
cursor on the line you want, where you'd hit dd, then you'd have this
situation (the deleted line is now in the buffer:
1 This is just
0 example to
1 demonstrate
2 how relative
3 numbers can
4 be useful
Then you can do 3j to move to the 'numbers can' line, and hit p. So
relative numbers are a nice way to move quickly to lines you can see. Also,
just for completeness, you can use relative numbers in a similar way on the
command line::-2m+3 (although I know this isn't what you're after). You can
even set both relative number and set number at the same time, in which case
it's like in the example above, only you have the absolute line number
displayed on the current line instead of a zero.

Fast way of deleting white space from right in Intellij

Say my cursor is at demo.getNamesSatisfyingCondition( line just after ( character. To have the next line (LENGTH_FIVE.and(STARTS_WITH_S), names));) at the same level as demo.getNamesSatisfyingCondition( I need to press several times Del key. Is there a way to do this in a faster way?
It can be done with Ctrl-Shift-J. The function is called join lines.

jEdit in hard word-wrap mode: insert comment character automatically?

Probably quite a niche question, but I believe in the power of a big community: Is it possible to set up jEdit in way, that it automatically inserts a comment character (//, #, ... depending on the edit mode) at the beginning of a new line, if the line before the wrap was a comment?
Sample:
# This is a comment spanning multiple lines. If I continue to type here, it
# wraps around automatically, but I have to manually add a `#` to each line.
If I continue to type after the . the third line should start with the # automatically. I searched in the plugin repository but could not find anything related.
Background: jEdit has the concepct of soft and hard wrap. While soft wrap only breaks lines visually at a character limit, it does not insert line breaks in the file. Hard wrap on the other hand inserts \n into the file at the desired character count.
This is not exactly what you want: I use the macros Enter_with_Prefix.bsh to automatically insert the prefix (e.g., #, //) at the beginning of the new line.
Description copied from Enter_with_Prefix.bsh:
Enter_with_Prefix.bsh - a Beanshell macro for jEdit
that starts a new line continuing any recognized
sequence that started the previous. For example,
if the previous line beings with "1." the next will
be prefixed with "2.". It supports alpha lists (a., b., etc...),
bullet lists (+, =, *, etc..), comments, Javadocs,
Java import statements, e-mail replies (>, |, :),
and is easy to extend with new sequence types. Suggested
shortcut for this macro is S+ENTER (SHIFT+ENTER).

Finding the ascii value for shift-in shift-out in sql?

I've some records which are really messed up.
My team lead told me to find out the position of characters with ascii value 14 and 15.
I've a query
SELECT CHARINDEX(CHAR(14),X_CUSTOMER_COMMENTS)
FROM vp_service_requests;
SELECT CHARINDEX(CHAR(15),X_CUSTOMER_COMMENTS)
FROM vp_service_requests;
which returns 0 because i wasn't able to find char with 14 and 15 ascii value after google
search i found 14 and 15 ascii value are for shift in and shift out
how this represents on keyboard so i can try for it with CHAR(14) function.
As a holdover from the old DOS days, Windows still allows you to enter certain old ASCII keys from the keyboard by pressing and holding the ALT key, followed by the three-digit code you wish to enter (from the 10-key pad, not the numeric row atop the keyboard), eg for 14, type ALT-014.
However, some of the lower-level codes are inherited from old terminal functions, eg ASCII 7 is a bell, 8 is a backspace, eg, and rather that typing a character, they cause the cursor to behave a certain way or induce an application to respond in a defined manner. You can embed a CHAR(XX) value for testing simply by concatenating the value into a string and INSERTing it into your test table.
It should be Ctrl-N and Ctrl-O although I doubt this will help.
Try loading the records into a good editor and look at them in HEX. Weird characters should stick out like a sore thumb

Why is there a convention of 1-based line numbers but 0-based char numbers?

According to TkDocs:
The "1.0" here represents where to insert the text, and can be read as "line 1, character 0". This refers to the first character of the first line; for historical conventions related to how programmers normally refer to lines and characters, line numbers are 1-based, and character numbers are 0-based.
I hadn't heard of this convention before, and I can't find anything relevant on Google. Can anyone explain this to me please?
I think you're referring to Tk's text widget. The man page says:
Lines are numbered from 1 for consistency with other UNIX programs that use this numbering scheme.
Although, I'm not sure which Unix tools it's talking about.
Update:
As mentioned in the comments, it looks like a lot of unix text manipulation tool starts line numbering at 1. And tcl/tk having a unix origin, it makes sense to be as compatible as possible with the underlying OS environment.
It really is nothing more than convention, but here is a suggestion.
Character positions are generally thought of in the same way as a Java iterator, which is a "pointer" to a position between two characters. Thus the first character is the one after index position 0. Substrings are taken between two inter-character positions, for instance.
Line positions on the other hand are generally thought of more in the way of a .NET enumerator, which is a "pointer" to the item itself, not to a position in between. Thus the first line is the line at position 1.