17
2
Create a program which when run displays the text below:
)-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-(
Use any functions or language to answer this, have fun. Shortest code wins
17
2
Create a program which when run displays the text below:
)-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-(
Use any functions or language to answer this, have fun. Shortest code wins
6
Saved 2 bytes thanks to @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
139 bytes – Shaggy – 2017-06-21T09:55:31.533
32
7WOW, I'll tattoo this approach on my cerebral cortex!! – Mauro Baraldi – 2017-06-20T20:59:46.017
Impressive, beat me by 1 byte! Take a +1 – Gryphon – 2017-06-21T00:08:37.750
12
PRINT')-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-('
SQL allows splitting string literals over lines, so those returns are counted.
Working on a procedural solution, but doubt I'll find one under 60.
New Edit: Found a simple REPLACE
that ties the trivial solution:
PRINT REPLACE('1
| Welcome User! |
1',1,')-*-*-*^_^*-*-*-(')
Turns out that REPLACE
will do an implicit conversion of a numeral to a string, so this lets me save 2 characters by eliminating the quotes around my replacement character.
Trying to put it into a variable is too long, due to the overhead of the DECLARE
(69 bytes):
DECLARE @ CHAR(17)=')-*-*-*^_^*-*-*-('PRINT @+'
| Welcome User! |
'+@
Please see this: https://codegolf.meta.stackexchange.com/a/1146/46066
– juniorRubyist – 2017-06-20T20:16:04.0638This answer is completely fine @juniorRubyist – Mr. Xcoder – 2017-06-20T20:16:53.277
Ok. I removed that downvote. – juniorRubyist – 2017-06-20T20:18:02.030
Thanks. Thought you were originally referring to the hard-coding the output limitation, but that's allowed for kolmogorov-complexity. Just not particularly efficient.
– BradC – 2017-06-20T20:19:55.4339
a="\n)-*-*-*^_^*-*-*-(\n"
print a+'| Welcome User! |'+a
Pretty simple. Includes leading and trailing newlines.
13It does not need to be a function. – totallyhuman – 2017-06-20T20:17:52.463
8
main(i){for(;printf(")-*-*-*^_^*-*-*-(")&i--;puts("\n| Welcome User! |"));}
Nice try, pretty low amount of bytes as well! – Amurt4l – 2017-06-20T20:03:30.730
Lowest I have got it down to is 66 bytes so far – Amurt4l – 2017-06-20T20:04:01.860
71 bytes with a trailing newline (75 without): #define P puts(")-*-*-*^_^*-*-*-(") f(){P;puts("| Welcome User! |");P;}
2@Amurt4l if you would like, since you have gotten quite a few answers, you can post your own answer as well :) – Stephen – 2017-06-20T20:35:43.350
6
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...
3This language <s>is</s> feels like such an abuse of the "rules", that I think we should change them just so that @Dennis will have to change the language a little – Stephen – 2017-06-20T20:33:16.137
@StephenS TBH, I agree. However, thankfully languages optimized for [tag:kolmogorov-complexity] (Jelly, 05AB1E, V, SOGL, some others) can still usually beat it without feeling as cheap. – James – 2017-06-20T20:34:32.290
11@StephenS If a challenge is best solved with Bubblegum, it’s the challenge’s fault, not the language’s. Instead of rules lawyering, write more interesting challenges. – Anders Kaseorg – 2017-06-21T04:57:48.807
6
-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
1You could do .∞
instead of û¨'(«
– Emigna – 2017-06-20T20:47:15.327
I knew this had to exist somehow! Thanks man – Datboi – 2017-06-20T20:52:39.557
Nevermind, what I posted was equivalent lol. – Magic Octopus Urn – 2017-06-21T13:56:01.833
I know it's been a while, but you can save a byte by changing the ")-*-*-*^_"
to ')„-*Є^_J
. :) – Kevin Cruijssen – 2020-01-06T14:56:27.593
5
alert(`${s=")-*-*-*^_^*-*-*-("}
| Welcome User! |
${s}`)
_=>(s=")-*-*-*^_^*-*-*-(")+`
| Welcome User! |
`+s
-2 bytes thanks to Rick Hitckcock
Why alert
? Save a few bytes using a function. – Shaggy – 2017-06-20T20:11:31.120
@Shaggy I know that, just edited it in, but currently OP says display, and has not responded to my comment yet – Stephen – 2017-06-20T20:12:25.333
Please see this: https://codegolf.meta.stackexchange.com/a/1146/46066
– juniorRubyist – 2017-06-20T20:16:25.7074@juniorRubyist we usually allow either a complete program or a function. OP did not specify that functions that returned the value instead of displaying it were allowed, so my second two entries may not be allowed. However, complete programs are (almost) always allowed, and JavaScript doesn't need boilerplate. Copy my alert
into a .js
file and run it in your browser, it'll run. – Stephen – 2017-06-20T20:19:55.313
Save 2 bytes with _=>(s=")-*-*-*^_^*-*-*-(")+
\n| Welcome User! |\n+s
– Rick Hitchcock – 2017-06-20T21:39:48.183
Is there a reason you can't use the function argument instead of a new variable for storing the top and bottom of the string? – kamoroso94 – 2017-10-19T17:01:28.437
5
print(")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-(")
Needs to be a function. – juniorRubyist – 2017-06-20T20:12:58.933
Please see this: https://codegolf.meta.stackexchange.com/a/1146/46066
– juniorRubyist – 2017-06-20T20:16:13.9973But it's not a snippet. It's a full program. – totallyhuman – 2017-06-20T20:17:18.083
2No, does not need to be a funciton. Read it again: Use any functions or language to answer this. – Mauro Baraldi – 2017-06-20T20:18:37.433
2@juniorRubyist The 1st line of the question says Create a program
– dzaima – 2017-06-20T20:18:50.867
@dzaima I'll point out the other python answer and then direct you towards the standard defaults.
– Draco18s no longer trusts SE – 2017-06-21T03:41:21.080@dzaima this is actually a full program.. – Stefan – 2017-06-22T07:34:29.367
4
main(){char*S=")-*-*-*^_^*-*-*-(";printf("%s\n| Welcome User! |\n%s",S,S);}
70 bytes like this;
m=")-*-*-*^_^*-*-*-(";main(){printf("%s\n| Welcome User! |\n%s",m,m);}
– cleblanc – 2017-06-21T12:59:16.383
4
_=>")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("
4
Two for the price of one:
s/^/)-*-*-*^_^*-*-*-(/p
x
s/^/| Welcome User! |/p
x
s/^/)-*-*-*^_^*-*-*-(\n| Welcome User! |/p
s/\n.*//
4
a=')-*-*-*^_^*-*-*-(';disp([a;'| Welcome User! |';a])
Why MATLAB / Python
? This is definitely not valid python. – James – 2017-06-21T00:06:18.540
@DJMcMayhem Sorry I meant Octave. Thanks for noticing the typo. Been answering python questions over on SO all day so brain had a small glitch :) – rayryeng - Reinstate Monica – 2017-06-21T00:06:32.133
If you ommit disp
Matlab will show leading ans = \n
. – Crowley – 2017-06-21T12:31:50.687
@Crowley That's why you need the disp
there as it won't conform to the exact output. – rayryeng - Reinstate Monica – 2017-06-21T14:21:16.840
If the ans =
is not disallowed you can save 6 bytes. – Crowley – 2017-06-21T16:18:38.803
@Crowley I agree completely with the byte count, but I don't think it's permitted for this challenge. This is Kolmogorov Complexity so the output must exactly match the challenge. If the OP has some leeway, it would have been mentioned. – rayryeng - Reinstate Monica – 2017-06-21T16:22:34.987
4
_^×*-³(⸿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.
(Why the downvote?) – Neil – 2017-06-22T12:15:49.690
2Apparently someone's been downvoting many of the answers in this challenge, my submission is also one of the affected ones. – user41805 – 2017-06-22T12:18:46.677
4
print$\=")-*-*-*^_^*-*-*-(","
| Welcome User! |
"
Uses the fact that $\
is implicitly printed after each print
.
What about say
? – simbabque – 2017-06-22T13:23:51.680
1
@simbabque I tend to follow this consensus. Furthermore, replacing all 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 :)
3
1<?=$a=")-*-*-*^_^*-*-*-(","\n| Welcome User! |\n$a";
– Christoph – 2017-06-21T09:32:18.387
3
Column@{t=")-*-*-*^_^*-*-*-(","| Welcome User! |",t}
3
func main(){var a string=")-*-*-*^_^*-*-*-(\n";Printf(a+"| Welcome User! |\n"+a)}
Hello, and welcome to PPCG! Your submission can be a function that returns the text as output, as per meta consensus, which might make it shorter and better for this site. – Comrade SparklePony – 2017-06-20T22:11:12.153
Ah okay, thank you for the heads up. I'll make an edit. – ionk – 2017-06-20T22:13:54.613
You have to include the fmt
import, sorry. – totallyhuman – 2017-06-22T12:44:30.347
@totallyhuman wait but it's not part of the function. – ionk – 2017-06-22T18:53:31.493
3
3
tellraw @a {"text":")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("}
This isn't even trying to compress the string... – Okx – 2017-06-22T10:07:29.957
2@Okx Well try doing that when the only non-constant things you can print are numbers and block/item names :p – dzaima – 2017-06-22T12:04:19.110
3
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
3
@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 ^^^^_^^^^
3
On your first line, you could change |"a">"01p to |>"01pa to save a couple characters – AGourd – 2017-06-22T13:20:20.467
@AGourd; Oh I must have missed that, seems simple when you point it out :) - I'll edit it out soon, thanks. – Teal pelican – 2017-06-22T13:25:50.947
2
é)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
2
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
Why the down vote? – jacoblaw – 2017-06-22T16:07:55.143
2
Why the downvote? – Comrade SparklePony – 2017-06-22T14:06:56.603
2
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
1i)-*-*-*^_^*-*-*-(^]
is much shorter for constructing the top line. Also, Y
is equivalent to Vy
– James – 2017-06-21T05:52:28.980
Actually if you more or less borrow DJ's V answer top line construction you can save 2 bytes on the hardcode input i)^]8a-*^[r(9hR^_^^[
– nmjcman101 – 2017-06-21T13:01:27.407
Thanks y'all. I've been using Vim for like a month and I was just trying to see if I could do it. Obviously I have a lot of optimization to go on my workflow – bioweasel – 2017-06-21T14:37:33.653
One last tip: If duplicate the line before opening a newline for "Welcome User!", you won't need to hit ^[
at the end. YPo| Welcome User! |
– James – 2017-06-22T16:24:19.697
See? didn't even know that P
was a thing. That's awesome though. Thanks! – bioweasel – 2017-06-22T19:36:17.113
2
)-*-*-*\^_\^*-*-*-(
^*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
2
f=")-*-*-*^_^*-*-*-("
echo "$f
| Welcome User! |
$f"
2
main(){printf("%s| Welcome User! |\n%1$s",")-*-*-*^_^*-*-*-(\n");}
Yes, there are other C solutions, also coming in at about 66 bytes.
Ungolfed
main()
{
printf("%s| Welcome User! |\n%1$s",
")-*-*-*^_^*-*-*-(\n"
);
}
GCC produces a warning for the missing printf prototype.
The %1$s says use argument 1 (again) for the second string argument.
In real-life programs, it can also be used to pass in precision/width arguments into a printf. This avoids having to use a printf to create the format string for the real printf.
1Which compiler successfully compiles and runs this? My gcc
(7.1.1) gives an error for the missing semicolon and fails to compile. – Doorknob – 2017-06-22T02:42:44.057
csm@localhost:~$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
– CSM – 2017-06-22T20:45:06.277
I tried compiling gcc 4.9.2 from source on my machine, but I still got an error rather than a warning for the missing semicolon. Is there any other way to reproduce this? – Doorknob – 2017-06-22T23:53:59.017
Argh. You are right, the semicolon is needed. I was accidentally running the previous compilation result. – CSM – 2017-06-23T12:33:16.780
2
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.
2
/tellraw @p ["",{"text":")-*-*-*^_^*-*-*-(\n"},{"text":"| Welcome User! |\n"},{"text":")-*-*-*^_^*-*-*-("}]
2
($z=')-*-*-*^_^*-*-*-(')
"| Welcome User! |
$z"
Ran into the problem everyone else is running into: there's not enough meat to justify trying to encode the top line's pattern. A fancier join method also turned out to cost one more byte
1
1
↑αMΟ±.○h+‘╬1"→ū↑, ¶‘θ⁾@∑32ž
Try it Here!
I have no idea why I still haven't added a capitalize 1st letter of each word function... Here it uses a 4-byte replacement
1
set a )-*-*-*^_^*-*-*-(
set b "| Welcome User! |"
puts " $a\n $b\n $a"
puts "[set a )-*-*-*^_^*-*-*-(]
| Welcome User! |
$a"
Thanks @sergiol for the suggestion!
1
")-*-*-*^_^*-*-*-("!&@"
| Welcome User! |
"@19&@
")-*-*-*^_^*-*-*-(" push the string ")-*-*-*^_^*-*-*-(" as characters
!&@ print all the characters on the stack without popping
"
| Welcome User! | push the string "\n| Welcome User! |\n"
"
@19 pop and print 19 characters on the stack
&@ print all the characters on the stack
1
fun main(a:Array<String>){val s=")-*-*-*^_^*-*-*-(";print("$s\n| Welcome User! |\n$s")}"
1
1
Fn.new{"1| Welcome User! |
1".replace("1",")-*-*-*^_^*-*-*-(
")}
Fn.new{ // New anonymous function
"1| Welcome User! |
1" // Create the string "| Welcome User! |"
.replace("1",")-*-*-*^_^*-*-*-(
")} // Prepend & append the string ")-*-*-*^_^*-*-*-(\n"
1
f(){printf("%s| Welcome User! |\n%1$s",")-*-*-*^_^*-*-*-(\n");}
Three bytes shorter than all the previous solutions because new rules allow functions.
0
!v"(-*-*-*^_"~! |
>~")"a"| !resU emocleW |v"61pa10.
l?!;o >
0
$a=')-*-*-*^_^*-*-*-(';
echo <<<S
$a
| Welcome User! |
$a
S;
Welcome to PPCG! – Laikoni – 2017-06-21T21:31:52.553
0
Anonymous VBE immediate window function that takes no input and outputs a greeting to the user via the immediate window
a=")-*-*-*^_^*-*-*-(":?a:?"| Welcome User! |":?a
I post mine then deleted immediately when I saw yours. :D – remoel – 2017-10-20T10:13:48.030
0
func n(){a:=")-*-*-*^_^*-*-*-(\n";Print(a+"| Welcome User! |\n"+a)}
Prints with a trailing newline.
0
0
(u=')-*-*-*^_^*-*-*-(')=>[u,'| Welcome User! |',u].join`
`
I am sure I can golf if down , but later
0
>")-*-*-*^_^*-*-*-(":$ak"| Welcome User! |"ak@
It will appear to process until it times out, due to the two ^
commands which spawn IPs that do nothing (necessitating the explicit entry >
). I am disapointed that this is 2 bytes shorter than the multiple IP method. Constructing the first and last lines using multiplication/duplication turns out to be even more expensive as well (50 bytes). :(
0
$a=')-*-*-*^_^*-*-*-(';write $a;"| Welcome User! |";$a
Write-Host ")-*-*-*^_^*-*-*-(`n| Welcome User! |`n)-*-*-*^_^*-*-*-("
0
r=")-*-*-*^_^*-*-*-(\n";cat(r,"| Welcome User! |\n",r,sep="")
Has a trailing newline. I couldn't see if that was approved or not, so I just rolled with it.
3Can we alternatively return this from a function, as per usual? – Stephen – 2017-06-20T20:00:57.673
6Are leading/trailing newlines allowed? – Gryphon – 2017-06-20T20:08:18.543