Bana bir Paskalya yumurtası yap!


29

Hayır, ^^vv<><>BAtür Paskalya yumurtaları değil, boyadığımız gerçek Paskalya yumurtaları.

İşte (çok çizilmiş) bir yumurta.

  __
 /  \
/    \
|    |
\____/

Paskalya'da onları desenlerle boyarız. Bunlar gibi:

  __
 /--\
/----\
|----|
\____/
  __
 /%%\
/%%%%\
|%%%%|
\____/
  __
 /~~\
/~~~~\
|~~~~|
\____/

Meydan okuma

Yumurtayı boyamak için bir karakter (yazdırılabilir ascii) verildiğinde, boyanmış yumurtayı yazdırın.

Örnekler:

&:
  __
 /&&\
/&&&&\
|&&&&|
\____/

#:
  __
 /##\
/####\
|####|
\____/

gözlük

  • İzleyen yeni satırlara / alanlara izin verilir.

8
Why the downvote? If you do not like this question, downvote then leave a reason please.
Matthew Roh

2
One potential reason might be that they don't think this task is clear enough or clear enough. I'd say it is clear enough, and it's not literally trivial either. That said, I'm not particularly excited either.
John Dvorak

17
The challenge will be very trivial in most languages. The egg is too short to allow much originality in the golfing. In my opinion, it's an uninteresting challenge (that hasn't been sandboxed, because you seem to be boycotting the sandbox for I don't know what reasons), therefor, I downvote it.
Dada

25
Upvoted because simple challenges like this are great for beginners like me to ease into golf.
Shaggy

7
POOF! You're an easter egg. (Sorry, couldn't resist)
George Cummins

Yanıtlar:


16

Brain-Flak, 270 268 266 + 1 = 267 bytes

+1 from the -c flag

(((((((((({}<(((([(()()())]((((((((((({}){}){}){}){}[()]))<>)<>{}())))))<>)<>(((()()()()()){}))({}()){})<>)<>>))))<<>({}<>)((()()()()()){})<>({}<>)>))))<<>((({})<>)({})<((()()()()()){})>[()()])>))<>((((({})<>)[(()()()()())({}){}])<((()()()()()){})<>((({}<>){}()))>))

Try it online!

I was going to write an explanation, but I took a nap first and forgot how this whole think works. Your guess is as good as mine.


14
This is the best explanation I've ever read on here. +1
David Conrad

12

Python 2, 62 bytes

Super straight-forward. Try it online.
-1 byte, thanks to @mbomb007

print r'''  __
 /~\
/~~\
|~~|
\____/'''.replace('~',input()*2)


@mbomb007 Good one, thanks
Dead Possum

2
You can save two bytes by using lambda function like this
Keerthana Prabhakaran

@KeerthanaPrabhakaran I'm not sure if lambdas are OK for ascii challenges
Dead Possum

1
what is the problem in using lambda in ascii challenges? how are they even related!? :o
Keerthana Prabhakaran

10

Charcoal, 30 26 16 bytes

Two bytes saved thanks to @Neil by filling after making the shape

__↗¹←↑¹↖²↓_‖M←¤S

Try it online!

Explanation

The program works by first creating the right half of the egg, and then reflecting it to generate the left half.

__↗¹                          Write the two bottom _s and write the /
←↑¹                           Move left and write the |
↖²                            Then write two \s
↓_                            And the top _
‖M←                          Reflect the canvas to the left
¤S                           Fill the shape with the string input

←_↘ can be just ↓_ but in fact you can fill after you reflect for 16 bytes: __↗¹←↑¹↖²↓_‖M←¤S.
Neil

@Neil Thanks for introducing me to ¤
Kritixi Lithos

9

Jelly, 24  22 bytes

Ḥ;“ ¶/\|_”“Ṁ¢ṚR;ḳ}AṠ’ṃ

Try it online!

How?

Ḥ;“ ¶/\|_”“Ṁ¢ṚR;ḳ}AṠ’ṃ - Main link: character c  e.g. '~'
Ḥ                      - double c: ['~','~']
  “ _¶/\|”             - string literal: [' ','_',<newline>,'/','\','|']
 ;                     - concatenate c:  [['~','~'],' ','_',<newline>,'/','\','|']
          “Ṁ¢ṚR;ḳ}AṠ’  - base 250 number: 3067183430901851641706
                     ṃ - base decompression with reversed @rguments:
                       -     take the number and convert it to a base length(the list)
                       -     then index (1-based) into that same list.
                       -     i.e.: 3067183430901851641706 in base 7
                                 = 22003241534115361163500004
                                   indexed into [['~','~'],' ','_',<newline>,'/','\','|']
                                 = [' ',' ','_','_',<newline>,' ','/',['~','~'],'\',<newline>,'/',['~','~'],['~','~'],'\',<newline>,'|',['~','~'],['~','~'],'|',<newline>,'\','_','_','_','_','/']
                       - implicit print:  __
                                         /~~\
                                        /~~~~\
                                        |~~~~|
                                        \____/

3
I nominate your explanation of for the longest explanation of a single byte.
Magic Octopus Urn

It seems to have become quite a handy atom, thought I'd give it some time in the limelight!
Jonathan Allan

2
I see Dennis use it a lot, this is the first time I feel like I actually understood it though; the time was not wasted! You have given me 1 unit of learn.
Magic Octopus Urn

1
Well it is one of my babies :)
Jonathan Allan

6

Sed, 43 characters

s:.:  __\n /&&\\\n/&&&&\\\n|&&&&|\n\\____/:

Sample run:

bash-4.3$ sed 's:.:  __\n /&&\\\n/&&&&\\\n|&&&&|\n\\____/:' <<< '★'
  __
 /★★\
/★★★★\
|★★★★|
\____/

That's exactly what I wrote, just a few seconds faster.
Riley

6

JavaScript (ES6), 53 49 47 bytes

I'm sure I can squeeze a bit more out of this - having to escape the \s is annoying me.

f=

c=>`  __
 /${c+=c}\\
/${c+=c}\\
|${c}|
\\____/`

console.log(f`-`)
console.log(f`%`)
console.log(f`~`)
console.log(f`&`)
console.log(f`#`)

  • 4 bytes saved by moving the s=c+c variable assignment inside the first set of {}.
  • 2 bytes saved by using c+=c instead of s=c+c & s=s+s, with thanks in part to Neil who spotted this improvement at the same time as I was making it.

Paint Your Own!


It would be a bit better if you put those input in <pre><code>s. Nice job though.
Matthew Roh

Thanks, @SIGSEGV. Consoles preserve white space and, by default, at least, use a monospaced font, so no need to output to a pre.
Shaggy

1
Why not c+=c?
Neil

Thanks, @Neil, I was just editing that in myself, but I'll update again to give you a nod as well.
Shaggy

@Arnauld You don't need to count the f=\n portion for the byte count. That's only so the snippet runs.
AdmBorkBork

5

Alice, 53 52 bytes, non-competing

Thanks to Leo for indirectly saving 1 byte.

/o *^i}'.*[;.h~r}}~"{.[^\\
@"S .^~ y~a}~~.["{!~"}^^^

Try it online!

Unfortunately, I had to fix a bug with y (transliteration) to make this work, so I've marked it as non-competing.

Explanation

The basic idea is to create a string of the egg but with ~ as a placeholder for two copies of the input. However, the other characters of the input aren't particularly friendly for Alice strings, because those can't contain linefeeds, and all of /\_| would need escaping (because they're treated as mirrors and walls). So I can save some bytes by using placeholders for these as well, and then transliterating them. The placeholders for /\_| are .[^{, which are simply the character right before the one they represent. For the linefeed I'm using }.

Now the code... the entire program can be solved in Ordinal mode since we only need string processing and no processing of integers. Furthermore, we don't need any conditional control flow. The entire program can be expressed linearly. The general structure of the program is this:

/...//
@....

In such a program, the IP bounces up and down through the ... section, first only executing half of the characters. Then the two / at the end move the IP right by one cell, so that on the way back it executes the other half (again bouncing up and down) until finally the @ terminates the program. So if we unfold the funny zigzag structure in the middle, the program we're executing really looks like this:

"  ^^} .~[}.~~[}{~~{}[^^^^.""!}"r.h~;a*y'~i.*So

Let's go through this:

"  ^^} .~[}.~~[}{~~{}[^^^^."
      This first string is simply the egg template I've talked about.
"!}"  Push this string. It covers all the characters we need to replace
      in the template except ~.
r     Range expansion. Turns '!}' into '!"#$...z{|}'.
.     Duplicate.
h~;   Split off the first character, swap it to the top and discard it.
a*    Append a linefeed.
      We've now basically rotated the string to the left, but appended
      a linefeed instead of the exclamation mark we've shifted off.
      This maps each character in the string to the next one, except }
      which gets mapped to a linefeed.
y     Transliterate. Since the strings have the same length, this just maps
      each character in the first string to the corresponding character in
      the second string, replacing all of our placeholder characters.
'~    Push "~".
i.*   Read the input and duplicate it.
S     Substitute all "~" with the doubled input.
o     Output the result.

:D it's here!! This language looks nifty
Conor O'Brien

@ConorO'Brien thank you. I've already plastered some older challenges with it in case you want to see more samples. :)
Martin Ender

4

PowerShell, 50 49 48 bytes

'  __
 /11\
/1111\
|1111|
\____/'-replace1,$args

Try it online!

Straightforward string replacement into a literal string. Not much room for golfing.

-1 byte thanks to HyperNeutrino; -1 byte thanks to wubs


4

Carrot, 34 bytes, non-competing

  __
 /##\\
/####\\
|####|
\\____/

Non-competing because I just fixed bug with the interpreter in leading whitespace not being shown.

Try it online here.

First, we are in caret-mode, where every character gets pushed to the "stack". And finally the "stack" gets printed as output.

In caret-mode, # pushes the input, so the instances of # are basically replaced with the input (FYI # is a one-byte cat program).


4

SOGL V0.12, 21 18 16 bytes

0≈⁾‛≤¦¶W?5┼EB§  ‘

Try it Here!

The whole program is the following compressed:

  __
 /ŗŗ\
/ŗŗŗŗ\
|ŗŗŗŗ|
\____/

where ŗ gets replaced with the input.

13 bytes almost works too, but it does unneeded things with certain inputs..


You have to paint the egg. (i.e. fill the inside of the egg with characters)
Matthew Roh

@SIGSEGV - It is explained that that is achieved by replacing the spaces with the input and replacing the dashes with spaces with the code @,ŗ -@ŗ
Jonathan Allan

Will SOGOL be at TIO any time soon?
Jonathan Allan

@JonathanAllan If someone can get it there, then yes.
dzaima

Talk to Dennis in the talk-tryitonline-net room.
Jonathan Allan

3

05AB1E, 34 33 32 bytes

„__I244S×'/ì'\«`©¦¨'|.ø®R¹'_‡).c

Try it online!

Explanation

„__                               # push "__"
   I244S×                         # push a list of the input repeated 2 and 4 and 4 times
         '/ì                      # prepend "/"
            '\«                   # append "\"
               `                  # split list to separate items
                ©                 # store a copy of the last one in register
                 ¦¨               # remove first and last item of the string
                   '|.ø           # surround with pipes
                       ®R         # retrieve the string from register and reverse it
                         ¹'_‡     # replace input with "_"
                             ).c  # print each line centered

•jÀňiXƒÐ[Z•6B6ôvy5ÝJ"_ |/\"¹«‡, for 32, entirely different though. This faked me out and made me think I could use palindromize... Damn the fact that ())( and /\\/ are palindromes.
Magic Octopus Urn

1
@carusocomputing: You should post it separately. It's different enough to be interesting on its own :)
Emigna

3

Python 3.6, 53 bytes

lambda x:fr'''  __
 /{2*x}\
/{4*x}\
|{4*x}|
\____/'''
  • Unnamed function taking the character x and returning a string.
  • Uses Python 3.6's f-strings as an added alternative to earlier version's .format() - the {} enclosed parts of the f-string are code to be evaluated.
  • The string is also an r-string and triple quoted saving one byte over:

lambda x:f'  __\n /{2*x}\\\n/{4*x}\\\n|{4*x}|\n\____/'

I can't see an online interpreter for Python 3.6 though.
Try it at repl.it (says 3.5 but it is 3.6)



3

Brainfuck - 257 bytes 181 bytes

Golfed: Live version click here

+++++++[>++++++<-]>[>+>++>++>++<<<<-]>+++++>>>>++++++++++[>+++>+<<<++++<+<+>>>-]>++<<<--<+>>>,>..<<<<..>>>>>.<.<<<<<.>>>>..<<.>>>>.<<<<<<.>>>>....<<.>>>>.<<<.>....<.>>>.<<<<.<....<.

I'm not a professional golfer though. This is my attempt as far as I can recall :D

Output:

  __ 
 /XX\ 
/XXXX\ 
|XXXX| 
\____/ where X is the given char.

Ungolfed ( + comments) :

; chars:
; _ 95
; / 47
; \ 92
; | 142
; min val = 42 (7 times 6)

; lets do some math
+++++++[>++++++<-]> ; effectively 7 times 6

; now lets copy this to the next pointers multiplying by 2 
the subsequent ones after the 1st
[>+>++>++>++<<<<-]

>+++++
>>>

> ; empty space starting from this pointer
++++++++++[>+++>+<<<++++<+<+>>>-]
>++<
<<--<+
>>>,
>..<<<<..>>>>>.<.
<<<<<.
>>>>..<<.>>>>.
<<<<<<.>>>>....<<.>>>>.
<<<.>....<.
>>>.<<<<.<....<.

2

05AB1E, 32 29 26 bytes (Thanks to Emigna/Adnan)

•jÀňiXƒÐ[Z•6B6ôvy5ÝJ¹"_ |/\ÿ"‡,

Try it online!

•jÀňiXƒÐ[Z•6B6ô # Push ['110011', '135541', '355554', '255552', '400003']
vy               # For each encrypted block...
  5ÝJ            # Push 012345.
     ¹"_ |/\ÿ"   # Push "_ |/\{input_char}".
              ‡, # Swap the charsets.

29 byte version (smarter w/o iteration needed due to encoding newlines as well):

05AB1E, 29 bytes (Emigna)

•P£<r7»TwDšç6•5ÝJI"
_/ÿ\|"‡.c

Try it online 2!


26 byte extension of Emigna's suggestion, using S to separate the chars into an array, then a[b] to interpolate each digit with the corresponding location in the previous array. This is essentially an element-wise transliteration (smart).

05AB1E, 26 bytes (Adnan)

"
_/ÿ\|"•P£<r7»TwDšç6•Sè.c

Try it online 3!


1
This is 3 bytes shorter. More similar to your answer than mine :)
Emigna

1
@Emigna that direct transliteration using newlines is a novel idea, I like that; this could honestly knock 5 bytes off many of my existing solutions.
Magic Octopus Urn


1
@adnan - sneaky sneaky...
Magic Octopus Urn

I feel like almost all my answers need to credit Admigna, wouldn't really know the language without both of your constant examples.
Magic Octopus Urn

2

PHP, 51 bytes

$a.=$a=$argn;echo"  __
 /$a\
/$a$a\
|$a$a|
\____/";

PHP, 58 Bytes without physical linebreaks

$a.=$a=$argn;echo"  __\n /$a\\\n/$a$a\\\n|$a$a|\n\\____/";

run this with -R option

61 Bytes

echo strtr("  __\n /88\\\n/8888\\\n|8888|\n\\____/",8,$argn);

Store the value doubled; remove unnecessary space; use literal newline character: pastebin.com/EghdAYMf
manatwork

@manatwork Thank you i have not really thinking about double the input
Jörg Hülsermann

save 7 bytes with physical linebreaks and not escaping the backslashes (the last one needs no escaping anyway). Oh and btw: -R is not a parameter, it´s an option.
Titus

@Titus i hate physical linebreaks Done
Jörg Hülsermann

@Titus, right, though man php calls them parameter: “It is also possible to process the standard input line by line using either the parameter -R or -F.”
manatwork

2

BF, 142 140 bytes

++++[->++++<]>[->+++>++++++>+>++++++>++>++++++++<<<<<<],>->---->------>->..<..<.>>.<<<<.<..
>>.>.<<.<....>>.>.>>>----.<....>.<<<.<.>>....<<<.

This is split across two lines for clarity; the newline is not counted.

It's fairly easy to write this sort of thing in BF, but it's non-trivial how to optimize the order of the cells to minimize movement. I wrote a brute-forcer script to try all the combinations and find the shortest, and I golfed it a bit to account for a golfing opportunity I hadn't included in the brute-forcer.


@JoKing I suggest you post that as a separate answer, because it seems very different from mine.
Esolanging Fruit

2

brainfuck, 114 bytes

-----[[<+>->++>++<<]->]<+++++++++++<+..<..>>.<.<<.>>,..<---.>>.<<<.>>....<.>>.<<<<---.>>>....<<<.>>>>.<<.+++....<.

Try it online!

I've used BF Crunch here to find a more optimal way to generate the individual characters.


2

C (gcc), 95 88 85 bytes

Thanks to Albert for -7 bytes

Thanks also to ceilingcat -3 bytes

f(c){for(int*s=L"  __\n /00\\\n/0000\\\n|0000|\n\\____/\n";*s;s+=printf(*s%6?s:&c));}

Try it online!


Don't declare *q just nest it right into your for-loop to save 5 bytes. char*s;f(c){for(s=" __\n /11\\\n/1111\\\n|1111|\n\\____/\n";*s;putchar(*s^49?*s:c),s++);}
Albert Renshaw

You can also save 2 more bytes ontop of that by declaring *s inside the for-loop's declaration argument: f(c){for(char*s=" __\n /11\\\n/1111\\\n|1111|\n\\____/\n";*s;putchar(*s^49?*s:c),s++);}
Albert Renshaw

You can shave 1 more byte too by checking for an ASCII character that has a numeric value of one digit. 1 is 49 in ASCII but that's 2 bytes, use something with a value from 0-9, for example the tabulation character ` ` is ASCII value 9.
Albert Renshaw

Suggest *s;f(c){for(s instead of f(c){for(int*
ceilingcat

1

SpecBAS - 70 bytes

1 INPUT a$:  ?"  __"'" /";a$*2;"\"'"/";a$*4;"\"'"|";a$*4;"|"'"\____/"

? is shorthand for PRINT command, and apostrophe moves cursor to next line.



1

Python, 59 bytes

lambda n:r'''  __
 /a\
/aa\
|aa|
\____/'''.replace('a',n*2)

1

Lua, 66 bytes

print((([[  __
 /ee\
/eeee\
|eeee|
\____/]]):gsub("e",io.read())))

((([[#NailedIt]])))




1

[R], 65 bytes

cat(gsub('x',scan(,''),"  __\n /xx\\\n/xxxx\\\n|xxxx|\n\\____/"))

Pretty unspectacular, please find a shorter one in R... It's your basic gsub


1

C++ 208 bytes

In response to comments: This is a complete re-post.

#include<iostream>
using namespace std;int main(){char e;cin>>e;cout<<"  __  \n";cout<<" /"<<e<<e<<"\\ "<<endl;cout<<"/"<<e<<e<<e<<e<<"\\"<<endl;cout<<"|"<<e<<e<<e<<e<<"|"<<endl;cout<<"\\____/ \n";return 0;}

1

C#, 56 bytes


Golfed

i=>"  __\n /i\\\n/ii\\\n|ii|\n\\____/".Replace("i",i+i);

Ungolfed

i => 
   "  __\n /i\\\n/ii\\\n|ii|\n\\____/"
      .Replace( "i", i + i );

Ungolfed readable

i => 
   "  __\n /i\\\n/ii\\\n|ii|\n\\____/"

      // Replace every instance of 'i' with the input cloned twice
      .Replace( "i", i + i );

Full code

using System;
using System.Collections.Generic;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, String> f = i => 
            "  __\n /i\\\n/ii\\\n|ii|\n\\____/"
               .Replace( "i", i + i );

         List<String>
            testCases = new List<String>() {
               "-",
               "%",
               "~",
               "o",
               " ",
         };

         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput:\n{f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}

Releases

  • v1.0 - 56 bytes - Initial solution.

Notes

The printed results within the link provided will not look like pretended, due to the font used not being monospace.


1

C(gcc), 87 bytes

e(d){printf("  __\n /%c%c\\\n/%c%c%c%c\\\n|%c%c%c%c|\n\\____/\n",d,d,d,d,d,d,d,d,d,d);}

printf without stdio.h causes warnings but no errors, allowing successful compilation.

Explanation

Printf statement that crams everything into one line, formatting the decoration character with %c.

Try it online


Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.