18
\$\begingroup\$

Here is an easy-intermediate challenge for anyone interested!

What is that?

A thing me and brother do a bit too often is this:

One of us has a problem and asks the other to explain how to do certain stuff. The other just says the following carelessly:

How to <verb> in <n> easy steps!
                                   (Newline mandatory)
Step 1 - Do not <verb>.
Step 2 - Do not <verb>.
Step 3 - Do not <verb>.
.
.
.
Step <n> - <verb>.                 (Capitalised)

For example, if my brother could not find a pen to write with (Do not ask me why) and asked How do I find a pen?, I would probably answer:

How to find a pen in 10 easy steps!

Step 1 - Do not find a pen.
Step 2 - Do not find a pen.
Step 3 - Do not find a pen.
Step 4 - Do not find a pen.
Step 5 - Do not find a pen.
Step 6 - Do not find a pen.
Step 7 - Do not find a pen.
Step 8 - Do not find a pen.
Step 9 - Do not find a pen.
Step 10 - Find a pen.

Sarcasm alert!
Now isn't that so accurate and helpful!

<verb> is the problem one of us wants to achieve.

<n> is a random number that we choose (for your information, we mostly use 10 as <n>, but that is not important for this challenge).

So what?

Your challenge is to write a usual program or function using standard I/O and golfing rules that takes in a string formatted with "How do I <v>?" as input, and then print or return the (accurate) how-to article specified according to the rules displayed above, where <verb> is <v> from the input, and <n> is any random natural number from the range 1 to 10 (inclusive) generated by your program. When <n> is 1, remove the ending s in ...steps!.

Standard loopholes are not allowed!


Note: There might be some cases where sentences will be illogical, like in the case of How do I find my pen?. Outputting How to find my pen in <n> easy steps is fine!


Here is another example for further clarity:

Input -

How do I make coffee?

Example output -

How to make coffee in 3 easy steps!

Step 1 - Do not make coffee.
Step 2 - Do not make coffee.
Step 3 - Make coffee.

Good luck!

\$\endgroup\$
15
  • 1
    \$\begingroup\$ Can we assume that <verb> will always start with a lowercase letter? \$\endgroup\$
    – Gymhgy
    Oct 15, 2020 at 18:35
  • 7
    \$\begingroup\$ @SunnyMoon Oh well, that renders all existing answers wrong. \$\endgroup\$
    – Adám
    Oct 15, 2020 at 19:42
  • 3
    \$\begingroup\$ I don't think the randomness adds anything to the challenge. Taking a number as input would have made much more sense. \$\endgroup\$
    – Sisyphus
    Oct 16, 2020 at 5:18
  • 2
    \$\begingroup\$ @Sisyphus I have not seen much a challenge involving random numbers in CGCC, so I thought I would make one! \$\endgroup\$
    – SunnyMoon
    Oct 16, 2020 at 5:37
  • 2
    \$\begingroup\$ @Sisyphus In real life, though, the only input one sibling would take is the verb, and they'd randomly decide how many steps to use :) \$\endgroup\$
    – user
    Oct 21, 2020 at 15:23

23 Answers 23

14
\$\begingroup\$

LaTeX, 269 bytes

\input tikz.tex\let\s\pgfmathsetmacro\pgfmathsetseed{\number\pdfrandomseed}\def\u#1{\uppercase{#1}}\def\f
How do I #1?{\s\n{random(0,9)}\s\m{int(\n+1)}How to #1 in \m~easy
step\ifnum\m>1s!\\\\\foreach\i in{1,...,\n}{Step \i~- Do not #1.\\}\else!\\\\\fi
Step \m~- \u#1.}

Random numbers aren't very nice to handle in LaTeX.

Example output:

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ I always suspected that LaTeX code is ment for golfing rather than actually working with it. :) \$\endgroup\$ Oct 18, 2020 at 12:37
9
\$\begingroup\$

Bash + coreutils seq, 128

  • Thanks to @NahuelFouilleul for some good golfing suggestions.
v=${1:9}
v=${v%?}
s=s
echo "How to $v in $[m=(n=$$%10)+1] easy step${s::n}!

`seq -f"Step %g - Do not $v." $n`
Step $m - ${v^}."

Try it online!

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I'm just trying to imagine a How to article with 32767 steps. "Do not find a pen, Do not find a pen, Do not find a pen ... And finally, find a pen!" \$\endgroup\$
    – user
    Oct 15, 2020 at 18:46
  • \$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$
    – Adám
    Oct 15, 2020 at 19:55
  • 2
    \$\begingroup\$ What does ${$: -1} do? \$\endgroup\$
    – corvus_192
    Oct 15, 2020 at 21:21
  • 2
    \$\begingroup\$ $$ is a variable containing the PID of bash interpreter. The ${varname: -1} expansion gives the last character of the variable. So here the last digit of the PID is used as the "random" number. \$\endgroup\$ Oct 15, 2020 at 21:29
  • \$\begingroup\$ 9 bytes could be saved \$\endgroup\$ Oct 16, 2020 at 20:24
6
\$\begingroup\$

APL (Dyalog Extended), 99 bytes

Full program. Prompts for string from stdin.

∊'How to'(¯1↓v←8↓⌽'.'@1⌽⍞)' in'n'easy step','s!'↓⍨1=n←?10
⍬
{∊'Step'⍵'- Do not'v}⍤0⍳n-1
∊'Step'n'-',⌈@2⊢v

Try it online!

ϵnlists (flattens) the list of components of each line. By default, numbers are printed with one spaces between them and adjacent text. Lines are implicitly printed.

The variable parts are:

,'s!'↓⍨1=n←?10

?10 random number in range 1–10
n← assign to n
1= is 1 equal to that? (1 if yes, 0 if no)
's!'↓⍨ drop that many characters from "s!"
, prepend the additional components on the left

¯1↓v←8↓⌽'.'@1⌽⍞

 prompt for string
 reverse
'.'@1 replace the character at index 1 with a period.
 reverse
8↓ drop the first 8 characters ("How do I")
v← assign to v
¯1↓ drop the last character (".")

 empty numeric list (prints as empty line)

{}⍤0⍳n-1

n-1 subtract 1 from n
 indices 1–(n−1)
{}⍤0 merge into a matrix the results from applying the following lambda on each element:
 the argument (current index)

'Step'n'-',⌈@2⊢v

⊢v on v
⌈@2 uppercase the second character (there's a leading space in v)
, prepend the components

\$\endgroup\$
6
\$\begingroup\$

C (gcc), 186 bytes

n;f(m){char*s;scanf("%m[^?]",&s);for(printf("How to%s in %d easy step%s!\n\n",memcpy(++s," Do not",7)+7,m=++n,"s"+!(n=time()%10));n--;printf("Step %d -%s.\n",m-n,(n||(1[s+=7]^=32),s)));}

Try it online!

+14 bytes due to removing the last s in ...steps! when n=1

-2 bytes by using lseek

-2 bytes by changing conditions

-1 byte by removing a space m- --nm-n--

-3 bytes thanks to Arnauld

-1 byte by changing the last condition from n+1 to !n

-31 bytes thanks to ErikF

-2 bytes by removing s in %m[^?]s and by removing space in "Do not "

-2 bytes thanks to ceilingcat

-1 byte thanks to ErikF

\$\endgroup\$
5
  • 1
    \$\begingroup\$ There are two newlines after ...steps!. \$\endgroup\$
    – SunnyMoon
    Oct 15, 2020 at 20:11
  • 2
    \$\begingroup\$ You can use "s"+!n instead of n?"s":"". \$\endgroup\$
    – Arnauld
    Oct 15, 2020 at 22:47
  • 1
    \$\begingroup\$ You can use How to%s and (b=a)+6. \$\endgroup\$
    – Arnauld
    Oct 15, 2020 at 22:55
  • 1
    \$\begingroup\$ You can save 31 bytes by having scanf give you an allocated string (and also stop at the question mark), and then overwriting the first bit, and reordering the initializations a bit; also golf submissions don't have to be complete programs: Try it online! \$\endgroup\$
    – ErikF
    Oct 16, 2020 at 3:50
  • 1
    \$\begingroup\$ 186 bytes by using the interesting subscripting feature that C has where a[1] == 1[a] \$\endgroup\$
    – ErikF
    Oct 22, 2020 at 1:07
6
\$\begingroup\$

Ruby -p, 141 140 137 131 bytes

Saved 3 bytes by using $$%10 instead of rand(10), a golf suggested by @NahuelFouilleul in comments on other answers.

$_="How to #{v=$_[9..-2]} in #{n=1+$$%10} easy ste#{:ps[0,n]}!
"+(1..n).map{|i|"
Step #{i} - #{i<n ?'Do not '+v:v.capitalize}."}*''

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ I got most of the plain parts, but I'm wondering what did you meant by $_, and I tried to replace it by some var v, which gave error :P \$\endgroup\$
    – vrintle
    Nov 21, 2020 at 15:11
  • 1
    \$\begingroup\$ @vrintle You'll often see $_/-p in Ruby/Perl golf because they basically let us read and print strings for free. $_ is a predefined global variable (inherited from Perl) that is automatically set to the last line read by gets or readline. The -p command-line flag causes the code to be wrapped in a while gets; ...; print $_; end loop. If ... is empty you have a cat program: each line from STDIN is printed to STDOUT. The fun starts when you use ... to modify $_ so it prints something different from what was read in. \$\endgroup\$
    – Dingus
    Nov 22, 2020 at 0:28
  • \$\begingroup\$ And, how does this works? Even, we've not specified $_. But, when I write just upcase in code, it gives error... Strange! \$\endgroup\$
    – vrintle
    Nov 30, 2020 at 10:11
  • 1
    \$\begingroup\$ @vrintle See this tip. In -p mode, sub operates on $_ if there is no explicit receiver. Note that you have specified $_ in your example: it's try it Online, read automatically from STDIN into $_ thanks to -p. \$\endgroup\$
    – Dingus
    Nov 30, 2020 at 10:28
  • \$\begingroup\$ (@vrintle I should mention a subtle gotcha: receiverless sub in -p mode modifies $_ in place if substitution occurs. In other words, it behaves differently from $_.sub, which performs substitutions on a copy of $_ and leaves $_ itself unchanged.) \$\endgroup\$
    – Dingus
    Nov 30, 2020 at 11:30
5
\$\begingroup\$

Scala, 195 188 bytes

q=>{val(r,s"How do I $v?")=(math.random*10).toInt+1->q
1 to r-1 map{i=>s"Step $i - Do not $v."}mkString(s"How to $v in $r easy ste${"ps"take r}!\n\n","\n",s"\nStep $r - ${v.capitalize}.")}

Here it is in Scastie, but double newlines don't work there for whatever reason.

Equivalent version with newlines in TIO (modified for Scala 2.10)

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Nice use of the string pattern match. \$\endgroup\$
    – corvus_192
    Oct 15, 2020 at 19:01
  • 1
    \$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$
    – Adám
    Oct 15, 2020 at 19:55
  • 1
    \$\begingroup\$ You can save 4 bytes with "s"take(r-1) \$\endgroup\$
    – corvus_192
    Oct 15, 2020 at 20:52
  • 2
    \$\begingroup\$ Even better, use "ps"take r \$\endgroup\$
    – corvus_192
    Oct 15, 2020 at 20:54
  • 1
    \$\begingroup\$ I thought the bytecount is one too high, so I thought you counted a newline after the last }, but it's correct now. \$\endgroup\$
    – corvus_192
    Oct 15, 2020 at 21:05
5
\$\begingroup\$

JavaScript (ES6), 159 bytes

s=>(g=i=>i?g(i-1)+`
Step ${i} - ${i-n?'Do not'+s:s[1].toUpperCase()+s.slice(2)}.`:`How to${s=s.slice(8,-1)} in ${n} easy step${n>1?'s':''}!
`)(n=new Date%10+1)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$
    – Adám
    Oct 15, 2020 at 19:55
  • \$\begingroup\$ @Adám Thank you for the notification. Updated. \$\endgroup\$
    – Arnauld
    Oct 15, 2020 at 22:37
5
\$\begingroup\$

C# (Visual C# Interactive Compiler), 180 bytes

s=>{int y=new Random().Next(10)+1,i=0;for(Write($"How to{s=s[8..^1]} in {y} easy step{(y<2?"":"s")}!\n");i++<y;)Write($"\nStep {i} - {(i<y?$"Do not"+s:(char)(s[1]^32)+s[2..])}.");}

-1 byte thanks to Dominic van Essen

+13 bytes due to having to remove the "s" in steps if the random number = 1.

-2 bytes due to Julian

-2 bytes due to Neil

Try it online!

\$\endgroup\$
7
  • \$\begingroup\$ Your program needs to print two newlines after ...<n> easy steps!. \$\endgroup\$
    – SunnyMoon
    Oct 15, 2020 at 18:33
  • \$\begingroup\$ @SunnyMoon Fixed \$\endgroup\$
    – Gymhgy
    Oct 15, 2020 at 18:34
  • \$\begingroup\$ -1 byte by reversing ?: order: try it \$\endgroup\$ Oct 15, 2020 at 19:32
  • \$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$
    – Adám
    Oct 15, 2020 at 19:55
  • 1
    \$\begingroup\$ @Julian Coincidentally, I was experimenting with that concept earlier before I modified it from substrings and remove to ranges. Your comment just made me revisit it and save 2 bytes. Thanks! \$\endgroup\$
    – Gymhgy
    Oct 16, 2020 at 3:02
4
\$\begingroup\$

PowerShell Core, 188 bytes

$q=$args.Substring(8,"$args".Length-9)
$r=(Random 10)+1
"How to$q in $r easy step$(('s','')[$r-eq1])!`n"
1..$r|%{"Step $_ - "+("Do not$q.","$($q[1]|% t*g|% tou*t)$($q|% s*g 2).")[$_-eq$r]}

Line by line

  1. Isolates the task make coffee with the initial space
  2. Generates a random number in the range 1..10
  3. Prints the title with an extra new line and the conditional s
  4. Prints the steps
{"Step $_ - "
+("Do not$q.", # if it is not the last line
"$($q[1]|% t*g|% tou*t)$($q|% s*g 2))." # if if is the last line, first char uppercase and the rest of the string
)[$_-eq$r]} # "is it the last line" condition

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ nice. thanks. you can save some bytes. Try it online! \$\endgroup\$
    – mazzy
    Oct 18, 2020 at 8:05
4
\$\begingroup\$

CJam, 92 bytes

"How to "q9>);:Q" in "Amr):T" easy step"T1>'s*'!NT{"
Step "U)" - "T(U=!"do not "*Q+(eu\'.}fU

Try it online!

\$\endgroup\$
4
\$\begingroup\$

C (gcc), 194 193 192 190 189 bytes

Thanks to Petr Fiedler, Neil and ceilingcat for the suggestions.

By using the method in Petr Fiedler's answer, I don't have to use counted strings and store the first character. I've never used sscanf to create a copy of a string before, but it really works well. (Not needed here, but another neat thing about using the scanf family to get a string is that you can use the %n specifier to get the string length at the same time!)

i,j;f(char*s){sscanf(s,"%m[^?]",&s);for(printf("How to%s in %d easy step%s!\n",memcpy(s+=2,"Do not",6)+6,i=++j,"s"+!(j=time(0)%10));i--;printf("\nStep %d - %s.",j-i,(i||(*(s+=7)^=32),s)));}

Try it online!

Original method: 194 bytes

So that I don't have to copy the string to uppercase the first character, I grab the first character of the phrase and then adjust the start of the string to the character after that. I then print up to the character just before the question mark to complete the phrase.

i,j,l,c;f(char*s){for(c=*(s+=9),printf("How to %c%.*s in %d easy step%s!\n\n",c,l=strlen(++s)-1,s,i=++j,"s"+!(j=time(0)%10));i--;printf("Step %d - %s%c%.*s.\n",j-i,i?"Do not ":"",c-32*!i,l,s));}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ You can save 1 byte by dropping the last space in "Do not ". You don't copy it anyway. \$\endgroup\$ Oct 17, 2020 at 2:59
  • \$\begingroup\$ You can save 2 bytes by printing a \n before Step, which avoids two of the other three uses. \$\endgroup\$
    – Neil
    Oct 18, 2020 at 19:14
  • \$\begingroup\$ Suggest mempcpy(s+=2,"Do not",6) instead of memcpy(s+=2,"Do not",6)+6 \$\endgroup\$
    – ceilingcat
    Jun 12, 2022 at 8:51
3
\$\begingroup\$

Python 2, 157 bytes

x=input()[9:-1]
n=id(0)%19/2+1
i=1
print'How to %s in %d easy ste%s!\n'%(x,n,'ps'[:n])
exec"print'Step %d -'%i,('Do not %s.'%x)[i/n*7:].capitalize();i+=1;"*n

Try it online!

id(0)%19/2+1 is not uniform, but it has a nonzero chance of giving each number, unlike id(0)%10+1.

\$\endgroup\$
3
\$\begingroup\$

Perl 5 -n, 129 bytes

chop;/I /;say"How to $' in ",$b=0|1+rand 10," easy step",'s'x($b>1),"!
";say"Step $_ - ",ucfirst"Do not "x($b>$_).$',"."for 1..$b

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ The number of steps should be randomly generated by the program. \$\endgroup\$
    – SunnyMoon
    Oct 15, 2020 at 20:12
  • \$\begingroup\$ @SunnyMoon Changed to a random number of steps. \$\endgroup\$
    – Xcali
    Oct 16, 2020 at 5:00
  • \$\begingroup\$ 124 bytes \$\endgroup\$ Oct 16, 2020 at 20:21
3
\$\begingroup\$

Charcoal, 89 85 82 80 bytes

≔✂S⁹±¹¦¹θ≔‽χηHow to θ in I⊕η easy step∧ηs¦!⸿F⊕η«⸿Step I⊕ι - ⭆⁺×Do not ‹ιηθ⎇λκ↥κ.

Try it online! Link is to verbose version of code. This feels far too long. Explanation:

≔✂S⁹±¹¦¹θ

Extract the verb from the input.

≔‽χη

Get a random number from 0 to 9, which represents the number of "Do not"s.

How to θ in I⊕η easy step∧ηs¦!⸿

Print the header, but only output the s if the random number wasn't 0 (1 step).

F⊕η«

Repeat for each step.

⸿Step I⊕ι - 

Start a new line and print the part common to each step. (For the first step this double-spaces the list of steps from the header.)

⭆⁺×Do not ‹ιηθ⎇λκ↥κ

Except for the last step, prefix Do not to the verb. Uppercase the first letter of the result.

.

Finish the step with a ..

\$\endgroup\$
0
3
\$\begingroup\$

Python 3, 160 170 168 167 bytes

p=print
a=input()[9:-1]
n=id(a)%99%10+1
s="Step %d - %%s."
p(f"How to {a} in {n} easy ste{'ps'[:n]}!\n")
for i in range(1,n):p(s%i%f"Do not {a}")
p(s%n%a.capitalize())

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ It seems my id()-based RNG only generates odd numbers (on cpython at least), too. I'm guessing that invalidates the solution. Are there any rules that the RNG has to be uniform? \$\endgroup\$
    – Kyuuhachi
    Oct 15, 2020 at 20:02
  • \$\begingroup\$ Because of memory alignment on most OSes, id(0)%10+1 will always be odd, but you can try something like id(0)%19/2+1. It's not uniform, but at least each number has a nonzero probability. \$\endgroup\$
    – Sisyphus
    Oct 16, 2020 at 1:56
  • \$\begingroup\$ This answer is invalid as written because "random" requires each value to have a non-zero probability of occuring, but @Sisyphus ' tweak would be valid with respect to the definition of "random" since uniformity is not required (per the same meta post). \$\endgroup\$ Oct 18, 2020 at 19:15
  • \$\begingroup\$ However, even with Sisyphus' tweak, this answer is invalid as a non-reusable function, because if you give if the same string in the same execution it always produces the same output. This is inherent to id-based randomization, and the only fix I can think of is turning this answer into a full program instead of a function. \$\endgroup\$ Oct 18, 2020 at 19:18
  • 1
    \$\begingroup\$ Turning it into a full program actually saved a couple of bytes. Seems not even id([]) works for randomness, probably because the GC makes it allocate the same memory each time. \$\endgroup\$
    – Kyuuhachi
    Oct 18, 2020 at 21:08
3
\$\begingroup\$

05AB1E, 74 bytes

TLΩÐD≠'s×sI8.$¨©“€ß€„ÿ€† ÿ‡šŠ¥ÿ!
“ˆG®N“Š¥ ÿ - Do€–ÿ.“ˆ}®™s“Š¥ ÿ -ÿ.“ˆ¯.ª»

Try it online.

Explanation:

TL                   # Push a list in the range [1,10]
  Ω                  # Pop and push a random value from this list
   ÐD                # Triplicate + Duplicate, so 4 copies are on the stack
     ≠               # Check if the top copy is NOT equal to 1 (0 if 1; 1 if [2,10])
      's×           '# Repeat "s" that many times
         s           # Swap so one random integer copy is at the top again
          I          # Push the input
           8.$       # Remove the first 8 characters ("How do I")
              ¨      # Remove the last character ("?")
               ©     # Store this verb in variable `®` (without popping)
“€ß€„ÿ€† ÿ‡šŠ¥ÿ!\n“  # Push dictionary string "how toÿ in ÿ easy stepÿ!\n",
                     # where the `ÿ` are filled with the top three values on the stack
                     # from left to right
                   ˆ # Pop and add this string to the global_array
G                    # Pop another random copy, and loop `N` in the range [1, n):
 ®                   #  Push the verb from variable `®`
  N                  #  Push `N`
   “Š¥ ÿ - Do€–ÿ.“   #  Push dictionary string "step ÿ - Do not ÿ.",
                     #  where the `ÿ` are filled with the top two values again
                  ˆ  #  Pop and add this string to the global_array
}                    # After the loop:
 ®                   # Push the verb again
  .ª                 # Sentence capitalize it
    s                # Swap so another random integer copy is at the top of the stack
     “Š¥ ÿ -ÿ.“      # Push dictionary string "step ÿ - ÿ.",
                     # where the `ÿ` are once again filled automatically
               ˆ     # Pop and push this string to the global_array as well
¯                    # Then push the global_array
 .ª                  # Sentence capitalize each string (without changing existing caps)
   »                 # And join this list by newlines
                     # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why “€ß€„ÿ€† ÿ‡šŠ¥ÿ!\n“ is "how toÿ in ÿ easy stepÿ!\n"; “Š¥ ÿ - Do€–ÿ.“ is "step ÿ - Do not ÿ."; and “Š¥ ÿ -ÿ.“ is "step ÿ - ÿ.".

\$\endgroup\$
1
  • \$\begingroup\$ Another stack based language beats the stack based language. Nice. \$\endgroup\$
    – Razetime
    Oct 16, 2020 at 10:09
3
\$\begingroup\$

Notepad++, 147 keystrokes

<Enter><Enter>
i<Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-Shift-End><Ctrl-D><Left><Left><Ctrl-Shift-End>
<Alt-E><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Right>r
<Right><Enter><Ctrl-F>i$<Enter><Esc><Ctrl-Shift-End><Del>
<Ctrl-G>3<Enter>
<Alt-E><Alt-C><Alt-N><Ctrl-A>1<Tab>1<Enter>
<Ctrl-H><Space>?I$<Tab><Del><Alt-A><Esc>
<Ctrl-End><Shift-Up><Ctrl-C>
<Ctrl-Home><End><Backsp><Ctrl-V><Space>easy<Space>steps!
<Left><Ctrl-Left><Up><Ctrl-Right><Shift-End><Ctrl-C>
<Ctrl-H>\d+$<Tab>Step<Space>$0<Space>-<Space><Ctrl-V>.<Alt-A>
-(.+\r)<Tab>- Do not$1<Alt-A>
(1<Space>.+p)s<Tab>$1<Alt-A><Esc>
<Right><Del><Space>in<Space><Home><Ctrl-Right><Del>t<Ctrl-Right><Del><Del>
<Ctrl-End><Shift-Home><Ctrl-Shift-Right><Ctrl-Alt-Shift-U>

(Newlines inserted only for ease of reading.)

Caveats

This solution requires version 7.9 of Notepad++ (at the time of writing, the most recent version), which added keyboard shortcuts to the Column Editor window.

The solution expects:

  • the question text to be in the buffer with the cursor at the end and no trailing newline;
  • the file to use Windows line endings;
  • the Replace dialog to have the following settings: Regular expression search ON, match whole word OFF, match case ON;
  • the Column Editor dialog to have the following settings: repeat BLANK, decimal format ON;
  • and the Go To dialog to be in Line mode.

I believe all of these restrictions can be worked around, at the cost of extra keystrokes.

How??

<Enter><Enter>

Add a couple of newlines after the question text.

i<Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-Shift-End><Ctrl-D>

Insert an i on the bottom blank line, and then use CtrlDuplicate to make it 9 lines, each containing a single i.

<Left><Left><Ctrl-Shift-End>

Select those lines.

<Alt-E><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Right>r

Open the Edit menu, go down to the Convert Case submenu, and select ranDOm CasE.

(As far as I know, this is the only source of randomness in Notepad++. I have no idea why it's even in there, but it's there, so we're gonna use it.)

We now have nine lines each containing either i or I at random.

<Right><Enter>

Add a blank line at the end.

<Ctrl-F>i$<Enter><Esc>

Find the first line that contains a lowercase i. If there is no lowercase i, the cursor stays on the blank line at the end.

<Ctrl-Shift-End><Del>

Delete everything from there to the end of the file.

We now have the original question, a blank line, 0 to 9 lines of I, and another blank line.

<Ctrl-G>3<Enter>

Go to line 3 (the first I line).

<Alt-E><Alt-C><Alt-N><Ctrl-A>1<Tab>1<Enter>

Open the Column Editor dialog and insert a number at the beginning of each line from the cursor to the end of the file, starting at 1, with an increment of 1. The numbered lines will be every line with an I plus the blank line at the end. Thus, we end up inserting the numbers 1 to N, where N is a random number between 1 and 10.

<Ctrl-H><Space>?I$<Tab><Del><Alt-A><Esc>

Delete the I after each number.

<Ctrl-End><Shift-Up><Ctrl-C>

Copy the last number (N).

<Ctrl-Home><End><Backsp><Ctrl-V><Space>easy<Space>steps!

Go to the end of the first line, delete the question mark, and insert the number plus the text easy steps!.

<Left><Ctrl-Left><Up><Ctrl-Right>

Position the cursor at the beginning of the first word after "How do I".

<Shift-End><Ctrl-C>

Select to the end of the line and copy (the action that I want to know how to do).

<Ctrl-H>

Replace:

\d+$<Tab>Step<Space>$0<Space>-<Space><Ctrl-V>.<Alt-A>

... each number X with Step X - [action]....

-(.+\r)<Tab>- Do not$1<Alt-A>

... the action on each instruction line except the last with Do not [action]...

(1<Space>.+p)s<Tab>$1<Alt-A><Esc>

... and 1 easy steps with 1 easy step.

<Right><Del><Space>in<Space>

Delete the newline between the action and N easy steps and replace it with in .

<Home><Ctrl-Right><Del>t<Ctrl-Right><Del><Del>

Change do to to and delete the I .

<Ctrl-End><Shift-Home><Ctrl-Shift-Right><Ctrl-Alt-Shift-U>

Go to the last line, select all but the first word, and convert to sentence case. This uppercases the first character of the action (e.g. Find a pen instead of find a pen).

\$\endgroup\$
2
\$\begingroup\$

Stax, 79 bytes

Çφ`¶J╙╜úº╢ßJ╒♂é↔1S├p$@¢☺<ME⌡┐α∟0/δ-/⌂╙Γâ∙╗-ó≡æñ↕S-α.Wì*°yf╞≈♣⌐Y/)\┬░╛₧níë╛♂9=%▀

Run and debug it

Can probably be shortened by a lot. I'm not too familiar with string manipulation in stax yet.

Since stax does not have a random number function, this program uses the length of the string as n.

\$\endgroup\$
2
\$\begingroup\$

PowerShell Core, 163 161 bytes

-2 bytes thanks @Julian

$q="$args"-replace'^.+I|\?$'
$r=Random 10
$s='s'*!!$r++
"How to$q in $r easy step$s!
"
1..$r|%{"Step $_ -$(' do not'*($_-ne$r)+$q-replace'^ .',{"$_"|% tou*r})."}

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice one! you can save 2 more bytes: by declaring $r first and doing $r++ without parenthesis: Try it online! \$\endgroup\$
    – Julian
    Oct 19, 2020 at 3:56
  • \$\begingroup\$ It's very smart! Thanks \$\endgroup\$
    – mazzy
    Oct 19, 2020 at 5:58
2
\$\begingroup\$

Japt -R, 79 bytes

A=ö)Îç¤i`How {=s8J}  {A±1} ey ¡ep` ·cAÆi`Do not` ·i¢iUÅÎu¹gAg°X)i`Sp {X} - 

Try it

\$\endgroup\$
1
\$\begingroup\$

Red, 180 bytes

func[s][t: n: 0
parse s["How do I "copy t to"?"]print["How to"t"in"n:
random 10"easy steps!^/"]append t"."repeat i
n - 1[print["Step"i"- Do not"t]]t/1:
t/1 - 32 print["Step"n"-"t]]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 95 bytes

A,P>z9hOT%."\ny6¶†Õ8Âù<û¡*SŠÄ™‘uü'iyÃ",GHVtH%." t²aD–ñö«É ?6^ó",hNG;%." t8ݧGeµè‡",HrG4

Try it online!

Explanation

A,                                                                                           # Set...
  P>z9                                                                                       # ...G to the verb...
      hOT                                                                                    # ...and H to the number of steps.
         %."\ny6¶†Õ8Âù<û¡*SŠÄ™‘uü'iyÃ",GH                                                    # Print "How to <G> in <H> easy steps!" with 2 trailing newlines.
                                              %." t²aD–ñö«É ?6^ó",hNG                        # Print "Step <N> - Do not <G>."...
                                           VtH                          ;                    # ...H-1 times.
                                                                         %." t8ݧGeµè‡",HrG4 # Print "Step <H> - <G>."
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 99 90 bytes

-9 bytes by using (two-char string) and (three-char string).

ð¡3.$ðý¨U…€ß€„ .ªX«ð«„€† «TLΩ©«ð«„‡š›Ž«®i¨}…!

«®F„Š¥ ™«N>«… - «N>®QiX.ª«ë…€·€– .ª«X«}„.
«

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.