In this AutohotKeys code, how to have each text-line of each list in its own line, instead of having all of them together in the same single line - autohotkey

I have this Autohotkeys code to randomly choose one line of text from each of the three lists of text-lines within the same file, and copy them together to the clipboard.
It works perfectly fine, but it is not practical to add new lines of long text to the code.
So I wonder if it is possible editing it to have each text-line in its own separated line in the code, instead of having all text-lines of each list in one single line, as it is right now.
For instance instead of having each list like this:
list = 1st text-line,2nd text-line,3rd text-line,4th text-line
better have them similar to something like this:
list =
1st text-line,
2nd text-line,
3rd text-line,
4th text-line
I've tried several options I know, but all I get are blank lines.
This is my current code:
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 = 1st text-line,2nd text-line,3rd text-line,4th text-line
list2 = 5th text-line,6th text-line,7th text-line,8th text-line
list3 = 9th text-line,10th text-line,11th text-line,12th text-line
; Selecting randomly one text-line from each list:
selectedLine1 := strsplit(list1,",")[rand1]
selectedLine2 := strsplit(list2,",")[rand2]
selectedLine3 := strsplit(list3,",")[rand3]
; Concatenating the 3 selected text-lines and copy them to the clipboard:
clipboard = %selectedLine1%`n%selectedLine2%`n%selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%
My AutoHotkey is version 1.1.36.02 . Thanks in advance for your help.

This is the solution:
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 =
(
1st text-line
2nd text-line
3rd text-line
4th text-line
)
list2 =
(
5th text-line
6th text-line
7th text-line
8th text-line
)
list3 =
(
9th text-line
10th text-line
11th text-line
12th text-line
)
; Selecting randomly one text-line from each list:
selectedLine1 := strsplit(list1,"`n")[rand1]
selectedLine2 := strsplit(list2,"`n")[rand2]
selectedLine3 := strsplit(list3,"`n")[rand3]
; Concatenating the 3 selected text-lines and copy them to the clipboard:
clipboard = %selectedLine1%`n%selectedLine2%`n%selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%

Related

Randomly choose 1 text-line from each of 3 lists of text-lines but instead it brings 3 blank text-lines

I have this code to randomly choose one line of text from each of the three lists of text lines within the same file, and copy them together to the clipboard.
It works but not properly because it brings three blank lines instead of three actual text lines.
It seems to me that the issue may be in the way this code is copying the text lines, but I'm not an expert.
Can somebody help me find where the issue is and maybe code it properly to bring the actual text lines instead of the blank ones?
My AutoHotkey is version 1.1.36.02 . Thanks in advance to everyone.
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 = 1st text line, 2nd text line, 3rd text line, 4th text line
list2 = 5th text line, 6th text line, 7th text line, 8th text line
list3 = 9th text line, 10th text line, 11th text line, 12th text line
; Selecting randomly one text line from each list:
selectedLine1 := list1[rand1]
selectedLine2 := list2[rand2]
selectedLine3 := list3[rand3]
; Concatenating the 3 selected text lines and copy them to the clipboard:
clipboard = %selectedLine1% `n %selectedLine2% `n %selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%
This solves the problem:
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 = 1st text line, 2nd text line, 3rd text line, 4th text line
list2 = 5th text line, 6th text line, 7th text line, 8th text line
list3 = 9th text line, 10th text line, 11th text line, 12th text line
; Selecting randomly one text line from each list:
selectedLine1 := strsplit(list1,",")[rand1]
selectedLine2 := strsplit(list2,",")[rand2]
selectedLine3 := strsplit(list3,",")[rand3]
; Concatenating the 3 selected text lines and copy them to the clipboard:
clipboard = %selectedLine1% `n %selectedLine2% `n %selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%

Brainfuck challenge

I have a any challenge. I must write brainfuck-code.
For a given number n appoint its last digit .
entrance
Input will consist of only one line in which there is only one integer n ( 1 < = n < = 2,000,000,000 ) , followed by a newline ' \ n' (ASCII 10).
exit
On the output has to find exactly one integer denoting the last digit of n .
example I
entrance: 32
exit: 2
example II:
entrance: 231231132
exit: 2
This is what I tried, but it didn't work:
+[>,]<.>++++++++++.
The last input is the newline. So you have to go two memory positions back to get the last digit of the number. And maybe you don't have to return a newline character, so the code is
,[>,]<<.
Nope sorry, real answer is
,[>,]<.
because your answer was getting one too far ;)
Depending on the interpreter, you might have to escape the return key by yourself. considering the return key is ASCII: 10, your code should look like this :
>,----- -----[+++++ +++++>,----- -----]<.
broken down :
> | //first operation (just in case your interpreter does not
support a negative pointer index)
,----- ----- | //first entry if it's a return; you don't even get in the loop
[
+++++ +++++ | //if the value was not ASCII 10; you want the original value back
>, | //every next entry
----- ----- | //check again for the the return,
you exit the loop only if the last entered value is 10
]
<. | //your current pointer is 0; you go back to the last valid entry
and you display it
Your issue is that a loop continues for forever until at the end of the loop the cell the pointer is currently on in equal to 0. Your code never prints in the loop, and never subtracts, so your loop will never end, and all that your code does is take an ASCII character as input, move one forward, take an ASCII character as input, and so on. All of your code after the end of the loop is useless, because that your loop will never end.

Delete first two characters of an alphanumeric sequence in a column

I'm trying to scan a column for character size. If the alphanumerical character size is met (qty 12), then the first two characters will be deleted. They will always be specific numbers (10). See below.
H063088955
F243066424
10G403085387
F253066457
E473057375
G503087343
10H303098124
G093075912
G433084322
10G403085388
Select the cells you wish to process and run:
Sub qwerty()
For Each r In Selection
v = r.Text
If Len(v) = 12 Then
r.Value = Mid(v, 3)
End If
Next r
End Sub

Remove last n characters of string after the dot with Autohotkey

I am using Autohotkey.
I have a string that looks like this S523.WW.E.SIMA. I want to remove the last few characters of the string after the dot (including the dot itself). So, after the removal, the string will look like S523.WW.E.
This may look like a simple question but I just cannot figure out using the available string functions in Autohotkey. How can this be done using Autohotkey? Thank you very much.
Example 1 (last index of)
string := "S523.WW.E.SIMA"
LastDotPos := InStr(string,".",0,0) ; get position of last occurrence of "."
result := SubStr(string,1,LastDotPos-1) ; get substring from start to last dot
MsgBox %result% ; display result
See InStr
See SubStr
Example 2 (StrSplit)
; Split it into the dot-separated parts,
; then join them again excluding the last part
parts := StrSplit(string, ".")
result := ""
Loop % parts.MaxIndex() - 1
{
if(StrLen(result)) {
result .= "."
}
result .= parts[A_Index]
}
Example 3 (RegExMatch)
; Extract everything up until the last dot
RegExMatch(string, "(.*)\.", result)
msgbox % result1
Example 4 (RegExReplace)
; RegExReplace to remove everything, starting with the last dot
result := RegExReplace(string, "\.[^\.]+$", "")

How to efficiently transpose rows into columns in Vim?

I have a data file like the following:
----------------------------
a b c d e .............
A B C D E .............
----------------------------
But I want it to be in the following format:
----------------------------
a A
b B
c C
d D
e E
...
...
----------------------------
What is the quickest way to do the transformation in Vim or Perl?
Basically :.s/ /SpaceCtrl+vEnter/gEnterjma:.s/ /Ctrl+vEnter/gEnterCtrl+v'axgg$p'adG will do the trick. :)
OK, let's break that down:
:.s/ /Ctrl+vEnter/gEnter: On the current line (.), substitute (s) spaces (/ /) with a space followed by a carriage return (SpaceCtrl+vEnter/), in all positions (g). The cursor should now be on the last letter's line (e in the example).
j: Go one line down (to A B C D E).
ma: Set mark a to the current position... because we want to refer to this position later.
:.s/ /Ctrl+vEnter/gEnter: Do the same substitution as above, but without the Space. The cursor should now be on the last letter's line (E in the example).
Ctrl+v'a: Select from the current cursor position (E) to mark a (that we set in step 3 above), using the block select.
x: Cut the selection (into the " register).
gg: Move the cursor to the first line.
$: Move the cursor to the end of the line.
p: Paste the previously cut text after the cursor position.
'a: Move the cursor to the a mark (set in step 3).
dG: Delete everything (the empty lines left at the bottom) from the cursor position to the end of the file.
P.S. I was hoping to learn about a "built-in" solution, but until such time...
Simple re-map of the columns:
use strict;
use warnings;
my #a = map [ split ], <>; # split each line on whitespace and store in array
for (0 .. $#{$a[0]}) { # for each such array element
printf "%s %s\n", $a[0]->[$_], $a[1]->[$_]; # print elements in order
}
Usage:
perl script.pl input.txt
Assuming that the cursor is on the first of the two lines, I would use
the command
:s/ /\r/g|+&&|'[-;1,g/^/''+m.|-j