สร้างโปรแกรมที่เรียกใช้เมื่อแสดงข้อความด้านล่าง:
)-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-(
ใช้ฟังก์ชั่นหรือภาษาใด ๆ เพื่อตอบคำถามนี้สนุก รหัสที่สั้นที่สุดชนะ
สร้างโปรแกรมที่เรียกใช้เมื่อแสดงข้อความด้านล่าง:
)-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-(
ใช้ฟังก์ชั่นหรือภาษาใด ๆ เพื่อตอบคำถามนี้สนุก รหัสที่สั้นที่สุดชนะ
คำตอบ:
บันทึก 2 ไบต์ขอบคุณ @Shaggy
[U="){"-*-*-*^_"ê}("`| WelÖ U r! |`U]·
[U="){"-*-*-*^_"ê}("`| WelÖ U r! |`U]·
[ ] // Create a new array
U= // Variable U =
") // ")
{ } // Evaluate everything in curley-brackets as code
"-*-*-*^_"ê // "-*-*-*^_" mirrored -> -*-*-*^_^*-*-*-
(" // ("
* Now we have [U=")-*-*-*^_^*-*-*-("]
`| WelÖ U r! |` // "| Welcome User! |" decompressed by `...`
U // ")-*-*-*^_^*-*-*-("
* Now we have [")-*-*-*^_^*-*-*-(","| Welcome User! |",")-*-*-*^_^*-*-*-("]
· // Split with new-lines
PRINT')-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-('
SQL อนุญาตให้แยกสตริงตัวอักษรเหนือเส้นดังนั้นการส่งคืนจะถูกนับ
ทำงานเกี่ยวกับวิธีการแก้ปัญหา แต่สงสัยฉันจะหาหนึ่งภายใต้ 60
ใหม่แก้ไข : พบวิธีง่ายๆREPLACE
ที่เชื่อมโยงกับวิธีแก้ปัญหาเล็กน้อย:
PRINT REPLACE('1
| Welcome User! |
1',1,')-*-*-*^_^*-*-*-(')
ปรากฎว่าREPLACE
จะทำการแปลงโดยนัยของตัวเลขเป็นสตริงดังนั้นสิ่งนี้ช่วยให้ฉันบันทึก 2 ตัวอักษรโดยกำจัดเครื่องหมายคำพูดรอบตัวอักขระทดแทนของฉัน
การพยายามใส่ลงในตัวแปรนั้นยาวเกินไปเนื่องจากโอเวอร์เฮดของDECLARE
(69 ไบต์):
DECLARE @ CHAR(17)=')-*-*-*^_^*-*-*-('PRINT @+'
| Welcome User! |
'+@
a="\n)-*-*-*^_^*-*-*-(\n"
print a+'| Welcome User! |'+a
ค่อนข้างง่าย รวมถึงการขึ้นบรรทัดใหม่ที่นำหน้าและต่อท้าย
main(i){for(;printf(")-*-*-*^_^*-*-*-(")&i--;puts("\n| Welcome User! |"));}
#define P puts(")-*-*-*^_^*-*-*-(") f(){P;puts("| Welcome User! |");P;}
00000000: d3d4 d502 c1b8 f838 30ad abc1 55a3 109e .......80...U...
00000010: 9a93 9c9f 9baa 105a 9c5a a4a8 50c3 a589 .......Z.Z..P...
00000020: ae06 00bd 4d85 9835 0000 00 ....M..5...
-3 Bytes thanks to Emigna
")-*-*-*^_".∞D”|‡Ý‚Ý! |”s»
")-*-*-*^_".∞D”|‡Ý‚Ý! |”s»
")-*-*-*^_" # Push )-*-*-*^_
.∞ # Intersected mirror (results in )-*-*-*^_^*-*-*-( )
D # Duplicate top of stack
”|‡Ý‚Ý! |” # Pushes | Welcome User! |
s # Swap top items on stack
» # Join on newlines
.∞
instead of û¨'(«
")-*-*-*^_"
to ')„-*Є^_J
. :)
print(")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-(")
Create a program
alert(`${s=")-*-*-*^_^*-*-*-("}
| Welcome User! |
${s}`)
_=>(s=")-*-*-*^_^*-*-*-(")+`
| Welcome User! |
`+s
-2 bytes thanks to Rick Hitckcock
alert
? Save a few bytes using a function.
alert
into a .js
file and run it in your browser, it'll run.
_=>(s=")-*-*-*^_^*-*-*-(")+
\n| Welcome User! |\n+s
main(){char*S=")-*-*-*^_^*-*-*-(";printf("%s\n| Welcome User! |\n%s",S,S);}
m=")-*-*-*^_^*-*-*-(";main(){printf("%s\n| Welcome User! |\n%s",m,m);}
_=>")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("
Two for the price of one:
s/^/)-*-*-*^_^*-*-*-(/p
x
s/^/| Welcome User! |/p
x
s/^/)-*-*-*^_^*-*-*-(\n| Welcome User! |/p
s/\n.*//
a=')-*-*-*^_^*-*-*-(';disp([a;'| Welcome User! |';a])
MATLAB / Python
? This is definitely not valid python.
disp
Matlab will show leading ans = \n
.
disp
there as it won't conform to the exact output.
ans =
is not disallowed you can save 6 bytes.
print$\=")-*-*-*^_^*-*-*-(","
| Welcome User! |
"
Uses the fact that $\
is implicitly printed after each print
.
say
?
print
with say
isn't really where the point of golfing lies in my opinion. But I'm not on any crusade to stop using say
though; I let everyone do as they like, and everyone is happy :)
_^×*-³(⸿emocleW |‖B¬J¹¦¹ User!
Try it online! Link is to verbose version of code. Explanation:
_^ Print("_^");
×*-³ Print(Times("*-", 3));
(⸿emocleW | Print("(\remocleW |");
Prints the mirror image of the top left portion of the output.
‖B¬ ReflectButterfly(:¬);
Reflects down and to the left to create the top and bottom lines and the left of the middle line.
J¹¦¹ JumpTo(1, 1);
User! Print(" User!");
Fixes up the middle line.
Column@{t=")-*-*-*^_^*-*-*-(","| Welcome User! |",t}
func main(){var a string=")-*-*-*^_^*-*-*-(\n";Printf(a+"| Welcome User! |\n"+a)}
fmt
import, sorry.
tellraw @a {"text":")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("}
22#)[#-#*]"^_^"[#*#-]#(V"
| Welcome User! |
"R!&@v&@R&@
It's 2 bytes shorter than hardcoding the output.
22 Push 2 2s to the stack
These are used for loop counting
#) Push )
[#-#*] Push -* 3 times, using one of the 2s
"^_^" Push ^_^
[#*#-] Push *- 3 times, using the remaining 2
#( Push (
V Create a new stack
"
| Welcome User! |
" Push \n| Welcome User! |\n to the new stack
R!&@ Return to main stack, print entire stack without popping
v&@ Switch to 2nd stack, pop and print stack
R Return to main stack, pop and print stack
<?=$a=")-*-*-*^_^*-*-*-(","\n| Welcome User! |\n$a";
@SET b=@ECHO )-*-*-*^^^^_^^^^*-*-*-(
%b%
@ECHO ^| Welcome User! ^|
%b%
I mostly enjoy this one because all the escape characters make the emoticon ^_^
look like an adorable Lovecraft abomination ^^^^_^^^^
é)8a-*r(ãhR^_^Äo| Welcome User! |
Hexdump:
00000000: e929 3861 2d2a 1b72 28e3 6852 5e5f 5e1b .)8a-*.r(.hR^_^.
00000010: c46f 7c20 5765 6c63 6f6d 6520 5573 6572 .o| Welcome User
00000020: 2120 7c ! |
Explanation:
é) " Insert a '('
8a " Append 8 copies of the following:
-*<esc> " '-*'
r( " Replace the last character on this line with '('
ãh " Move to the middle of this line
R " And write the following text over the existing text:
^_^<esc> " '^_^'
Ä " Duplicate this line
o " On a new line:
| Welcome User! | " Write the whole middle line
It's boring, but I just cant find a way to creat )-*-*-*^_^*-*-*-(
or | Welcome User! |
in less bytes than just copying the strings.
J")-*-*-*^_^*-*-*-("J"| Welcome User! |"J
Explanation:
J")-*-*-*^_^*-*-*-(" # J = ")-*-*-*^_^*-*-*-("
J # Print J with new line
"| Welcome User! |" # Print "| Welcome User! |" with new line
J # Print J with new line
)-*-*-*\^_\^*-*-*-(
^*1//.+/gS"
| Welcome User! |
"
)-*-*-*\^_\^*-*-*-(
^ Give the stack-string this value ")-*-*-*^_^*-*-*-(\n"
*1 Append 1 duplicate of the stack-string to itself
stack-string: ")-*-*-*^_^*-*-*-(\n)-*-*-*^_^*-*-*-("
//.+/g Get matches of /.+/g and set the stack-array to this result
stack-array: [")-*-*-*^_^*-*-*-(",")-*-*-*^_^*-*-*-("]
S"
| Welcome User! |
" Join the stack-array on "\n| Welcome User! |\n" and
set the stack-string to this result
f=")-*-*-*^_^*-*-*-("
echo "$f
| Welcome User! |
$f"
i)^[8a-*^[r(9hR^_^^[Yo| Welcome User! |^[p
Shoutout to the homies in the comments
Original:
i)-\*^[vhyl2pa^_^\*-^[vhyl2pa(^[Vyo| Welcome User! |^[p
Where ^[
is the ESC
key
i)-*-*-*^_^*-*-*-(^]
is much shorter for constructing the top line. Also, Y
is equivalent to Vy
i)^]8a-*^[r(9hR^_^^[
^[
at the end. YPo| Welcome User! |
P
was a thing. That's awesome though. Thanks!
x->"".format("%s| Welcome User! |\n%<s",")-*-*-*^_^*-*-*-(\n")
Or as full program (110 bytes):
interface A{static void main(String[]a){System.out.printf("%s| Welcome User! |\n%<s",")-*-*-*^_^*-*-*-(\n");}}
Surprised there wasn't a Java answer yet.