# Create an Accurate How-To Article

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.


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!

• Can we assume that <verb> will always start with a lowercase letter? Oct 15 '20 at 18:35
• @SunnyMoon Oh well, that renders all existing answers wrong.
Oct 15 '20 at 19:42
• I don't think the randomness adds anything to the challenge. Taking a number as input would have made much more sense. Oct 16 '20 at 5:18
• @Sisyphus I have not seen much a challenge involving random numbers in CGCC, so I thought I would make one! Oct 16 '20 at 5:37
• @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 :)
– user
Oct 21 '20 at 15:23

# 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:

• I always suspected that LaTeX code is ment for golfing rather than actually working with it. :) Oct 18 '20 at 12:37

# 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! • 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!" – user Oct 15 '20 at 18:46 • OP now requires removing "s" if n=1. – Adám Oct 15 '20 at 19:55 • What does {: -1} do? Oct 15 '20 at 21:21 • $$ 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. Oct 15 '20 at 21:29 • 9 bytes could be saved Oct 16 '20 at 20:24 # 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 # 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 • There are two newlines after ...steps!. Oct 15 '20 at 20:11 • You can use "s"+!n instead of n?"s":"". Oct 15 '20 at 22:47 • You can use How to%s and (b=a)+6. Oct 15 '20 at 22:55 • 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! Oct 16 '20 at 3:50 • 186 bytes by using the interesting subscripting feature that C has where a[1] == 1[a] Oct 22 '20 at 1:07 # 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! • 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 Nov 21 '20 at 15:11
• @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. Nov 22 '20 at 0:28
• And, how does this works? Even, we've not specified $_. But, when I write just upcase in code, it gives error... Strange! Nov 30 '20 at 10:11 • @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. Nov 30 '20 at 10:28
• (@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.) Nov 30 '20 at 11:30

# 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)

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

# 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! • OP now requires removing "s" if n=1. – Adám Oct 15 '20 at 19:55 • @Adám Thank you for the notification. Updated. Oct 15 '20 at 22:37 # 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!

• Your program needs to print two newlines after ...<n> easy steps!. Oct 15 '20 at 18:33
• @SunnyMoon Fixed Oct 15 '20 at 18:34
• -1 byte by reversing ?: order: try it Oct 15 '20 at 19:32
• OP now requires removing "s" if n=1.
Oct 15 '20 at 19:55
• @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! Oct 16 '20 at 3:02

# 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$_ - "
";say"Step $_ - ",ucfirst"Do not "x($b>$_).$',"."for 1..b  Try it online! • The number of steps should be randomly generated by the program. Oct 15 '20 at 20:12 • @SunnyMoon Changed to a random number of steps. Oct 16 '20 at 5:00 • 124 bytes Oct 16 '20 at 20:21 # Charcoal, 898582 80 bytes ≔✂Ｓ⁹±¹¦¹θ≔‽χηHow to θ in Ｉ⊕η easy step∧ηs¦!⸿Ｆ⊕η«⸿Step Ｉ⊕ι - ⭆⁺×Do not ‹ιηθ⎇λκ↥κ.  Try it online! Link is to verbose version of code. This feels far too long. Explanation: ≔✂Ｓ⁹±¹¦¹θ  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 Ｉ⊕η easy step∧ηs¦!⸿  Print the header, but only output the s if the random number wasn't 0 (1 step). Ｆ⊕η«  Repeat for each step. ⸿Step Ｉ⊕ι -  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 .. # Python 3, 160170168 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! • 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? Oct 15 '20 at 20:02 • 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. Oct 16 '20 at 1:56 • 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). Oct 18 '20 at 19:15 • 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. Oct 18 '20 at 19:18 • 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. Oct 18 '20 at 21:08 # 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 ÿ - ÿ.". • Another stack based language beats the stack based language. Nice. Oct 16 '20 at 10:09 # 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). # 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.

# 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!

• Nice one! you can save 2 more bytes: by declaring $r first and doing$r++ without parenthesis: Try it online! Oct 19 '20 at 3:56
• It's very smart! Thanks Oct 19 '20 at 5:58

# Japt-R, 79 bytes

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


Try it

# 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!

# Pyth, 95 bytes

A,P>z9hOT%."\ny6¶†Õ8Âù<û¡*SŠÄ™‘uü'iyÃ",GHVtH%." t²aD–ñö«É ?6^ó",hNG;%." t8Ý§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>."


# 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!