# 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? – Embodiment of Ignorance Oct 15 at 18:35
• @SunnyMoon Oh well, that renders all existing answers wrong. – Adám Oct 15 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. – Sisyphus Oct 16 at 5:18
• @Sisyphus I have not seen much a challenge involving random numbers in CGCC, so I thought I would make one! – SunnyMoon Oct 16 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 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. :) – Zsolt Szilagy Oct 18 at 12:37

# Bash + coreutils seq, 128

• Thanks to @NahuelFouilleul for some good golfing suggestions.
v=${1:9} v=${v%?}
s=s
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. – corvus_192 Oct 15 at 19:01 • OP now requires removing "s" if n=1. – Adám Oct 15 at 19:55 • You can save 4 bytes with "s"take(r-1) – corvus_192 Oct 15 at 20:52 • Even better, use "ps"take r – corvus_192 Oct 15 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. – corvus_192 Oct 15 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 at 19:55
• @Adám Thank you for the notification. Updated. – Arnauld Oct 15 at 22:37

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!. – SunnyMoon Oct 15 at 18:33 • @SunnyMoon Fixed – Embodiment of Ignorance Oct 15 at 18:34 • -1 byte by reversing ?: order: try it – Dominic van Essen Oct 15 at 19:32 • OP now requires removing "s" if n=1. – Adám Oct 15 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! – Embodiment of Ignorance Oct 16 at 3:02 # 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! # 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!

• nice. thanks. you can save some bytes. Try it online! – mazzy Oct 18 at 8:05

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

# C (gcc), 194193192190 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!

• You can save 1 byte by dropping the last space in "Do not ". You don't copy it anyway. – Petr Fiedler Oct 17 at 2:59
• You can save 2 bytes by printing a \n before Step, which avoids two of the other three uses. – Neil Oct 18 at 19:14

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

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

• The number of steps should be randomly generated by the program. – SunnyMoon Oct 15 at 20:12
• @SunnyMoon Changed to a random number of steps. – Xcali Oct 16 at 5:00
• 124 bytes – Nahuel Fouilleul Oct 16 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? – Caagr98 Oct 15 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. – Sisyphus Oct 16 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). – pppery Oct 18 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. – pppery Oct 18 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. – Caagr98 Oct 18 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. – Razetime Oct 16 at 10:09

Çφ¶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! – Julian Oct 19 at 3:56 • It's very smart! Thanks – mazzy Oct 19 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 # 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). # 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 bytes ð¡3.$ðý¨U“€ß€„ “.ªX«ð«“€† “«TLΩ©«ð«“‡š›Ž“«®Θi¨}'!«¶«¶«®F”Š¥ ”«N>«" - "«N>®QiX.ª«ë“€·€– “.ª«X«}'.«¶«


Try it online!

 ¡                                                            # split
# implicit input
ð                                                             # by spaces
3.\$                                                         # pop a, push a[3:]
ý                                                       # pop a, join a
ð                                                        # by spaces
¨                                                      # pop a, push a[:-1]
U                                                     # pop a, store a in X
“€ß€„ “.ª                                            # push "How to "
X«                                          # concatenated with X
«                                        # concatenated with
ð                                         # a whitespace
«                                  # concatenated with
“€† “                                   # "in "
«                             # concatenated with
Ω                               # a random element from
L                                # [1, 2, ...,
T                                 # ..., 10]
©                              # and store that in register_c
«                           # concatenated with
ð                            # a whitespace
«                    # concatenated with
“‡š›Ž“                     # "easy steps"
i                 # if
®                   # the value in register_c
Θ                  # is equal to 1
¨                # then pop a, push a[:-1]
}               # exit if statement
«            # concatenated with
'!             # an exclamation point
« «        # concatenated with (two chars)
¶ ¶         # two newlines
F      # for N in [0, 1, ...,
®       # ..., register_c - 1]
«                                                        # concatenated with
”Š¥ ”                                                         # "Step "
«                                                     # concatenated with
N>                                                      # N + 1
" - "«                                               # concatenated with " - "
i                                          # if
N>                                             # N + 1
Q                                           # is equal to
®                                            # the value in register_c
«                                      # then concatenated with
X.ª                                       # X in Sentence case
ë                                     # else
«                           # concatenated with
“€·€– “.ª                            # "Do not "
X«                        # concatenated with X
}                       # end if statement
«                    # concatenated with
'.                     # a period
«                  # concatenated with
¶                   # a newline
# implicit output
`