Following this question: Tut-tut-tut-tut-tut
Write a program that writes "tut-tut-tut" without using the characters "t", "u" or "-" in the code itself.
This is code golf, shortest code in bytes wins.
Following this question: Tut-tut-tut-tut-tut
Write a program that writes "tut-tut-tut" without using the characters "t", "u" or "-" in the code itself.
This is code golf, shortest code in bytes wins.
No code points, but assuming capital letters are OK for the output, as this will produce TuT-TuT-TuT
@for /f %%a in ('sc^|find "CO"') do @se%OS:~9% q=%%a
@se%OS:~9% a=%q:~8,1%%OS:~9%%q:~6,1%%OS:~9%
@echo %a:~1%%a%%a%
Length calculated by using Unix/LF as EOL, without an EOL at the end of the last line.
Shaved of 54 bytes thanks to @jdt, who posted a solution using code points (which I wanted to avoid), but contained three t
s. Thinking about ways to fix this made me have another go at mine as well.
The first issue with Batch is that you can't even set
a variable without using a t
.
But Batch will expand variables in a command first and then take the resulting line verbatim, so the forbidden characters can be picked from a variable. As luck would have it, there is a default environment variable with only two letters, and it even has the T at the last position (allowing to drop the substring length when extracting the T): OS=Windows_NT
.
So a T
in a command line can be replaced by %OS:~9%
, which solves most of the problems; but no such luck for U
or -
.
@for /f %%a in ('sc^|find "CO"') do @se%OS:~9% q=%%a
This will use the help for sc.exe, find the line continue--------Sends a CONTINUE control request to a service.
, break it into tokens at spaces (discarding empty fields), and set the variable q
to continue--------Sends
, where u
and -
are at single-digit positions.
@se%OS:~9% a=%q:~8,1%%OS:~9%%q:~6,1%%OS:~9%
This sets a
to -TuT
by picking characters from OS
and q
.
@echo %a:~1%%a%%a%
This prints a
three times, with the first instance %a:~1%
starting with the second character to remove the leading -
.
@for %%a in (84,85,84,45,84,85,84,45,84,85,84) do @(cmd /C exi%OS:~9% %%a&echo|se%OS:~9% /p=%%^=Exi%OS:~9%CodeAscii%%)
@jdt posted this in a comment for initially 110 bytes, but it used exit
, set
, and ExitCodeAscii
in the original. Replacing the t
s with %OS:~9%
brought it to 128, some more golfing brought it down to a one-liner with 118 bytes.
@for /f %%a in ('help^|find "SE%OS:~9,1% "') do @%%a s=%%a
@for /f "delims=" %%a in ('wmic/?^|find "/E"') do @%s%q=%%a
@%s%a=%q:~10,1%%q:~3,1%%q:~1,1%%q:~3,1%
@echo %a:~1%%a%%a%
Used the line SET Displays, sets, or removes Windows environment variables.
of the help
output to set a variable to SET
.
Above is the "safe" version (178 bytes) that should work with localized versions as well.
In the optimized version for English versions of cmd.exe only (otherwise the first line might run some unexpected commands, and/or not work at all), the first line changes to this, for a total of 169 bytes:
@for /f %%a in ('help^|find "s e"') do @%%a s=%%a
(this line ends with a trailing space!)
exit
, set
, and ExitCodeAscii
;-). Fixed it for 128, then golfed it down to a one-liner with 118 bytes; see above.
\$\endgroup\$
Commented
Sep 28, 2022 at 22:54
No code points; taking advantage of the long cmdlet names for a change ...
$ofs='';"$((gal oh|% R*e)[3,2,1,2])"*3|% S*g 1
$ofs=''; # set the output field separator to an empty string
gal oh # gal is an alias for Get-Alias; oh is an alias for Out-Host; returns an AliasInfo object
|% R*e # pipe the AliasInfo object for "oh" to % (an alias for ForEach-Object), and call its member ResolvedCommandName, which will return the string "Out-Host"
( )[3,2,1,2] # take the characters at positions 3, 2, 1, 2 from "Out-Host" (-, t, u, t)
"$( )" # evaluate that in a subexpression $() and stuff it all into a single string "-tut"
*3 # "multiply" with 3 to get "-tut-tut-tut"
|% S*g 1 # pipe that to ForEach-Object again, and call its member "SubString" to get everything starting at position 1
-
, which is one of the banned characters.
\$\endgroup\$
This was harder and easier than I though...
exec('prin\x74(("\x2d\x74\x75\x74"*3)[1:])')
I've tested it on Python 2.7.11+, 3.9.6 and 3.10.5.
Good 'ol evil eval exec to the rescue!
Thanks to @Dingus for pointing out a mistake, and @Bubbler for saving 1 byte.
Personally, I feel these are against the spirit of the challenge, and that's why they aren't replacing the "main" answer.
This is an alternative provided by @Bubbler.
It uses "TUT" instead of "tut", for the string, saving 1 byte.
I modified a little, to save 3 more bytes.
exec('prinT(("\x2dTUT"*3)[1:])'.lower())
This was edited to use exec
to run in Python 2.7.
This alternative was written by @py3programmer.
It produces the correct output, and avoids the [1:]
string indexing.
exec("prinT('TUT\x2d'*2+'TUT')".lower())
-1
isn't allowed (~0
is an easy fix).
\$\endgroup\$
\x2d
to the front and do [1:]
for -1 byte, and it also seems that 'TUT'.lower()
is 1 byte shorter than \x74\x75\x74
.
\$\endgroup\$
'prinT(("\x2dTUT"*3)[1:])'.lower()
instead of 'TUT'.lower()
. However, I feel this goes against the spirit of the challenge. While (strictly speaking) it doesn't break the rules at all, and must be a valid solution, I just feel like it is a little ... iffy... dirty... skirting in a gray area...
\$\endgroup\$
Commented
Sep 21, 2022 at 6:51
exec("prinT('TUT\x2d'*2+'TUT')".lower())
, as it also has 40 bytes.
\$\endgroup\$
Commented
Sep 21, 2022 at 15:31
exec
existed. I replaced all instances of eval
with exec
and the code now runs in Python 2.7. I've added it as an alternative answer as well, with credits to you.
\$\endgroup\$
Commented
Sep 21, 2022 at 20:13
p"#{[116,117,116,45,116,117,116,45,116,117,116].map{|c|c.chr}.join()}"
Four different alternatives:
…TUTl45ç«11∍
.•x`•45ç«11∍
'±È3£45ç«6∍û
"vwv/"ÇÍç6∍û
Without the restricted-source it would have been just 3 bytes shorter:
"tut-"11∍
Explanation:
Part 1 alternatives:
…TUT # Push string "TUT"
l # Convert it to lowercase
45 # Push 45
ç # Convert it to a character with this codepoint: "-"
« # Append the two together: "tut-"
.•x`• # Push compressed string "tut"
45ç« # Same as above
'±È '# Push dictionary string "tutorial"
3£ # Only keep its first 3 characters: "tut"
45ç« # Same as above
"vwv/" # Push string "vwv/"
Ç # Convert it to a list of its codepoint-integers: [118,119,118,47]
Í # Decrease each by 2
ç # Convert it from codepoint-integers to a list of characters
Part 2 alternatives:
11∍ # Extend it to size 11: "tut-tut-tut"
# (after which the result is output implicitly)
6∍ # Extend it to size 6: "tut-tu"
û # Palindromize it: "tut-tut-tut"
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why .•x`•
is "tut"
and '±È
is "tutorial"
.
t
/u
/-
, such as using code points. \$\endgroup\$ᵗ
? \$\endgroup\$