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!
-
1\$\begingroup\$ Can we assume that <verb> will always start with a lowercase letter? \$\endgroup\$Gymhgy– Gymhgy2020年10月15日 18:35:12 +00:00Commented Oct 15, 2020 at 18:35
-
7\$\begingroup\$ @SunnyMoon Oh well, that renders all existing answers wrong. \$\endgroup\$Adám– Adám2020年10月15日 19:42:32 +00:00Commented 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– Sisyphus2020年10月16日 05:18:38 +00:00Commented 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– SunnyMoon2020年10月16日 05:37:58 +00:00Commented 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– user2020年10月21日 15:23:56 +00:00Commented Oct 21, 2020 at 15:23
23 Answers 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:
-
\$\begingroup\$ I always suspected that LaTeX code is ment for golfing rather than actually working with it. :) \$\endgroup\$Zsolt Szilagy– Zsolt Szilagy2020年10月18日 12:37:00 +00:00Commented Oct 18, 2020 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^}."
-
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– user2020年10月15日 18:46:09 +00:00Commented Oct 15, 2020 at 18:46
-
\$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$Adám– Adám2020年10月15日 19:55:30 +00:00Commented Oct 15, 2020 at 19:55
-
2\$\begingroup\$ What does
${$: -1}do? \$\endgroup\$corvus_192– corvus_1922020年10月15日 21:21:11 +00:00Commented 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\$Digital Trauma– Digital Trauma2020年10月15日 21:29:15 +00:00Commented Oct 15, 2020 at 21:29 -
\$\begingroup\$ 9 bytes could be saved \$\endgroup\$Nahuel Fouilleul– Nahuel Fouilleul2020年10月16日 20:24:17 +00:00Commented Oct 16, 2020 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
∊ ε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)));}
+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- --n → m-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
-
1\$\begingroup\$ There are two newlines after
...steps!. \$\endgroup\$SunnyMoon– SunnyMoon2020年10月15日 20:11:22 +00:00Commented Oct 15, 2020 at 20:11 -
2\$\begingroup\$ You can use
"s"+!ninstead ofn?"s":"". \$\endgroup\$Arnauld– Arnauld2020年10月15日 22:47:54 +00:00Commented Oct 15, 2020 at 22:47 -
1\$\begingroup\$ You can use
How to%sand(b=a)+6. \$\endgroup\$Arnauld– Arnauld2020年10月15日 22:55:22 +00:00Commented Oct 15, 2020 at 22:55 -
1\$\begingroup\$ You can save 31 bytes by having
scanfgive 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– ErikF2020年10月16日 03:50:54 +00:00Commented Oct 16, 2020 at 3:50 -
1
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}."}*''
-
\$\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 varv, which gave error :P \$\endgroup\$vrintle– vrintle2020年11月21日 15:11:52 +00:00Commented Nov 21, 2020 at 15:11 -
1\$\begingroup\$ @vrintle You'll often see
$_/-pin 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 bygetsorreadline. The-pcommand-line flag causes the code to be wrapped in awhile gets; ...; print $_; endloop. If...is empty you have acatprogram: 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– Dingus2020年11月22日 00:28:48 +00:00Commented Nov 22, 2020 at 0:28 -
\$\begingroup\$ And, how does this works? Even, we've not specified
$_. But, when I write justupcasein code, it gives error... Strange! \$\endgroup\$vrintle– vrintle2020年11月30日 10:11:36 +00:00Commented Nov 30, 2020 at 10:11 -
1\$\begingroup\$ @vrintle See this tip. In
-pmode,suboperates on$_if there is no explicit receiver. Note that you have specified$_in your example: it'stry it Online, read automatically from STDIN into$_thanks to-p. \$\endgroup\$Dingus– Dingus2020年11月30日 10:28:44 +00:00Commented Nov 30, 2020 at 10:28 -
\$\begingroup\$ (@vrintle I should mention a subtle gotcha: receiverless
subin-pmode 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– Dingus2020年11月30日 11:30:31 +00:00Commented Nov 30, 2020 at 11:30
Scala, (削除) 195 (削除ここまで) 188 bytes
- Saved 7 bytes thanks to @corvus_192
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)
-
1\$\begingroup\$ Nice use of the string pattern match. \$\endgroup\$corvus_192– corvus_1922020年10月15日 19:01:22 +00:00Commented Oct 15, 2020 at 19:01
-
1\$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$Adám– Adám2020年10月15日 19:55:47 +00:00Commented Oct 15, 2020 at 19:55
-
1\$\begingroup\$ You can save 4 bytes with
"s"take(r-1)\$\endgroup\$corvus_192– corvus_1922020年10月15日 20:52:42 +00:00Commented Oct 15, 2020 at 20:52 -
2\$\begingroup\$ Even better, use
"ps"take r\$\endgroup\$corvus_192– corvus_1922020年10月15日 20:54:46 +00:00Commented 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– corvus_1922020年10月15日 21:05:48 +00:00Commented Oct 15, 2020 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)
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
-
\$\begingroup\$ Your program needs to print two newlines after
...<n> easy steps!. \$\endgroup\$SunnyMoon– SunnyMoon2020年10月15日 18:33:24 +00:00Commented Oct 15, 2020 at 18:33 -
\$\begingroup\$ @SunnyMoon Fixed \$\endgroup\$Gymhgy– Gymhgy2020年10月15日 18:34:55 +00:00Commented Oct 15, 2020 at 18:34
-
\$\begingroup\$ -1 byte by reversing
?:order: try it \$\endgroup\$Dominic van Essen– Dominic van Essen2020年10月15日 19:32:34 +00:00Commented Oct 15, 2020 at 19:32 -
\$\begingroup\$ OP now requires removing "s" if n=1. \$\endgroup\$Adám– Adám2020年10月15日 19:55:55 +00:00Commented 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– Gymhgy2020年10月16日 03:02:42 +00:00Commented Oct 16, 2020 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
- Isolates the task
make coffeewith the initial space - Generates a random number in the range 1..10
- Prints the title with an extra new line and the conditional s
- 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
-
\$\begingroup\$ nice. thanks. you can save some bytes. Try it online! \$\endgroup\$mazzy– mazzy2020年10月18日 08:05:09 +00:00Commented Oct 18, 2020 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
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)));}
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));}
-
\$\begingroup\$ You can save 1 byte by dropping the last space in
"Do not ". You don't copy it anyway. \$\endgroup\$Petr Fiedler– Petr Fiedler2020年10月17日 02:59:54 +00:00Commented Oct 17, 2020 at 2:59 -
\$\begingroup\$ You can save 2 bytes by printing a
\nbeforeStep, which avoids two of the other three uses. \$\endgroup\$Neil– Neil2020年10月18日 19:14:24 +00:00Commented Oct 18, 2020 at 19:14 -
\$\begingroup\$ Suggest
mempcpy(s+=2,"Do not",6)instead ofmemcpy(s+=2,"Do not",6)+6\$\endgroup\$ceilingcat– ceilingcat2022年06月12日 08:51:04 +00:00Commented Jun 12, 2022 at 8:51
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
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
-
2\$\begingroup\$ The number of steps should be randomly generated by the program. \$\endgroup\$SunnyMoon– SunnyMoon2020年10月15日 20:12:16 +00:00Commented Oct 15, 2020 at 20:12
-
\$\begingroup\$ @SunnyMoon Changed to a random number of steps. \$\endgroup\$Xcali– Xcali2020年10月16日 05:00:49 +00:00Commented Oct 16, 2020 at 5:00
-
\$\begingroup\$ 124 bytes \$\endgroup\$Nahuel Fouilleul– Nahuel Fouilleul2020年10月16日 20:21:30 +00:00Commented Oct 16, 2020 at 20:21
Charcoal, (削除) 89 (削除ここまで) (削除) 85 (削除ここまで) (削除) 82 (削除ここまで) 80 bytes
≔✂S9±1¦1θ≔‽χη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:
≔✂S9±1¦1θ
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 ..
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())
-
\$\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– Kyuuhachi2020年10月15日 20:02:10 +00:00Commented Oct 15, 2020 at 20:02
-
\$\begingroup\$ Because of memory alignment on most OSes,
id(0)%10+1will always be odd, but you can try something likeid(0)%19/2+1. It's not uniform, but at least each number has a nonzero probability. \$\endgroup\$Sisyphus– Sisyphus2020年10月16日 01:56:43 +00:00Commented 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\$The Fifth Marshal– The Fifth Marshal2020年10月18日 19:15:21 +00:00Commented 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\$The Fifth Marshal– The Fifth Marshal2020年10月18日 19:18:19 +00:00Commented 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– Kyuuhachi2020年10月18日 21:08:52 +00:00Commented Oct 18, 2020 at 21:08
05AB1E, 74 bytes
TLΩÐD≠'s×ばつsI8.$ ̈©"€ß€„ÿ€† ÿ‡šŠ\ÿ!
"ˆG®N"Š\ ÿ - Do€–ÿ."ˆ}®TMs"Š\ ÿ -ÿ."ˆ ̄.a»
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
.a # 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
.a # 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 ÿ - ÿ.".
-
\$\begingroup\$ Another stack based language beats the stack based language. Nice. \$\endgroup\$Razetime– Razetime2020年10月16日 10:09:05 +00:00Commented Oct 16, 2020 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 not1ドル<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 not1ドル<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╙╜úo╢ßJ╒♂é↔1S├p$@¢☺<ME⌡┐α∟0/δ-/⌂╙Γâ∙╗-ó≡æñ↕S-α.Wì*°yf╞≈♣⌐Y/)\┬░╛₧níë╛♂9=%▀
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})."}
-
1\$\begingroup\$ Nice one! you can save 2 more bytes: by declaring $r first and doing $r++ without parenthesis: Try it online! \$\endgroup\$Julian– Julian2020年10月19日 03:56:38 +00:00Commented Oct 19, 2020 at 3:56
-
\$\begingroup\$ It's very smart! Thanks \$\endgroup\$mazzy– mazzy2020年10月19日 05:58:45 +00:00Commented Oct 19, 2020 at 5:58
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]]
Pyth, 95 bytes
A,P>z9hOT%."\ny6¶Õ8Âù<û¡*SÄuü'iyÃ",GHVtH%." t2aDñö«É ?6^ó",hNG;%." t8ݧGeμè",HrG4
Explanation
A, # Set...
P>z9 # ...G to the verb...
hOT # ...and H to the number of steps.
%."\ny6¶†Õ8Âù<û¡*SŠÄTM‘uü'iyÃ",GH # Print "How to <G> in <H> easy steps!" with 2 trailing newlines.
%." t2aD–ñö«É ?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...€ß€„ .aX«ð«„€† «TLΩ©«ð«„‡š›Ž«®i ̈}...!
«®F„Š\ TM«N>«... - «N>®QiX.a«ë...€·€– .a«X«}„.
«