title: New Password Idea: Word-walker

text:
# Question
Title: New Password Idea: Word-walker
I thought of a new way to generate my passwords, and even though it's probably not very clever in the long run, it could still make for a fun code-golf.

Taking a string of words, the password is generated thus:

* Pick the *nth* character in the *nth* word
* If *n* is larger than the word, continue counting backwards

Example:

```
This is a fun task!
T     s a  u      !

```

T is the first character
s is the second
a is the first, but going back and forth it is also the third
u is the second but because of counting backwards it's also the fourth
'!' is the fifth character in 'task!' and thus will be included in the final password, `Tsau!`

**Rules**

* Input will be a string
* Separate the string on spaces, all other characters must be included
* Uppercase letters must remain uppercase, same with lowercase
* You take *n* steps in each word, where *n* is the number of words that have come before plus one
* If *n* is larger than the word, you must step backwards through the word, if you hit the start, you go forward again until you have stepped *n* times
* The first and last character is only stepped once, so 'fun' on the seventh position as an example goes 'funufun' and ends on n, not 'funnuff' and ends on f
* Output must be a string

Examples:

```
Input              Output
Once Upon A Time   OpAe
There was a man    Taaa
Who made a task    Waak
That was neat!     Taa
This is a long string to display how the generator is supposed to work  Tsagnoyotoipto

```

The shortest code in bytes wins!

# Answer
# Python 2, 72 bytes

```
lambda s:''.join((-~i*(w+w[-2:0:-1]))[i]for i,w in enumerate(s.split()))

```

Try it online!
> 13 votes

# Answer
# 05AB1E, 11 bytes

```
#vyN©Fû}®è?

```

Try it online!

**Explanation**

```
#             # split input on spaces
 vy           # for each word in input
   N©F        # N times do, where N is the current iteration
      û}      # palendromize the word
        ®è    # use N to index into the resulting word
          ?   # print

```
> 7 votes

# Answer
# Java 10, ~~148~~ ~~117~~ ~~114~~ 110 bytes

```
s->{int i=-1,j;for(var a:s.split(" "))System.out.print(a.charAt((j=a.length()-1)>0*i++?i/j%2<1?i%j:j-i%j:0));}

```

-31 bytes thanks to *@SamYonnou* by creating a port of *@user71546*'s JavaScript answer.
-4 bytes thanks to *@SamYonnou* again, optimizing the algorithm for Java.

Try it online.

**Explanation:**

```
s->{                            // Method with String parameter and no return-type
  int i=-1,                     // Step integer, starting at -1
      j;                        // Temp integer
  for(var a:s.split(" "))       // Loop over the parts split by spaces
    System.out.print(           // Print:
     a.charAt((j=a.length()-1)  //  Set `j` to the the length of the part minus 1
               >0               //  If the length of the part is larger than 1 (`j` > 0)
                 *i++?          //  (and increase `i` by 1 in the process with `i++`)
                i/j%2<1?        //   If `i` integer-divided by `j` is even:
                 i%j            //    Print the character at index `i` modulo-`j`
                :               //   Else:
                 j-i%j          //    Print the character at index `j` minus `i` modulo-`j`
               :                //  Else:
                0));}           //   Print the first (and only) character
                                //   (the >0 check is added to prevent divided-by-0 errors)

```
> 4 votes

# Answer
# Jelly, 12 bytes

```
ḲJị"ŒBṖȯ$€$Ɗ

```

Try it online!
> 4 votes

# Answer
# Charcoal, 16 bytes

```
⭆⪪Ｓ §⁺ι✂ι±²¦⁰±¹κ

```

Try it online! Link is to verbose version of code. Explanation:

```
  Ｓ                 Input string
 ⪪                  Split on spaces
⭆                   Map over words and join
      ι ι           Current word
       ✂ ±²¦⁰±¹     Slice backwards from 2nd last character to start exclusive
     ⁺              Concatenate
    §          κ    Cyclically index on current word index
                    Implicitly print

```

I don't often get to use Slice's last parameter.
> 3 votes

# Answer
# JavaScript (Node.js), ~~78~~ ~~70~~ ~~69~~ 68 bytes

-1 byte @Arnauld

```
x=>x.split` `.map((y,i)=>y[a=i%(l=y.length-1)|0,i/l&1?l-a:a]).join``

```

Try it online!

**Explanation**

```
x=>
 x.split` `                    // Split the words by spaces
 .map((y,i)=>                  // For each word:
  y[                           //  Get the character at index:
                               //   A walk has cycle of length (2 * y.length - 2)
   a=i%(l=y.length-1)|0,       //   Calculate index a = i % (y.length - 1)
   i/l&1                       //   Check in which half the index i in
   ?l-a                        //   If in the second half of cycle, use y.length - 1 - a
   :a                          //   If in the first half of cycle, use a
  ]
 ).join``                      // Join back the letters

```
> 3 votes

# Answer
# Stax, 9 bytes

```
éñ~╗D¡┤Gq

```

Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

```
j       split into words
{       start block for mapping
  cDrD  copy word; remove first and last character; reverse
  +     concatenate with original word
  i@    modularly (wrap-around) index using map iteration index
m       perform map

```

Run this one
> 3 votes

# Answer
# Red, 135 bytes

```
func[s][n: 0 p: copy""foreach w split s" "[append/dup r: copy""append w
reverse copy/part next w back tail w n: n + 1 append p r/(n)]p]

```

Try it online!

## Readable:

```
f: func[s][
    n: 0
    p: copy ""
    foreach w split s "  "[
        r: copy ""
        append/dup r append w reverse copy/part next w back tail w n: n + 1
        append p r/(n)
    ]
    p
]

```
> 2 votes

# Answer
# Perl 5, 76 bytes

```
print map{$l=length;substr$_.reverse,$i++%(2*$l-2||1)*(1+1/$l),1}split" ",<>

```

Try it online!
> 2 votes

# Answer
# , ~~31~~ ~~30~~ 28 bytes

```
{x{*|y#x,1_|1_x}'1+!#x}@" "\

```

Try it online!
> 2 votes

# Answer
# Husk, ~~14~~ 11 bytes

```
SzS!ö!…¢ŀŀw

```

Try it online! Inspiration was taken from this program by Zgarb for the forward-and-reverse stepping.
> 2 votes

# Answer
# Japt, `-P`, 11 bytes

```
¸Ëê ÅªD gEÉ

```

Try it

```
¸Ë+s1J w)gE

```

Try it

---

## Explanations

```
¸Ëê ÅªD gEÉ
¸               :Split on spaces
 Ë              :Map over each element D at index E
  ê             :  Palindromise
    Å           :  Slice off the first character
     ªD         :  Logical OR with the original element (the above will return an empty string for single character words)
        g       :  Get the character at index
         EÉ     :  E-1

```

```
¸Ë+s1J w)gE
¸               :Split on spaces
 Ë              :Map over each element D at index E
   s1J          :  Slice off the first and last characters
       w        :  Reverse
  +     )       :  Append to D
         gE     :  Get the character at index E

```
> 1 votes

# Answer
## Haskell, ~~65~~ ~~62~~ 61 bytes

```
zipWith(\i->(!!i).cycle.(id<>reverse.drop 1.init))[0..].words

```

Try it online!

It requires the latest version of `Prelude` which features the `<>` function.

```
                   words    -- split the input string into a list of words
zipWith(\i->     )[0..]     -- zip the elements i of [0..] and the words pairwise
                            -- with the function
      ... <> ...            --   call the functions with a word and concatenate
                            --   the results. The functions are
        id                  --     id: do nothing
        reverse.drop 1.init --     drop last and first element and reverse
    cycle                   --   repeat infinitely
(!!i)                       -- take the ith elemnt of

```

Edit: -3 bytes thanks to @user28667, -1 byte thanks to @B. Mehta
> 1 votes

# Answer
# PHP, 77 bytes

```
while(ord($w=$argv[++$i]))echo($w.=strrev(substr($w,1,-1)))[~-$i%strlen($w)];

```

Try it online!

* -3 bytes thanks to Kevin
* -10 bytes thanks to Titus
> 1 votes

# Answer
# Pyth, 12 bytes

```
s.e@+b_Ptbkc

```

Try it online

```
s.e@+b_PtbkcQ   Final Q (input) implicit

           cQ   Split on spaces
 .e             Map the above with b=element, k=index
       Ptb        Remove 1st and last character
      _           Reverse
    +b            Prepend the unaltered element ('abcd' -> 'abcdcb')
   @      k       Get the kth character (0 indexed, wrapping)
s               Join on empty string, implicit output

```
> 1 votes

# Answer
# C (gcc), 148 bytes (string version), 114 bytes (print version)

If I must return a string (long version):

```
char c[99]={0};char*f(s,t,u,i,j,k)char*s,*t,*u;{for(u=c,i=0;t=strtok(s," ");s=0,i++)*u++=t[j=strlen(t),k=2*j-(j>1)-1,(i%k<j?i%k:k-i%k)%j];return c;}

```

Try it online!

Otherwise, I just print and don't worry about a buffer (short version):

```
f(s,t,i,j,k)char*s,*t;{for(i=0;t=strtok(s," ");s=0,i++)putchar(t[j=strlen(t),k=2*j-(j>1)-1,(i%k<j?i%k:k-i%k)%j]);}

```

Try it online!
> 1 votes

# Answer
# AWK, 79 bytes

Mostly because I'm curious to see any better awk or bash solutions!

```
{for(i=1;i<=NF;i++){l=length($i);k=int(i/l)%2?l-i%l:k%l;printf substr($i,k,1)}}

```

Try it online!
> 1 votes

# Answer
# C# (.NET Core), 111 bytes

```
s=>{int i=-1,j;return String.Concat(s.Split(' ').Select(a=>a[++i>(j=a.Length-1)?j>0?i/j%2<1?i%j:j-i%j:0:i]));};

```

Try it online!
> 1 votes

# Answer
# Vyxal, 11 bytes

```
⌈₅(ʁ):ẏ¨£i∑

```

Try it Online!

```
⌈           # Input split on spaces
 ₅( )       # repeat len(that) times...
   ʁ        # Palindromise each word
       ¨£   # Zipping...
     :      # Words
      ẏ     # range(0, len(words))
         i  # Index the numbers into the words
          ∑ # Stringify

```
> 1 votes

# Answer
# Powershell ~~208~~ ~~186~~ 170 bytes

```
$args|%{$i=0;-join($_.Split()|%{$l=($b=($a=$_)).Length;if($l-gt2){$b=($a|%{-join$a[($l-2)..1]})}for($j=0;$a.Length-le$i;$j++){$a+=($b,$_)[$j%2]}$a.Substring($i,1);$i++})}

```

Ungolfed:

```
$args|%{
   $i=0;
    -join($_.Split()|%{
        $l=($b=($a=$_)).Length;
        if($l-gt2){
            $b=($a|%{-join$a[($l-2)..1]})
        }
        for($j=0;$a.Length-le$i;$j++){
            $a+=($b,$_)[$j%2]
        }
        $a.Substring($i,1);
        $i++
    })
}

```

Test cases below or try it online

```
@(
    "This is a fun task!",
    "Once Upon A Time",
    "There was a man",
    "Who made a task",
    "That was neat",
    "This is a long string to display how the generator is supposed to work"
)|%{$i=0;-join($_.Split()|%{$l=($b=($a=$_)).Length;if($l-gt2){$b=($a|%{-join$a[($l-2)..1]})}for($j=0;$a.Length-le$i;$j++){$a+=($b,$_)[$j%2]}$a.Substring($i,1);$i++})}

```
> 0 votes

# Answer
# J, 43 bytes

```
[:(>{~"_1#@>|i.@#)[:(,}.@}:)&.>[:<;._1' '&,

```

## ungolfed

```
[: (> {~"_1 #@> | i.@#) [: (, }.@}:)&.> [: <;._1 ' '&,

```
* `<;._1 ' '&,` split on spaces
* `(, }.@}:)&.>` for each word, kill the first and last elm and append to word
* `#@> | i.@#` take the remainder of each word's length divided into its index
* `> {~"_1` take that result and pluck it from each word.

Try it online!
> 0 votes

# Answer
# CJam, 22 bytes

```
qS/{_);1>W%+T_):T@*=}%

```

Try it online!
> 0 votes

# Answer
# Ruby `-pl`, 60 bytes

```
gsub(/(\S+) ?/){w=$1+$1.reverse[1..-2]
w[(-2+$.+=1)%w.size]}

```

Attempt This Online!
> 0 votes

---
Tags: code-golf, string
---


title: Counting characters

text:
# Question
Title: Counting characters
Write a function or program that accepts one character (or a string of length 1) as input, and outputs the number of times that character occurs inside the code.

* This program must be a Proper Quine, only in the sense that it cannot, for example, read itself as a file, etc.

Input can be any character, printable or not. Output may be to standard out, or as a return value from a function. This is code golf, so the shortest submission in bytes wins. Good luck!

# Answer
> 11 votes
# Python 2, ~~30~~ 22 bytes

*-8 bytes thanks to @Mukundan314*

```
`'``*2.count'*2`.count

```

Try it online!

# Answer
> 8 votes
# COW, ~~711~~ ~~519~~ ~~504~~ ~~390~~ 387 bytes

```
moOMooMOOmOoMoOMoOMoOMoOMoOMoOMoOMOOmoOMOoMOoMOoMOoMOoMOoMOoMOoMOoMOoMOomOoMOomoomoOMMMMOOMOomoomoOMoOMoOMoOMoOMoOMoOMoOMoOmOomooMMMMOOMOoMOoMMMmoOMoOMoOmoOMOomOomOoOOOmooMMMMOOmOoMoOMoOMoOMoOMOOmoOMOoMOoMOoMOoMOoMOoMOoMOomOoMOomoomoOMMMmoOMOomoOMoOmOomOoOOOmooMMMMOOMoOMoOMMMmoOOOOMoOMoOMoOmoOMOoMOomOomOoOOOmooMMMMOOmoOmoomoOMOOmoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOmOoMOomoomoOOOM

```

Try it online!

*I appreciated a lot the previous solution (504 bytes) because it's deducted step by step, if you are interested please take a look at that in the timeline...
Now I furnish the program with a more "sensible" structure that promises to be less expensive (in terms of total byte count) but finding just a working set of values isn't simple...
To find the best, **brute force** comes in.*

**The next sections refers to the 390 bytes answer since it's simpler to explain that and then tell what it's done to save 3 bytes.**

## What it does

\\$L = \\{M,O,o,m\\}\\$ is the set of used chars and \\$n\_1,\dots ,n\_4\\$ their count.
The program has a structure that allows to form the output number \\$n\_i\\$ as $$ \begin{align} n\_i = x\_i\times cf+y\_i \end{align} $$ Furthermore we don't need to form \\$x\_i\\$ and \\$y\_i\\$ every time from zero, we reach them using the *partial sums* of 2 sequences occurring in cells `[2]` and `[3]` respectively.

```
[0]: multiplier for [1]     [1]: input-current_char     [2]: x_i     [3]: y_i

[1] = getchar()
if[1] { [1]-=77(M), [2]+=8, [3]+=0, cut[1] } paste[1]  //checks for 'M' and prepares its count
if[1] { [1]-= 2(O), [2]+=2, [3]+=0, cut[1] } paste[1]  //checks for 'O' and prepares its count
if[1] { [1]-=32(o), [2]-=1, [3]-=1, cut[1] } paste[1]  //checks for 'o' and prepares its count
if[1] { [1]+= 2(m), [2]-=6, [3]-=2, cut[1] } paste[1]  //checks for 'm' and prepares its count
if ![1]                                                //input was one of the letters above
    print [2]*13+[3]
else                                                   //input was something else
    print [4] (0)

```

As long as the input doesn't match any letter in \\$L\\$, `[1]` stays ≠ 0 and `[2]` and `[3]` hold \\$x\_i\\$ and \\$y\_i\\$ of the last tested letter.
Otherwise, if `[1]` has become 0, those value are no longer updated and at the end they will form the related \\$n\_i\\$.

(When the input isn't a letter in \\$L\\$, after the 4 tests `[1]` is still ≠ 0 so the flow enters a loop (`[>]`) that sabotages the placement of the head, thus prevents from printing \\$n\_4\\$ (the number of `o`).)

## How

I've first constructed the exoskeleton: the complete program without the info about its char count.
That is without \\$cf\\$(*common factor*) and the 2 sequences that form \\$x\_i\\$ and \\$y\_i\\$.

* **The exoskeleton**

```
    moo ]    mOo <    MOo -    OOO *    Moo .
    MOO [    moO >    MoO +    MMM =    oom o

    >.
    [  <+++++++[>-----------<-]>  > ? > ? <<  =*]=
    [             --              > ? > ? <<  =*]=
    [     <++++[>--------<-]>     > ? > ? <<  =*]=
    [             ++              > ? > ? <<  =*]=
    [>]
    >[> ? <-]>o

```

Some of them can be negative but I know that in order to write them I'll spend \\$len\\$: the sum of their absolute value in `MoO`s and `MOo`s (`+` and `-`).

*Thanks to this condition the comptutation is rather straightforward.*

## Brute force

* \\$cf\>0\qquad\qquad A=\\{a\_1,\ a\_2,\ a\_3,\ a\_4,\ a\_5,\ a\_6,\ a\_7,\ a\_8\\}\\$
* \\$x\_i=\sum\_{j=1}^{i} a\_j \qquad y\_i=\sum\_{j=5}^{4+i} a\_j\\$
* \\$n\_i = x\_i\times cf+y\_i\\$
* \\$len = cf + \sum\_{j=1}^{8} |a\_j|\\$

$$ (\*)\begin{cases} n\_1=|M|+len\\ n\_2=|O|+len\\ n\_3=|o|+len\\ n\_4=|m| \end{cases} $$

Given the letter count in the exoskeleton \\$|M|=71,\ |O|=97,\ |o|=85,\ |m|=38\\$
we can now search for \\$cf\\$ and \\$A\\$ that satisfies \\$(\*)\\$ minimizing \\$len\\$.

`cf = 13, A = [8, 2, -1, -6, 0, 0, 1, -2]` is the best for that exoskeleton (\\$len=33\\$)

## Finished program

```
>.
[  <+++++++[>-----------<-]>  >  ++++++++  >      <<  =*]=
[             --              >     ++     >      <<  =*]=
[     <++++[>--------<-]>     >     -      >   +  <<  =*]=
[             ++              >   ------   >  --  <<  =*]=
[>]
>[>+++++++++++++<-]>o

```

As you can se when some \\$a\_i\\$ is \\$0\\$ its relative pair of `>` `<` became non-functional. But obviously we can't take them off in retrospect.

## -3 bytes, 387 bytes

Juggling with the exoskeleton I've found that there is one configuration slightly different that overall saves 3 bytes (1 instruction). What's different?

* One `*` is replaced with `[-]` that has the same effect *(+2 instr.)*
* Using one `*` \\$x\_4\\$ is detached from the partial sum: \\$x\_4=a\_4\\$ *(+1 instr.)*
* A pair of `>` `<` are saved because \\$a\_5=0\\$ *(-2 instr.)*

The letter count of this exoskeleton is \\$|M|=73,\ |O|=98,\ |o|=86,\ |m|=37\\$
`cf = 13, A = [8, 2, -1, 3, 0, -1, 1, -2]` is the best. (\\$len=31\\$) *(-2 instr.)*

# Answer
> 6 votes
# JavaScript (Node.js), 54 bytes

```
y=>"3.>=includes(*)\\\"y3.>=includes(*)".includes(y)*3

```

Try it online!

A bit convoluted but I tried to avoid using `f=` that would violate the proper quine requirement. The code is written in the way that all characters occur exactly 3 times.

# Answer
> 6 votes
# JavaScript (ES6),  ~~40~~  38 bytes

A function made of 19 distinct characters used twice each.

```
_=>_.match`[\\]chmt[-a.02:=>?^^-]`?2:0

```

Try it online!

### How?

The range going from `[` to `a` allows us to match the backtick and the underscore, which are both already doubled in the code, without explicitly including them in the pattern.

This method comes with two minor drawbacks:

* Because this range also includes `^`, we need to insert it twice in the code as well although it's not part of the payload.
* We also have to insert a second `-`.

Character set:

```
-.02:=>?[\]^_`achmt

```

# Answer
> 5 votes
# Pyth, 10 bytes

```
y/+N"y/+N"

```

Try it online!

Test cases

```
y/+N"y/+N"
    "y/+N"    String literal
  +N          Append the string `"`
 /            Count occurrences of the input in that string
y             Multiply by 2

```

# Answer
> 4 votes
# Stax, 12 bytes

```
".+#H".""+#H

```

Run and debug it

Takes as input a code point. Those provided in the test are for each character in the program, as well as their immediate predecessors and successors.

### Explanation:

```
".+#H".""+#H
".+#H"          String literal ".+#H"
      .""       String literal "\"\""
         +      Concatenate
          #     Count occurrences of the input
           H    Double

```

Constructs a string of half the program, permuted somehow. Counts occurrences there, then doubles.

# Answer
> 4 votes
# , 34 bytes

```
(2*1#.=&'(2*1#.=&)+6*=&')+6*=&''''

```

Try it online!

## how

```
                             single quote
         quoted program      adjustment
                |              /
        vvvvvvvvvvvvvvvv _____/___
(2*1#.=&'(2*1#.=&)+6*=&')+6*=&''''
^^^^^^^^                ^^^^^^^^^^
        \               /
         regular program

```
* Everything above a `^` is part of the "regular program".
* The rest is "the program quoted", but with one exception:
    + The quoted program doesn't include the program's single quote characters `'`
* `2*1#.=&'...'` \- Two times `2*` the sum of `1#.` the total number of times the input char matches a char in "the quoted program". One for the actual program char, one for its quoted twin.
* `+6*=&''''` \- Plus six times `+6*` the `1/0`-indicator of whether the input char is equal to a single quote `=&''''`. This is the hardcoded knowledge that there are 6 single quotes in the program.

# Answer
> 4 votes
# Jelly,  ~~12 10~~  8 bytes

-2 thanks to caird coinheringaahing (input is a character, not a string!)

```
“ḤṾċⱮ”Ḥċ

```

A monadic Link accepting a character that yields the count.

**Try it online!**

### How?

```
“ḤṾċ”ḤṾċ - Main Link: character, c
           (A full program with a single character as input gives the main
            Link a list of characters - i.e. S = ['c'])
“ḤṾċ”    - list of characters = ['Ḥ', 'Ṿ', 'ċ']
     Ḥ   - double = ["ḤḤ", "ṾṾ", "ċċ"]  (Python strings)
      Ṿ  - un-eval = ['“', 'Ḥ', 'Ḥ', 'Ṿ', 'Ṿ', 'ċ', 'ċ', '”']
       ċ - count occurrences of c (in the un-eval-ed list)
         - implicit print (a list with a single entry just prints that entry)

```

# Answer
> 3 votes
# Charcoal, 20 bytes

```
Ｉ⊗№⁺´”´””yＩ⊗№⁺´´yＳ”Ｓ

```

Try it online! Explanation:

```
    ´”´”                Literal string `””`
   ⁺                    Concatenated with
        ”yＩ⊗№⁺´´yＳ”     Literal string `Ｉ⊗№⁺´´yＳ`
  №                Ｓ    Count matches of input character
 ⊗                      Doubled
Ｉ                       Cast to string
                        Implicitly print

```

Charcoal has two ways of quoting non-ASCII characters, `´` (which quotes a single character) and `”y...”` (which quotes anything except ). Trying to do everything with `´` is awkward because it uses too many of them; the best I could do was 26 bytes.

# Answer
> 3 votes
# 05AB1E, 14 bytes

Port of the Stax answer. `¢` is order-sensitive, which is fairly annoying here.

```
"„Js¢·"„""Js¢·

```

Try it online!

# 05AB1E, 18 bytes

As for this... I wrote this myself.

```
„…J…¢s·'„'D''DJs¢·

```

Try it online!

## Explanation

```
„…J                 2-char string. …, J
   …¢s·             3-char string. ¢, s, ·
       '„           1-char string. „
         'D         1-char string. D
           ''       1-char string. '
             D      Copy this character.
              J     Join the stack.
               s¢   Count occurances of the input in the string.
                 ·  Multiply the count by 2. (Perfectly makes the 0-count still 0.)

```

# Answer
> 2 votes
# perl, 128 bytes, assuming ASCII input only

```
print 1;#!"$%&'()*+,-./023456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghjklmoqsuvwxyz{|}~...

```

Replace the trailing `...` with the 33 unprintable characters (ASCII 0 .. ASCII 31 + ASCII 127), with the newline at the end. (If anyone knows how to put unprintable characters in a textfield and have them show up here, I'm all ears).

# Answer
> 2 votes
# , ~~96~~ ~~82~~ ~~126~~ ~~94~~ 90 bytes

```
3*sum(unlist(strsplit(c('"',"#'''((()))*,,3=acilmnprsssttu"),''))==scan(,''))##()*,3amprst

```

Try it online!

*Edit1: thanks to math junkie for pointing-out a horrible bug in the original version (the `\` character): hence the temporary increase and subsequent decrease in byte-length, as successive patches were added in panic..*

*Edit2: -4 bytes: Copying the entire program into the 'look-up' string seemed wasteful (94 bytes), so instead added extra characters so that every character was present an even-number of times, and now just include half the program (character-wise) in the look-up string*

# Answer
> 2 votes
# Brachylog, 18 bytes

```
∈"∈∈\\\"∧33||"∧3|∧

```

Try it online!

Brachylog doesn't really have any good way to get quotes without escaping them in a string literal (or using the  constant, which came out longer when I tried it), so the approach I came to is to simply triple down on everything else.

(I don't know why the testing header runs out of stack after it's done every test case; I'd think it's something to do with the unbound variable output for 0 but it works fine on individual inputs... so long as an unbound variable is indeed an acceptable way to give 0. If it's not, +3 bytes)

# Answer
> 2 votes
# Python 3, 48 bytes

```
x="(x+2*chr(34)+'x=;f=eval(x)').count";f=eval(x)

```

Try it online!

Idea: Store code in string. The stored code returns function that counts characters in the string within which it is contained. Evaluate the string to get the function. Special care for characters wrapping the string.

# Python 3 without `eval` I, 48 bytes

```
 lambda c:3*(c in" \\\"(())**33::abbcddiillmmnn")

```

Try it online!

# Python 3 without `eval` II, 124 bytes

And a more creative, but much longer solution:

```
lambda c:[0o3623>(ord(c)-76)**2>195,' !!""##$$%%&&++,-..//4457889:;;==ZZ\\^^__``beeffgghhiijjkklmnnppqqrssttuuvvwwxx'][0]<<1

```

Try it online!

Idea: Ensure all characters that satisfy a certain equation (`195 < (c-76)² < 1939`) appear exactly twice in the code, and return 2 for those characters (0 for all others). Maybe someone can think of a better compression for the long string, but remember expressing it may only use the same character twice.

# Answer
> 1 votes
# Husk, 10 bytes

```
D#hs"D#hs"

```

Try it online!

```
D             Twice
 #            the number of occurrences of the input in
    "D#hs"    "D#hs",
   s          quoted,
  h           without the second quote.

```

For the same number of bytes:

# Husk, 10 bytes

```
#S+s"#S+s"

```

Try it online!

Somewhat boring adaptation of the standard `S+s"S+s+` quine.

# Answer
> 1 votes
# , 24 bytes

```
2*1#.0 :0=[
2*1#.0 :0=[

```

Try it online!

The second newline counts too, so it's not 23.

# Answer
> 1 votes
# Retina 0.8.2, 26 bytes

```
T`Tan[-a\]\n^0__-`2
[^2]
0

```

Try it online!

I got the idea to use `[-a` from @Arnauld's JavaScript answer.

**Explanation**

```
T`Tan[-a\]\n^0__-`2

```

Transliterate each of the following characters into a `2`:

* The letters `T`, `a`, and `n`
* The range `[-a` which also includes `\`, `]`, `^`, `_`, and ```
* Literal `]` and literal newline
* The characters `^`, `0`, `_`, and `-`

```
[^2]
0

```

Replace any character that is not a `2` with a `0`

# Answer
> 1 votes
# Perl 5 \+ `-plF`, 49 bytes

```
$_=q($_=grep/\Q@F/,qq(\$_=q($_);eval)=~/./g);eval

```

Try it online!

## Explanation

Pretty much the standard quine with some minor changes.

The program itself is stored in `$_` which is `eval`ed (`eval` \- along with most other functions - works on `$_` by default if no argument is specified. When the program is `eval`uated, `$_` is set to the number of matches (`~~grep`) against the input char `/\Q@F/`, which is interpolated at runtime and necessitates `\Q` to escape any special chars, against the list of chars resulting from the template string `$_=q(...);eval` with the actual program interpolated in the innermost `%_`, which is obtained with `=~/./g` (this returns a list of all the chars that matches the regex, `.` being match-all).

# Answer
> 1 votes
# Retina, 1 byte

```
1

```

Try it online!

Counts the number of 1s in the input, so the output is always 1 or 0.

Inspired by this answer on a related question.

# Answer
> 1 votes
# Ruby `-nl`, <sup>~~40...32~~</sup> 28 bytes

```
p~/[,-2\[-\]p~,..011?:]/?2:0

```

Try it online!

Derived from my answer to a related challenge. Each of the 14 distinct characters in the code appears twice. The input is tested against a regexp. The outer `[]` is a character class containing literal characters plus two character ranges: `,-2` is equivalent to the literal characters `,-./012` and `\[-\]` is equivalent to the literal characters `[\]`. The code prints `2` if the regexp matches the input character; `0` is printed otherwise.

# Answer
> 1 votes
# C (gcc), 303 bytes

```
n[4467]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,1,0,0,3,3,0,0,126,0,0,0,92,15,17,2,2,2,2,2,0,1,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,2,0,0,0,2,0,1,1,1,1,1,1,2,0,0,0,1,5,0,1,0,2,0,2,0,0,0,0,0,0,2,0,2};main(){printf("%d\n",n[getchar()]);}

```

Try it online!

# Answer
> 0 votes
# Turing Machine Code, 95 bytes

I'm not sure this counts, and if so deemed, I'll make it non-competing (or delete it if you guys think it's too egregious). The reasons why have to do with the Turing Machine Code interpreter I'm using. This affects the space character ( ), asterisk (\*), and semi-colon(;).

**Space character**
Basically it internally converts space characters into underscores '`_`'. Also, it interprets the *lack* of any character as a space character, and therefore interprets that as an underscore. Not only this, but it also interprets an actual underscore '`_`' as an underscore (or space, or lack of a character). Since the input is strictly limited to the text box on the web page, this means there is significant ambiguity as to how to count a space character. ***So that character will not work with this code.*** Any attempts at trying to fudge something here could easily and reasonably be discounted as wrong by atleast 3 different valid interpretations that I can come up with off the top of my head.

**Asterisk**
This character is set aside for a few special uses, depending on where in the code it's used. Most relevantly for this challenge, the asterisk - when used as an input check - acts as a special catch-all character. So any attempt at trying to catch this as input, catches anything and everything, including the aforementioned space character. It does so without any ability to discern an actual asterisk from the infinite possibilities. ***So that character will not work with this code.***

**Semicolon**
Lastly, the semicolon is a **very strict** line comment. You put that anywhere in that line of code, and that's it. Everything after it (inclusive) on that line is interpreted as a comment, and is ignored. As a result of this, this Turing Machine interpretor will never be able to 'read' the semicolon character '`;`'. ***So that character will not work with this code.***

```
0 0 1 r 0
0 _ 2 * 2
0 r 7 * r
0 7 3 * r
0 2 7 * 2
0 3 5 * r
0 1 2 * r
0 5 3 * r
0 * 0 * 2;3325_

```

Try it online!

I'm deeply suspicious that there is a two or three line solution to this. I'll probably play around with this for a bit some more. Having to use a comment to pad the numbers really sets off a flag in my head that this code could accomplish this task far more efficiently.

# Answer
> 0 votes
# Japt, 16 bytes

```
"UèiQÑ )"iQ èU)Ñ

```

Try it

Takes inspiration from the normal Japt quine. Essentially, counts the number of occurences in the string at the beginning (with a quote), then doubles it.

# Answer
> 0 votes
# Whitespace, 144 bytes

```
[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve_input][S N
S _Duplicate][S S S T   S S S S S N
_Push_32][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_SPACE][S N
S _Duplicate][S S S T   S S T   N
_Push_9][T  S S T   _Subtract][N
T   S T N
_If_0_Jump_to_Label_TAB][S S S T    S T S N
_Push_10][T S S T   _Subtract][N
T   S S T   N
_If_0_Jump_to_Label_NEWLINE][N
S N
N
_Jump_to_Label_PRINT][N
S S S N
_Create_Label_SPACE][S S S T    S S T   S T T   N
_Push_75][N
S N
N
_Jump_to_Label_PRINT][N
S S T   N
_Create_Label_TAB][S S S T  S S S S T   N
_Push_33][N
S N
N
_Jump_to_Label_PRINT][N
S S S T N
_Create_Label_NEWLINE][S S S T  S S T   S S N
_Push_36][N
S S N
_Create_Label_PRINT][T  N
S T _Print_as_integer_to_STDOUT]

```

Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

**Explanation in pseudo-code:**

```
Character c = STDIN as character
If(c == ' '):
  Print 75 to STDOUT
Else-if(c == '\t'):
  Print 33 to STDOUT
Else-if(c == '\n'):
  Print 36 to STDOUT
Else:
  Print 0 to STDOUT

```

This sounds pretty straight-forward, but it was reasonably tricky to get the correct numbers. Pushing a number in Whitespace is done as follows:

* `S`: Enable Stack Manipulation
* `S`: Push number
* `S`/`T`: Positive/negative respectively
* Some `T`/`S` followed by a single `N`: Decimal as binary, where `T` is 1 and `S` is 0

So, after I created the template of my program, the amount of newlines were fixed and I could simply print 36 in that case.
But the amount of spaces and tabs are variable. If I correct the count-output of the amount of spaces, the tabs would be incorrect, and vice-versa. This required some tweaking, which I eventually did without wasting any bytes by using a Label `ST` for the `Label_NEWLINE`. Usually I create Labels in the following order, based on the amount of times it's used: (empty label); `S`; `T`; `SS`; `ST`; `TS`; `TT`; `SSS`; etc. In this case, I've skipped the `SS` and used `ST` instead, allowing me to print 75 and 33 with the binary pushes of `TSSTSTT` and `TSSSST` for the counts of spaces and tabs respectively.

# Answer
> 0 votes
# Vyxal, ~~12~~ 8 bytes

```
`I$O`I$O

```

Try it Online!

Back then, there was no quine cheese. Now there is.

## Explained

```
`I$O`I$O
`I$O`    # The string "I$O"
     I   # surrounded in backticks and appended to itself
      $O # Get the count of the input in that.

```

---
Tags: code-golf, quine, self-referential
---


# Question
Title: Find numbers within the Copeland–Erdős constant
# Background

The Copeland–Erdős constant is the concatenation of "0." with the base 10 representations of the prime numbers in order. Its value is

```
0.23571113171923293137414...

```

See also OEIS A033308.

Copeland and Erdős proved that this is a normal number. This implies that every natural number can be found at some point in the decimal expansion of the Copeland-Erdős constant.

# The challenge

Given a positive integer, express it in base 10 (without leading zeros) and output the index of its first appearance within the sequence of decimal digits of the Copeland–Erdős constant.

Any reasonable input and output format is allowed, but input and output should be in base 10. In particular, the input can be read as a string; and in that case it can be assumed not to contain leading zeros.

Output may be 0-based or 1-based, starting from the first decimal of the constant.

The actual results may be limited by data type, memory or computing power, and thus the program may fail for some test cases. But:

* It should work in theory (i.e. not taking those limitations into account) for any input.
* It should work in practice for at least the first four cases, and for each of them the result should be produced in less than a minute.

# Test cases

Output is here given as 1-based.

```
13       -->         7   # Any prime is of course easy to find
997      -->        44   # ... and seems to always appear at a position less than itself
999      -->      1013   # Of course some numbers do appear later than themselves
314      -->       219   # Approximations to pi are also present
31416    -->     67858   # ... although one may have to go deep to find them
33308    -->     16304   # Number of the referred OEIS sequence: check
36398    -->     39386   # My PPCG ID. Hey, the result is a permutation of the input!
1234567  -->  11047265   # This one may take a while to find

```

# Answer
# 05AB1E, 14 bytes

Uses **0-indexed output**. Prime functions in osabie are *very* inefficient. Code:

```
[NØJD¹å#]¹.Oð¢

```

Explanation:

```
[       ]        # Infinite loop...
 N               # Get the iteration value
  Ø              # Get the nth prime
   J             # Join the stack
    D            # Duplicate this value
     ¹å#         # If the input is in this string, break out of the loop
         ¹.O     # Overlap function (due to a bug, I couldn't use the index command)
            ð¢   # Count spaces and implicitly print

```

Uses the **CP-1252** encoding. Try it online!.
> 6 votes

# Answer
# Python 2, 64 bytes

```
f=lambda n,k=2,m=1,s='':-~s.find(`n`)or f(n,k+1,m*k*k,s+m%k*`k`)

```

Returns the 1-based index. Test it on Ideone.
> 7 votes

# Answer
# Jelly, 17 bytes

```
ÆRDFṡL}i
Ḥçßç?
çD

```

Returns the 1-based index. Try it online! or verify most test cases.

I've verified the last test case locally; it took 8 minutes and 48 seconds.

### How it works

```
çD        Main link. Argument: n (integer)

 D        Decimal; yield A, the array of base 10 digits of n.
ç         Call the second helper link with arguments n and A.

Ḥçßç?     Second helper link. Left argument: n. Right argument: A.

Ḥ         Unhalve; yield 2n.
    ?     If...
   ç        the first helper link called with 2n and A returns a non-zero integer:
 ç            Return that integer.
          Else:
  ß           Recursively call the second helper link with arguments 2n and A.

ÆRDFṡL}i  First helper link. Left argument: k. Right argument: A.

ÆR        Prime range; yield the array of all primes up to k.
  DF      Convert each prime to base 10 and flatten the resulting nested array.
     L}   Yield l, the length of A.
    ṡ     Split the flattened array into overlapping slices of length l.
       i  Find the 1-based index of A in the result (0 if not found).

```

## Alternate version, 11 bytes (non-competing)

```
ÆRVw³
ḤÇßÇ?

```

The `w` atom did not exist when this challenge was posted. Try it online!

### How it works

```
ḤÇßÇ?  Main link. Argument: n (integer)

Ḥ      Unhalve; yield 2n.
    ?  If...
   Ç     the helper link called with argument 2n returns a non-zero integer:
 Ç         Return that integer.
       Else:
  ß      Recursively call the main link with argument 2n.

ÆRVw³  Helper link. Argument: k (integer)

ÆR     Prime range; yield the array of all primes up to k.
  V    Eval; concatenate all primes, forming a single integer.
    ³  Yield the first command-line argument (original value of n).
   w   Windowed index of; find the 1-based index of the digits of the result to
       the right in the digits of the result to the left (0 if not found).

```
> 5 votes

# Answer
## Actually, 19 bytes

```
╗1`r♂Pεj╜@íu`;)╓i@ƒ

```

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

```
╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗                    push input to register 0
  `r♂Pεj╜@íu`;)      push this function twice, moving one copy to the bottom of the stack:
   r♂Pεj               concatenate primes from 0 to n-1 (inclusive)
        ╜@íu           1-based index of input, 0 if not found
1              ╓     find first value of n (starting from n = 0) where the function returns a truthy value
                i@   flatten the list and move the other copy of the function on top
                  ƒ  call the function again to get the 1-based index

```
> 4 votes

# Answer
# Husk, 6 bytes

```
€ṁdİpd

```

Try it online!

Prime number infinite list babyyyyy
> 4 votes

# Answer
# Julia, 55 bytes

```
\(n,s="$n",r=searchindex(n|>primes|>join,s))=r>0?r:3n\s

```

Returns the 1-based index. Completes all test cases in under a second. Try it online!
> 3 votes

# Answer
# Pyth, 17 bytes

```
 fhJxs`MfP_YSTz2J

```

Leading space is important.

Test suite.
> 3 votes

# Answer
# , 37 bytes

```
(0{":@[I.@E.[:;<@":@p:@i.@]) ::($:+:)

```

Input is given as a base 10 integer and the output uses zero-based indexing.

## Usage

```
   f =: (0{":@[I.@E.[:;<@":@p:@i.@]) ::($:+:)
   f 1
4
   f 13
6
   f 31416
67857

```

## Explanation

This first call treats the verb as a monad, however subsequent calls which may occur recursively treat it as a dyad.

```
0{":@[I.@E.[:;<@":@p:@i.@]  Input: n on LHS, k on RHS
                         ]  Get k
                      i.@   Get the range [0, 1, ..., k-1]
                   p:@      Get the kth prime of each
                ":@         Convert each to a string
              <@            Box each string
           [:;              Unbox each and concatenate to get a string of primes
     [                      Get n
  ":@                       Convert n to a string
      I.@E.                 Find the indices where the string n appears in
                            the string of primes
0{                          Take the first result and return it - This will cause an error
                            if there are no matches

(...) ::($:+:)  Input: n on RHS, k on LHS
(...)           Execute the above on n and k
      ::(    )  If there is an error, execute this instead
           +:   Double k
         $:     Call recursively on n and 2k

```
> 2 votes

# Answer
# Ruby `-rprime`, 48 bytes

0-based.

```
->n{s=""
Prime.find{s<<_1.to_s=~/#{n}/}
$`.size}

```

Attempt This Online!
> 2 votes

# Answer
# Raku, 45 bytes

```
{{$~={$_ x.is-prime}(++$)}...*~~/$_/;$/.from}

```

Try it online!

Really had to dig deep to bring the byte count way down here. The code generates a warning, but oh well!

The first bracketed expression generates strings consisting of the concatenation of successive primes. `++$` increments an anonymous state variable, and that number is passed to an anonymous function `{ $_ x .is-prime }`, which replicates the stringified number once if it's prime, and zero times (ie, to an empty string) if it isn't. That string is appended to another anonymous state variable that keeps the concatenation of all primes seen so far with `$ ~=`. The sequence looks like `2, 23, 23, 235, 235, 2357, 2357, 2357, 2357, 235711, ...`, with a repeated element whenever there isn't a prime. Very inefficient!

The sequence terminates when the ending condition `* ~~ /$_/` is met; that is, when the concatenated string of primes matches the input number interpolated into a regex. That has the side effect of storing the resulting Match object into `$/`. Then the function just returns `$/.from`, the starting position of the match in the string of primes.
> 2 votes

# Answer
## PowerShell v2+, 90 bytes

```
for($a="0.";!($b=$a.IndexOf($args)+1)){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){$a+=$i}}$b-2

```

Combines the logic of my Find the number in the Champernowne constant answer, coupled with the prime generation method of my Print the nth prime that contains n answer, then subtracts `2` to output the index appropriately (i.e., not counting the `0.` at the start).

Takes input as a string. Finds the `999` one in about seven seconds on my machine, but the `33308` one in quite a bit longer (*edit - I gave up after 90 minutes*). Should theoretically work for any value up to index `[Int32]::Maxvalue` aka `2147483647`, as that's the maximum length of .NET strings. Will likely run into memory issues long before that happens, however.
> 1 votes

---
Tags: code-golf, math, string, number, number-theory
---


# Question
Title: List all possible titles for the Anno games
In the Anno video game series there are 6 games with a 7th one announced for early 2019. Their titles always feature a year in a specific pattern:

`Anno 1602, Anno 1503, Anno 1701, Anno 1404, Anno 2070, Anno 2205, Anno 1800`

* The digital sum is always 9.
* The years are four digits long.
* They contain at least one zero.

Within these constrains there exist 109 possible titles:

```
[1008,1017,1026,1035,1044,1053,1062,1071,1080,1107,1170,1206,1260,1305,1350,1404,1440,1503,1530,1602,1620,1701,1710,1800,2007,2016,2025,2034,2043,2052,2061,2070,2106,2160,2205,2250,2304,2340,2403,2430,2502,2520,2601,2610,2700,3006,3015,3024,3033,3042,3051,3060,3105,3150,3204,3240,3303,3330,3402,3420,3501,3510,3600,4005,4014,4023,4032,4041,4050,4104,4140,4203,4230,4302,4320,4401,4410,4500,5004,5013,5022,5031,5040,5103,5130,5202,5220,5301,5310,5400,6003,6012,6021,6030,6102,6120,6201,6210,6300,7002,7011,7020,7101,7110,7200,8001,8010,8100,9000]

```

Your objective is to list them all in any reasonable form in the fewest number of bytes.

# Answer
> 20 votes
# , ~~59~~ 51 bytes

Outputs the valid numbers as the *names* of a list of 201's. Why 201? Because ASCII 0 is 48, and 4\*48+9 is... yeah. Saved 6 bytes by aliasing `^` to `Map` and another 2 by using `1:9e3` as range.

```
"^"=Map;x=sum^utf8ToInt^grep(0,1:9e3,,,T);x[x==201]

```

Try it online!

# Explanation

```
# Create list of sums of ASCII char values of numbers,
# with the original numbers as the names of the list
x <- Map(sum,
  # Create a list from the strings where each element is the string split
  # into ASCII char values
  Map(utf8ToInt,
      # Find all numbers between 1 and 9e3 that contain a zero
      # Return the matched values as a vector of strings (6th T arg)
      grep(pattern=0,x=1:9000,value=TRUE)
  )
)
# Pick out elements with value 201 (i.e. 4-digits that sum to 9)
# This implicitly only picks out elements with 4 digits, since 3-digit
# sums to 9 won't have this ASCII sum, letting us use the 1:9e3 range
x[x==201]

```

# Answer
> 17 votes
# Perl 6, ~~35~~ 33 bytes

*-2 bytes thanks to Jo King*

```
{grep {.ords.sum==201&&/0/},^1e4}

```

Try it online!

# Answer
> 10 votes
# Python 2, ~~67~~ ~~66~~ 64 bytes

```
print[y for y in range(9001)if('0'in`y`)*sum(map(ord,`y`))==201]

```

Try it online!

---

Saved:

* -1 byte, thanks to Luis felipe De jesus Munoz
* -2 bytes, thanks to Kevin Cruijssen

# Answer
> 9 votes
# Jelly, 11 bytes

```
9ȷṢ€æ.ẹ9ṫ19

```

Try it online!

### How it works

```
9ȷṢ€æ.ẹ9ṫ19  Main link. No arguments.

9ȷ           Set the left argument and the return value to 9000.
  Ṣ€         Sort the digits of each integer in [1, ..., 9000].
    æ.       Perform the dot product of each digit list and the left argument,
             which gets promoted from 9000 to [9000].
             Overflowing digits get summed without multiplying, so we essentially
             map the digit list [a, b, c, d] to (9000a + b + c + d).
      ẹ9     Find all 1-based indices of 9.
             Note that 9000a + b + c + d == 9 iff a == 0 and b + c + d == 9.
        ṫ19  Tail 19; discard the first 18 indices.

```

# Answer
> 7 votes
# PowerShell, ~~50~~ 49 bytes

```
999..1e4-match0|?{([char[]]"$_"-join'+'|iex)-eq9}

```

Try it online!

Constructs a range from `999` to `10000`, then uses inline `-match` as a filter to pull out those entries that regex match against `0`. This leaves us with `1000, 1001, 1002, etc.` We then pipe that into a `Where-Object` clause where we take the current number as a string `"$_"`, cast it as a `char`-array, `-join` those characters together with `+` and `I`nvoke-`Ex`pression (similar to eval) to come up with their digit sum. We check whether that is `-eq`ual to `9`, and if so it's passed on the pipeline. At program completion, those numbers are picked up from the pipeline and implicitly output.

# Answer
> 6 votes
# JavaScript (ES6), ~~78~~ 73 bytes

*Saved 2 bytes thanks to @KevinCruijssen*

Returns a space-separated string.

```
f=(n=9e3)=>n>999?f(n-9)+(eval([...n+''].join`+`)&/0/.test(n)?n+' ':''):''

```

Try it online!

### How?

We iterate over the range \\$\[1008..9000\]\\$ with an increment of \\$9\\$, ignoring numbers that don't have a \\$0\\$.

All these numbers are multiples of \\$9\\$, so the sum of their digits is guaranteed to be a multiple of \\$9\\$ as well.

Because valid numbers have at least one \\$0\\$, they have no more than two \\$9\\$'s, which means that the sum of the remaining digits is at most \\$18\\$. Therefore, it's enough to test if the sum of the digits is odd.

Hence the test:

```
(eval([...n + ''].join`+`) & /0/.test(n)

```

# Answer
> 5 votes
# JavaScript (Node.js), 89 bytes

```
[...Array(9e3)].map(_=>i++,i=1e3).filter(a=>(s=[...a+""]).sort()[0]<1&eval(s.join`+`)==9)

```

Try it online!

* -4 bytes thanks to @ETHproductions

# JavaScript (Node.js), ~~129~~ ~~127~~ ~~126~~ ~~124~~ ~~115~~ ~~114~~ ~~111~~ ~~110~~ ~~105~~ ~~97~~ ~~93~~ ~~92~~ 90 bytes

```
[...Array(9e3)].map(f=(_,i)=>eval(s=[...(i+=1e3)+""].sort().join`+`)-9|s[0]?0:i).filter(f)

```

Try it online!

### Explanation

```
[...Array(9e3)].map(f=(_,i)=>eval(s=[...(i+=1e3)+""].sort().join`+`)-9|s[0]?0:i).filter(f)
[...Array(9e3)].map(f=(_,i)=>                                                  )           // Create a 9000-length array and loop over it; store the loop body
                                    [...(i+=1e3)+""]                                       // Add 1000 to the index and split it into an array of characters (17 -> ["1", "0", "1", "7"])
                                                    .sort()                                // Sort the array of characters in ascending order by their code points ("0" will always be first) (["1", "0", "1", "7"] -> ["0", "1", "1", "7"])
                                  s=                       .join`+`                        // Join them together with "+" as the separator (["0", "1", "1", "7"] -> "0+0+2+9"); store the result
                             eval(                                 )-9                     // Evaluate and test if it's different than 9
                                                                       s[0]                // Take the first character of the string and implicitly test if it's different than "0"
                                                                      |    ?0              // If either of those tests succeeded, then the number doesn't meet challenge criteria - return a falsey value
                                                                             :i            // Otherwise, return the index
                                                                                .filter(f) // Filter out falsey values by reusing the loop body

```

First time doing code golf in JavaScript. I don't think I need to say it, but if I'm doing something wrong, please notify me in the comments below.

* -3 bytes thanks to @Luis felipe De jesus Munoz
* -6 bytes thanks to @Kevin Cruijssen

# Answer
> 5 votes
# Python 2, 57 bytes

```
n=999
exec"n+=9\nif'0'in`n`>int(`n`,11)%10>8:print n\n"*n

```

Try it online!

*2 bytes thanks to Dennis*

Uses an `exec` loop to counts up `n` in steps of 9 as 1008, 1017, ..., 9981, 9990, printing those that meet the condition.

Only multiples of 9 can have digit sum 9, but multiples of 9 in this range can also have digits sum of 18 and 27. We rule these out with the condition `int(`n`,11)%10>8`. Interpreting `n` in base 11, its digit sum is equal to the number modulo 10, just like in base 10 a number equals its digit sum modulo 9. The digits sum of (9, 18, 27) correspond to (9, 8, 7) modulo 10, so taking those`>8` works to filter out nines.

The number containing a zero is check with string membership. `'0'in`n``. This condition is joined with the other one with a chained inequality, using that Python 2 treats strings as greater than numbers.

# Answer
> 4 votes
# sed and grep (and seq), ~~72~~ ~~64~~ 63 bytes

```
seq 9e3|sed s/\\B/+/g|bc|grep -wn 9|sed s/:9//|grep 0|grep ....

```

# Answer
> 4 votes
# Haskell, 55 bytes

```
[i|i<-show<$>[1..5^6],201==sum(fromEnum<$>i),elem '0'i]

```

Thanks to @Laikoni, see the comments.

Readable:

```
import Data.Char (digitToInt)

[i | i <- show <$> [1000..9999]
   , sum (digitToInt <$> i) == 9
   , '0' `elem` i
   ]

```

# Answer
> 3 votes
# , 82 bytes

```
write((x=t(expand.grid(1:9,0:9,0:9,0:9)))[,colSums(x)==9&!apply(x,2,all)],1,4,,"")

```

Try it online!

Generates a matrix `x` of all possible 4-digit numbers, excluding leading zeros, going down columns. Then filters for column (digital) sums of 9 and containing zero, i.e., not `all` are nonzero. `write` prints down the columns, so we `write` to `stdout` with a width of `4` and a separator of `""`.

Outgolfed by J.Doe

# Answer
> 3 votes
# Japt, ~~20~~ 18 bytes.

*-2 bytes thanks to @Shaggy and @ETHproductions*

```
A³òL² f_=ì)x ¥9«Z×

```

---

```
A³òL² f_=ì)x ¥9«Z×  Full program
A³òL²               Range [1000, 10000]
      f_            Filter by :
        =ì)         Convert to array
           x ¥9     Sum equal to 9?
               «    And
                Z×  Product not 0

```

Try it online!

# Answer
> 3 votes
# 05AB1E, ~~15~~ ~~13~~ ~~12~~ 10 bytes

```
₄4°ŸεW°ö9Q

```

-2 bytes thanks to *@Emigna*
-3 bytes thanks to *@Grimy*

Try it online.

**Explanation:**

```
₄4°Ÿ        # Create a list in the range [1000,10000]
    ʒ       # Filter this list by:
     W      #  Get the smallest digit in the number (without popping the number itself)
      °     #  Take 10 to the power this digit
       ö    #  Convert the number from this base to an integer (in base-10)
        9Q  #  Check if it's equal to 9

```
* If the smallest digit is \\$d=0\\$ it will become \\$1\\$ with the \\$10^d\\$ (`°`). And the number in base-1 converted to an integer in base-10 (`ö`) would act like a sum of digits.
* If the smallest digit is \\$d=1\\$ it will become \\$10\\$ with the \\$10^d\\$ (`°`). And the number in base-10 converted to an integer in base-10 (`ö`) will of course remain the same.
* If the smallest digit is \\$d=2\\$ it will become \\$100\\$ with the \\$10^d\\$ (`°`). And the number in base-100 convert to an integer in base-10 (`ö`) would act like a join with `0` in this case (i.e. `2345` becomes `2030405`).
* If the smallest digit is \\$d=3\\$ it will become \\$1000\\$ with the \\$10^d\\$ (`°`). And the number in base-100 convert to an integer in base-10 (`ö`) would act like a join with `00` in this case (i.e. `3456` becomes `3004005006`).
* ... etc. Smallest digits \\$d=\[4,9\]\\$ would act the same as \\$d=2\\$ and \\$d=3\\$ above, with \\$d-1\\$ amount of `0`s in the 'join'.

If the smallest digit is \\$\>0\\$ with the given range \\$\[1000,10000\]\\$, the resulting number after `°ö` would then be within the range \\$\[1111,9000000009000000009000000009\]\\$, so can never be equal to \\$9\\$. If the result is equal to \\$9\\$ (`9Q`) it would mean the smallest digit is \\$d=0\\$, resulting in a base-1 with `°ö`; and the sum of the digits was \\$9\\$.

# Answer
> 3 votes
# Java 8, ~~128~~ ~~117~~ 115 bytes

```
v->{int i=109,r[]=new int[i],n=i;for(;i>0;n++)if((n+"").chars().sum()==201&(n+"").contains("0"))r[--i]=n;return r;}

```

-11 bytes thanks to *@nwellnhof*.

Try it online.

**Explanation:**

```
v->{                              // Method with empty unused parameter & int-array return
  int i=109,                      //  Index-integer, starting at 109
      r[]=new int[i],             //  Result-array of size 109
      n=i;                        //  Number integer, starting at 109
   for(;i>0;                      //  Loop as long as `i` is not 0 yet:
       n++)                       //    After every iteration, increase `n` by 1
     if((n+"").chars().sum()==201 //   If the sum of the unicode values of `n` is 201,
                                  //   this means there are four digits, with digit-sum = 9
        &(n+"").contains("0"))    //   and `n` contains a 0:
       r[--i                      //    Decrease `i` by 1 first
            ]=n;                  //    And put `n` in the array at index `i`
  return r;}                      //  Return the array as result

```

# Answer
> 3 votes
# , 85 bytes

(just competing for the best abuse of R square brackets ... :P )

```
`[`=`for`;i[a<-0:9,j[a,k[a,w[a,if(sum(s<-c(i,j,k,w))==9&any(!s)&i)write(s,1,s='')]]]]

```

Try it online!

# Answer
> 2 votes
# Octave, 49 bytes

*6 bytes saved using a more convenient output format as suggested by J.Doe.*

*Thanks to @Laikoni for a correction*.

```
y=dec2base(x=1e3:9999,10)'-48;x(sum(y)==9>all(y))

```

Try it online!

# Answer
> 2 votes
# APL(Dyalog), ~~33~~ 29 bytes

```
1e3+⍸(0∘∊∧9=+/)¨⍎¨∘⍕¨1e3+⍳9e3

```

*-4 bytes thanks to @Adam*

Try it online!

# Answer
> 2 votes
## PHP, ~~69, 87 bytes~~ 74 bytes

~~`for($i=999;$i<9001;$i++){echo((array_sum(str_split($i))==9&strpos($i,"0")!=0)?$i:" ");}`~~ `for($i=999;$i++<1e4;)echo!strpos($i,48)|array_sum(str_split($i))-9?" ":$i;`

Note this puts a space for every "failed" number, leading to some kind of funky spacing. This can be changed to comma separation, but will add another 4 characters: `?$i.",":""`

Got bigger because I wasn't checking for 0. Derp. Shortened by 13 by Titus!

# Answer
> 2 votes
# Ruby, ~~46 42~~ 41 bytes

```
?9.upto(?9*4){|x|x.sum==201&&x[?0]&&p(x)}

```

Try it online!

### How it works:

* Iterate on strings ranging from '9' to '9999'
* Check that sum of ASCII values is 201
* Check if string contains a zero (without regex, a regex would be 1 byte longer)

(Thanks Laikoni for -2 bytes)

# Answer
> 2 votes
# Pip, 18 bytes

```
{0Na&$+a=9}FIm,t*m

```

Use an ouput-format flag such as `-p` to get readable output. Try it online!

```
{0Na&$+a=9}FIm,t*m
             m,t*m  Range from 1000 to 10*1000
{         }FI       Filter on this function:
 0Na                 There is at least one 0 in the argument
    &                and
     $+a             The sum of the argument
        =9           equals 9

```

# Answer
> 2 votes
# Wolfram Language (Mathematica), ~~56~~ 55 bytes

```
Select[9!!~Range~9999,Tr@#==Times@@#+9&@*IntegerDigits]

```

Try it online!

We test the range from 9!! = 945 to 9999, since there are no results between 945 and 999. Maybe there's a shorter way to write a number between 9000 and 10007, as well.

`Tr@#==Times@@#+9&` applied to `{a,b,c,d}` tests if `a+b+c+d == a*b*c*d+9`, which ends up being equivalent to The Anno Condition.

# Answer
> 2 votes
# Dart,  ~~103 100~~  96 bytes

```
f()=>List.generate(9001,(i)=>'$i').where((i)=>i.contains('0')&&i.runes.fold(0,(p,e)=>p+e)==201);

```
- -3 bytes by setting the value in the array to string, making the conversion once and not twice
- -4 bytes by using runes instead of codeUnits

Pretty self-explanatory. generates a list of 9001 (0-9000) cells with the cell's index as value, filters the ones containing a 0 then the one having an ASCII sum of 201 (The result if all the ASCII characters sum to 9). These conditions implictly include that the year is 4 digits long because using 2 ASCII numbers (and the 0), you cannot reach 201.

Try it on Dartpad!

# Answer
> 2 votes
# Bash (with `seq`, `grep`), 39 bytes

```
seq 0 9 1e4|egrep '([0-4].*){3}'|grep 0

```

Try it online!

# Answer
> 2 votes
# K (ngn/k), 22 bytes

```
55_&(|/~a)&9=+/a:!4#10

```

Try it online!

# Answer
> 2 votes
# APL (Dyalog Unicode), 23 bytes

```
55↓⍸(×⌿<9=+⌿)10⊥⍣¯1⍳9e3

```

Try it online!

# Answer
> 2 votes
# Scala (76 63 61 56 bytes)

```
for(n<-0 to 9000;t=n+""if t.sum==201&t.min<49)println(t)

```

Try it online

* Thanks to Laikoni for the suggestions
* Two more bytes shed after applying Jo King's comment

# Answer
> 2 votes
# Vyxal, 13 bytes

```
k1k2r'∑9=n0c∧

```

Try it Online!

Extremely slow.

# Answer
> 1 votes
# Tcl, 77 bytes

```
time {if [incr i]>1e3&[regexp 0 $i]&9==[join [split $i ""] +] {puts $i}} 9999

```

Try it online!

# Answer
> 1 votes
# , 38 bytes

-1 byte and bug fixed thanks to Quintec

```
echo(#~(4#10)(0&e.*9=+/)@#:])1e3+i.9e3

```

Try it online!

Thanks to Laikoni for findng an even bigger bug!

# Answer
> 1 votes
# Japt, 16 bytes

Returns an array of digit arrays.

```
L²õì l4 k_×ª9aZx

```

Test it

---

## Explanation

```
L                    :100
 ²                   :Squared
  õ                  :Range [1,L²]
   ì                 :Convert each to a digit array
     l4              :Filter elements of length 4
        k_           :Remove each Z that returns truthy (not 0)
          ×          :  When reduced by multiplication
           ª         :  OR
              Zx     :  When reduced by addition
            9a       :   And subtracted from 9

```

# Answer
> 1 votes
# APL(NARS), 45 chars, 90 bytes

```
f←{⍵×⍳(0∊x)∧9=+/x←⍎¨⍕⍵}⋄f¨1e3..5e3⋄f¨5e3..9e3

```

test afther some formatting:

```
1008  1017  1026  1035  1044  1053  1062  1071  1080  1107  1170  1206  1260
  1305  1350  1404  1440  1503  1530  1602  1620  1701  1710  1800  2007  2016
  2025  2034  2043  2052  2061  2070  2106  2160  2205  2250  2304  2340
  2403  2430  2502  2520  2601  2610  2700  3006  3015  3024  3033  3042  3051
  3060  3105  3150  3204  3240  3303  3330  3402  3420  3501  3510  3600
  4005  4014  4023  4032  4041  4050  4104  4140  4203  4230  4302  4320  4401
  4410  4500
5004  5013  5022  5031  5040  5103  5130  5202  5220  5301  5310  5400  6003
  6012  6021  6030  6102  6120  6201  6210  6300  7002  7011  7020  7101  7110
  7200  8001  8010  8100  9000

```

possible alternative

```
r←f;i;x
   r←⍬⋄i←1e3⋄→B
A: r←r,i
B: i+←1⋄→A×⍳(0∊x)∧9=+/x←⍎¨⍕i⋄→B×⍳i≤9e3

```

# Answer
> 1 votes
# Jelly, 13 bytes

```
ȷ4µṢÄm3Ḍ)ẹ9ṫ4

```

**Try it online!**

### How?

```
ȷ4µṢÄm3Ḍ)ẹ9ṫ4 - Link: no arguments
ȷ4            - literal 10^4 = 10000
  µ     )     - for each in range (1,2,3,...,10000): e.g. 3042       or  5211
   Ṣ          -   sort (given an integer makes digits)    [0,2,3,4]      [1,1,2,5]
    Ä         -   cumulative addition                     [0,2,5,9]      [1,2,4,9]
     m3       -   modulo 3 slice (1st,4th,7th...)         [0,9]          [1,9]
       Ḍ      -   convert from decimal digits             9              19
         ẹ9   - 1-based indices equal to nine             [9,99,999,1008,1017,...,8100,9000]
           ṫ4 - tail from the 4th index                   [1008,1017,...,8100,9000]

```

# Answer
> 1 votes
# Stax, 13 bytes

```
ü┌o☻≈;╫▄mI░↨Z

```

Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

```
VM      Constant one million
        this program produces its output pretty quickly, but takes much longer to end
f       filter the numbers [1..n] using the rest of the program as a predicate
  $     convert to ascii decimal string e.g. "1234"
  |+    sum of ascii codes
  201=  is equal to 201 [result a]
  _E:*  product of the decimal digits [result b]
  >     [result a] is greater than [result b]

```

Run this one

# Answer
> 1 votes
# MathGolf, ~~16~~ 13 bytes

```
♫♪↨Ç{▒ε*\Σ8=┌

```

Try it online!

### Explanation:

```
  ↨              Range from
♫♪               1000 to 10000
   Ç{            Filter out by
     ▒ε*         The product of all digits is not 0
        Σ8=┌     The digit sum of the loop index (0 based) is not equal to 8

```

# Answer
> 1 votes
# JavaScript (SpiderMonkey), 57 bytes

```
for(y=0;y<9e3;)/(?=([0-4].?){3}).*0/.test(y+=9)&&print(y)

```

Try it online!

---

# JavaScript (SpiderMonkey), 58 bytes

```
for(y=999;++y<1e4;9-p-q-r-s|q*r*s||print(y))[p,q,r,s]=''+y

```

Try it online!

~~You may change `print` to `alert` to test it in your browser. :)~~

# Answer
> 1 votes
# K (oK), 37 bytes

```
x@&{9=+/x*0in x}'(4#10)\'x:1000+!9000

```

Try it online!

On mobile, will add explanation later. Couldn't get `0 in'` to work without the lambda which wastes bytes...

# Answer
> 1 votes
# Common Lisp, 140 bytes

```
(defun x()(loop for x from 1008 to 9000 for y =(map'list #'digit-char-p(prin1-to-string x))when(and(member 0 y)(=(apply #'+ y)9))collect x))

```

Try it online!

# Answer
> 1 votes
# Julia 1.0, 52 bytes

```
f()=[x for x=1:9^5 if'0' in"$x"&&sum(Int,"$x")==201]

```

Try it online!

# Answer
> 1 votes
# K (ngn/k), 33 bytes

```
t@&"0"=*'t@'<'t:$&201=+/'i:$!9001

```

Try it online!

Will edit with explanation later.

# Answer
> 1 votes
# C (clang), ~~95~~ 91 bytes

```
f(i){char*c;for(i=1e4;--i;*c+c[1]+c[2]+c[3]-201||index(c,48)&&puts(c))asprintf(&c,"%d",i);}

```

Try it online!

-4 bytes thanks to @ceilingcat

# Answer
> 1 votes
# Haskell, ~~66 79~~ 74 bytes

```
drop 55[x>>=show|x<-sequence.replicate 4$[0..9],sum x==9,elem 0x]

```

Damn you with your type juggling, you can treat numbers as strings :(

Basically just an exact description of whats asked here. Just no spaces.

Try it online! (Modifications for it to *run* were necessary, tio doesn't support pure functions in Haskell.)

# Answer
> 0 votes
# Retina 0.8.2, 52 bytes

```

9001$*
.
$.`=>$.`;
>|\G\d
$*
M!`\d{4}(?==1{9};)
G`0

```

Try it online! Explanation:

```

9001$*

```

Insert 9001 `1`s.

```
.
$.`=>$.`;

```

Replace each `1` with the number of `1`s to its left, followed by `=>`, followed by the same number again, followed by `;`.

```
>|\G\d
$*

```

Convert `>` and subsequent digits to unary, thus calculating the digit sum.

```
M!`\d{4}(?==1{9};)

```

List all the 4-digit numbers with a digit sum of 9.

```
G`0

```

Keep those that contain a zero.

# Answer
> 0 votes
# Jelly, 13 bytes

```
ȷ4ȷrDS9Ƒ>ẠƲƇḌ

```

Try it online!

-2 (yucky, yucky trivial) bytes thanks to Dennis.

# Answer
> 0 votes
# Red, 109 bytes

```
repeat n 8000[s: 0 p: 1 foreach t form d: 1000 + n[s: s + r: do t - 48 p: p * r]if all[s = 9 p = 0][print d]]

```

Try it online!

# Answer
> 0 votes
# Pyth, ~~22~~ 19 bytes

```
f&}\0Tq201sCMT`M^T4

```

Output is an array of strings. Try it online here.

```
f&}\0Tq201sCMT`M^T4
              `M^T4   Array of strings of numbers 0-999
f                     Keep the elements of the above, as T, where:
           CMT          Get the code points of each character in T
          s             Take the sum
      q201              Does the above == 201?
  }\0T                  Does T contain "0" ?
 &                      Logical AND the two previous results

```

The 201 trick is the same as used in other answers.

Previous answer, without using 201 trick, 22 bytes: `iRTf}0Tfq9sTjRTr^T3^T4`

# Answer
> 0 votes
# PHP, 114 bytes

```
<?php
for($i=1e3;$i<=9e3;$i++)
    if(array_sum($a=[$i/1e3%10,$i/100%10,$i/10%10,$i%10])==9&in_array(0,$a))
        echo $i.' ';

```

Try it online!

# Answer
> 0 votes
# Prolog 117 bytes

`b(X):-between(0,9,X).
w(X):-write(X).
y():-b(A),b(B),b(C),b(D),X is A+B+C+D,X=9,(A=0;B=0;C=0;D=0),w(A),w(B),w(C),w(D).`

# Answer
> 0 votes
# , 35 bytes

```
echo@>55}.I.(4#10)(*/<9=+/)@#:i.1e4

```

Try it online!

# Answer
> 0 votes
# C# (.NET Core), 106 bytes

```
for(int i=999;++i<9999;)if(i.ToString().Sum(c=>c-'0')==9&&i.ToString().Contains("0"))Console.WriteLine(i);

```

Try it online!

Ungolfed:

```
for(int i = 999; ++i < 9999;)               // from 1000 to 9999 (fulfills four digit parameter)
    if(i.ToString().Sum(c => c - '0') == 9  // if the sum of the digits is nine
            && i.ToString().Contains("0"))  //   and if the year contains at least one zero
        Console.WriteLine(i);               // write the year to the console

```

# Answer
> 0 votes
# Perl 5 `-MList::Util=sum`, ~~40~~ 32 bytes

```
map/0/*9-(sum/./g)||say,1E3..9E3

```

Try it online!

# Answer
> 0 votes
# Scala, 58 bytes

jrook's solution is currently 2 byte shorter

```
val v=(9 to 9000).filter(x=>(x+"").min<49&(x+"").sum==201)

val v=(9 to 9000).map(_+"").filter(x=>x.min<49&x.sum==201)

```

Try it online!

# Answer
> 0 votes
# Attache, 37 bytes

```
{{Sum@Ords@_=201and"0"in _}@S\1:9000}

```

Try it online!

Based on the perl answer.

# Answer
> 0 votes
# Kotlin, 59 bytes

Lambda that returns a `List<Int>` containing every valid year.

```
{(1008..9000).filter{"$it".sumBy{it-'0'}==9&&'0' in "$it"}}

```

Try it online!

# Answer
> 0 votes
# Deadfish~

```
{iiiii}dcdcc{i}ddc{d}iiicdciciiiiiicddddddcdciiciiiicdddddcdciiiciicddddcdciiiiccdddcdciiiiicddcddcdciiiiiicddddcdcdc{i}dddcddddddccdc{i}ddc{d}iiciccdc{i}dddcddddddcciiiiiic{d}iiicicicddciiiiiicdddddciciiiicddddddciciicdddciiiiicddddciiciicdddddciciiicddddciiiicdddciiiccddddciciiiicdddddciiicddciiiicddcdddciciiiiicddddddciicdciiiiicddddcddciciiiiiic{d}iiicicciiiiiicddddddcdcic{i}dddc{d}iicciicddcc{i}dddcdddddcddciciiiiicddddcddciiciiicdddcddciiicicddcddciiiicdcdcddciiiiicdddccddciiiiiicdddddcicddc{i}dddc{d}iiiciicdcdciiiiiicddddcdciiiiicddddddciiccddciiiiicdddcciiicdddddciicicdddciiiicddcicicddddciiciicddddciiicdciicdcdddciiciiicdddddciicciiicdddcddciiciiiicddddddciciciiiicdddddcdciiciiiiic{d}iiicciiicdddcciiiiiicdddcdddciciiiicddcdddciiciicdcdddciiicccdddciiiicddcicdddciiiiicddddciicdddciiiiiicddddddciiicddcdciiiiicddcddciiiicdddddciiicdcddciiiicdcdciicddddciiiccdddciiiccccdddciiicicddddciicicicddcddciiiciicdddddciciiciicddddcdciiiciiicddddddcciiiicddddcciiiiicdcddddciciiiccddddciicicicddddciiicdciicddddciiiicdddciiicddddciiiiicdddddciiiicdddcdciiiiccdddciiicddddciiiicddcddciiicicddcicdddciiiicdcdddciiciicdcdcddciiiiccddddciciiiccdddcdciiiicicdddddcciiiiicdddddcciiiicicdddddciciiciicdddddciicciiicdddddciiicddciiiicdddddciiiicddddciiiiicddddcdciiiciicddddciicdddciiiiicdddcddciiciiicdddccddciiiiicddcdddciciiiicddcddcdciiiiicdcddddcciiiiiicddddddcciiiciiicddddddciciciiiicddddddciicdciiiiicddddddciiicdddciiiiiicdddddcdciiciiiicdddddcicddciiiiiicddddcddciciiiiicddddcdcdciiiiiicdddcdddcc{i}dddc{d}iiicciiciiiiic{d}iiicicciiiiiic{d}iiiciicddc{i}dddcddddddcdciciiiiiicddddddccdc{i}dddcdddddcddcc{i}ddc{d}iiccic{i}dddc{d}iicicdc{i}ddc{d}iiicdcc{i}dc{d}iccc

```

Do I need the spaces?

---
Tags: code-golf, number, kolmogorov-complexity
---


title: Make me an Easter egg!

text:
# Question
Title: Make me an Easter egg!
> No, not the `^^vv<><>BA` kind of Easter eggs, real Easter eggs that we paint.

Here is an (awfully drawn) egg.

```
  __
 /  \
/    \
|    |
\____/

```

In easter, we paint them with patterns. Like these:

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

```

---

# The challenge

Given a character (printable ascii) to paint the egg, print the painted egg.

**Examples:**

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

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

```

# Specs

* Trailing newlines/spaces are allowed.

# Answer
> 17 votes
# Brain-Flak `-c`, ~~270~~ ~~268~~ 266 bytes

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

```

Try it online!

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

# Answer
> 12 votes
## Python 2, 62 bytes

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

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

```

# Answer
> 11 votes
# Charcoal, ~~30~~ ~~26~~ 16 bytes

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

```
__↗¹←↑¹↖²↓_‖Ｍ←¤Ｓ

```

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 _
‖Ｍ←                          Reflect the canvas to the left
¤Ｓ                           Fill the shape with the string input

```

# Answer
> 9 votes
# 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:  __
                                         /~~\
                                        /~~~~\
                                        |~~~~|
                                        \____/

```

# Answer
> 6 votes
# 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!

```
f=

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

o.innerText=f` `;i.addEventListener("input",function(){o.innerText=f(this.value||" ");})
```

```
<input maxlength="1" id="i">
<pre id=o></pre>
```

# Answer
> 6 votes
# Sed, 43 characters

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

```

Sample run:

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

```

# Answer
> 5 votes
## 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.

```

# Answer
> 4 votes
# 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*

# Answer
> 4 votes
# Carrot, 34 bytes

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

```

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).

# Answer
> 4 votes
# 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..

# Answer
> 4 votes
# Brainfuck - 257 bytes 181 bytes

Golfed: Live version click here

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

```

I'm not a professional golfer though; this is my first attempt.

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
++++++++++[>+++>+<<<++++<+<+>>>-]
>++<
<<--<+
>>>,
>..<<<<..>>>>>.<.
<<<<<.
>>>>..<<.>>>>.
<<<<<<.>>>>....<<.>>>>.
<<<.>....<.
>>>.<<<<.<....<.

```

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# Retina 0.8.2, ~~43~~ 41 bytes

-2 bytes thanks to Kevin Cruijssen

```
.
$&$&
..
  __¶ /$&\¶/$&$&\¶|$&$&|¶\____/

```

Try it online!

# Answer
> 3 votes
# 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)

# Answer
> 2 votes
# 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!

# Answer
> 2 votes
# 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);

```

# Answer
> 2 votes
# 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!

# Answer
> 2 votes
## 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.

# Answer
> 2 votes
# brainfuck, 114 bytes

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

```

Try it online!

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

# Answer
> 1 votes
# SpecBAS - 70 bytes

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

```

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

# Answer
> 1 votes
# Röda, 46 bytes

```
{a=`  __
 /-\
/--\
|--|
\____/`a~="-",_*2;[a]}

```

Try it online!

# Answer
> 1 votes
# Python, 59 bytes

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

```

# Answer
> 1 votes
# Swift - 88 bytes

```
var f={x in"  __\n /&&\\\n/&&&&\\\n|&&&&|\n\\____/".replacingOccurrences(of:"&",with:x)}

```

Lambda-like function with usage: `print(f("x"))`.

**Try it out here!**

---

***NOTE:*** *In some environments, as in the one linked above, this requires `import Foundation`, but on a standard project it doesn't. That's because `replacingOccurrences()` belongs to `Foundation`, but Xcode projects have that optimised, and is not required.*

# Answer
> 1 votes
## 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;}

```

# Answer
> 1 votes
# Lua, 66 bytes

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

```

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

# Answer
> 1 votes
# Retina, 41 bytes

```
.
$0$0
..
  __¶ /$0\¶/$0$0\¶|$0$0|¶\____/

```

Try it online!

# Answer
> 1 votes
# Japt, 35 bytes

```
"  __
 /01
/001
|00|
1____/"d0U²1'\

```

Try it online!

### 41-byte solution:

```
[S²'_²RS'/U²'\R'/U²²'\R'|U²²'|R'\'_²²'/]q

```

Try it online!

# Answer
> 1 votes
# \[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

# Answer
> 1 votes
## 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.

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# C (gcc), 84 bytes

```
g(f){char e[]={f,f,f,f};printf("  __\n /%.2s\\\n/%.4s\\\n|%.4s|\n\\____/\n",e,e,e);}

```

Try it online!

# Answer
> 1 votes
# Pyth, 36 bytes

```
jm:s@L"-/|\\_ "jCd6\-+QQ"ԈџÛƲ獩

```

Try it online!

# Answer
> 1 votes
## c(gcc) ~~81~~ 78 bytes

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

```

Try it online

# Answer
> 0 votes
## Batch, 76 bytes

```
@for %%l in ("  __" " /%1%1\" "/%1%1%1%1\" "|%1%1%1%1|" \____/)do @echo %%~l

```

Note: To run this with special characters such as `&`, prefix the character with a `^`.

# Answer
> 0 votes
# JavaScript (ES6), 55 bytes

```
x=>`  __
 /0\\
/00\\
|00|
\\____/`.replace(/0/g,_=>x+x)

```

# Answer
> 0 votes
# Bash, 50 bytes

```
echo "  __
 /$1$1\\
/$1$1$1$1\\
|$1$1$1$1|
\____/"

```

I've also tried to do pattern substitution during parameter expansion, but it seems like the most straightforward way to do this is also the shortest.

Try it online!

# Answer
> 0 votes
# Vim, 31 bytes

Expects the input character to be the only thing in the buffer to start. Ends in insert mode with the egg displayed in the buffer. I have replaced `^M` and `^O` with `<CR>` and `<C-O>` for readability. All whitespace is significant.

```
s  __<CR> /<C-O>2p\<CR>/<C-O>4p\<CR>|<C-O>4p|<CR>\____/

```

Since  is backwards-compatible, you can Try it online!

Explanation:

```
s                                                       " Delete input (storing it to the default register) and enter insert mode
   __<CR>                                               " Type "  --\n"
          /                                             " Type " /"
           <C-O>2p                                      " Paste twice from the default register without leaving insert mode (e.g. put "%%")
                  \<CR>                                 " Type "\\\n"
                       /                                " Type "/"
                        <C-O>4p                         " This time paste 4 times
                               \<CR>                    " Type "\<CR>"
                                    |<C-O>4p|<CR>       " Same drill, but with | before and after
                                                 \____/ " The bottom of the egg

```

# Answer
> 0 votes
# C#, 140 Bytes

```
class x{static void Main(){System.Console.WriteLine(("  __\n"+@" /%%\"+'\n' +@"/%%%%\"+'\n'+@"|%%%%|"+'\n' +@"\____/ ").Replace("%","A"));}}

```

It's my first time codegolfing :) Anyway, this works by replacing '%' from the example to any character you want. This prints out:

```
  __
 /AA\
/AAAA\
|AAAA|
\____/

```

# Answer
> 0 votes
# Excel VBA, 66 Bytes

Anonymous Excel VBE immediates window function that takes a clean input of 1 character from cell `[A1]` on the `ActiveSheet` object and prints to the VBE immediate window.

```
?Replace(Replace("  __0 /11\0/1111\0|1111|0\____/",0,vbCr),1,[A1])

```

# Answer
> 0 votes
# JS (ES6), 60 bytes

```
x=>`  __
 /~\\
/~~\\
|~~|
\\____/`.replace(/~/g,x.repeat(2))

```

Basically the same thing as the python answer.

# Answer
> 0 votes
# Java 7, 79 bytes

```
String f(String c){return"  __\n /x\\\n/xx\\\n|xx|\n\\____/".replace("x",c+c);}

```

**Explanation:**

```
String f(String c){                           // Method with String(-character) parameter and String return-type
  return "  __\n /x\\\n/xx\\\n|xx|\n\\____/"  //  Return this String
    .replace("x",c+c);                        //  And replace every 'x' with two times the input String-character
}                                             // End of method

```

**Test code:**

Try it here.

```
class Main{
  static String f(String c){return"  __\n /x\\\n/xx\\\n|xx|\n\\____/".replace("x",c+c);}

  public static void main(String[] a){
    System.out.println(f("^"));
    System.out.println(f("|"));
    System.out.println(f("o"));
  }
}

```

**Output:**

```
  __
 /^^\
/^^^^\
|^^^^|
\____/
  __
 /||\
/||||\
||||||
\____/
  __
 /oo\
/oooo\
|oooo|
\____/

```

# Answer
> 0 votes
# C, 49 bytes

```
f(){puts("  __\n /~~\\n/~~~~\\n|~~~~|\n\____/");}

```

**Output** Live

```
  __
 /~~\
/~~~~\
|~~~~|
\____/

```

**Unicode, 77 bytes**

```
g(){printf("  .\u2322.\n\n\u239bHAPPY\u239e\n EASTER\n\u239d.___.\u23a0\n");}

```

**Output**

```
  .⌢.

⎛HAPPY⎞
 EASTER
⎝.___.⎠

```

# Answer
> 0 votes
# Aceto, ~~68~~ 64 bytes

8 by 8, so a 3rd order Hilbert curve.

```
/"ppp(pp
np(p"pp)
\\)p|n
"\"\\\
)k,p\\n"
pp/"__\|
   n__
"__\/"p

```

Since we're already non-competing, I used features introduced after the question was posted.

Output:

```
  __
 /==\
/====\
|====|
\____/

```

# Answer
> 0 votes
# Common Lisp, SBCL, 73 bytes

```
(format t"  __
 /~@?\\
/~@?~@?\\
|~@?~@?|
\\____/""~2@{~a~:*~}~@*"(read))

```

# Answer
> 0 votes
## \>\<\>, 58 bytes

```
|v"  __   /":{"\ /"}::::{"\|"}::::i"|\____/"
o>ooooool?!;a

```

Try it online, or at the fish playground!

Takes input from STDIN. If you're allowed to exit with an error, you can get rid of the `l?!;` in the second line.

Explanation: The fish swims through the first line backwards, so it reads `"/____\|"i::::}"|\"{::::}"/ \"{:"/ __ "`. This builds up the string in reverse, keeping a copy of the input at the back of the stack for when it's needed again. The fish then gets to row 2, which prints six characters and a newline and then loops until the stack is empty.

# Answer
> 0 votes
# Ruby, 63 bytes

```
puts"  __  \n /00\\ \n/0000\\\n|0000|\n\\____/".gsub"0",$*[0]

```

As basic as it gets, honestly

# Answer
> 0 votes
# 05AB1E, 25 bytes

```
"ÿ_
\/|"•θ8Ë1Âõ]Æ°•6вèJ.c

```

Try it online.

**Explanation:**

```
"ÿ_
\/|"                   # Push the string "ÿ\n\/|", where `ÿ` is automatically filled
                       # with the (implicit) input-character
    •θ8Ë1Âõ]Æ°•        # Push compressed integer 1269961759550053939510
               6в      # Converted to Base-6 as list:
                       #  [1,1,2,4,0,0,3,2,4,0,0,0,0,3,2,5,0,0,0,0,5,2,3,1,1,1,1,4]
                 èJ    # Index each into the string, and then join together
                   .c  # And centralize it to add the appropriate leading spaces
                       # (after which the result is output implicitly)

```

See this 05AB1E tip of mine (sections *How to compress large integers?* and *How to compress integer lists?*) to understand why `•θ8Ë1Âõ]Æ°•` is `1269961759550053939510` and `•θ8Ë1Âõ]Æ°•6в` is `[1,1,2,4,0,0,3,2,4,0,0,0,0,3,2,5,0,0,0,0,5,2,3,1,1,1,1,4]`.

# Answer
> 0 votes
# Excel Formula, 54 bytes

Makes use of multi-line entry in the formula bar (`Alt`+`Enter`), where `#` is your chosen character to paint!

```
=SUBSTITUTE("  __
 /~~\
/~~~~\
|~~~~|
\____/","~","#")

```

# Answer
> 0 votes
# Whitespace, ~~240~~ 229 bytes

```
[S S S T    S T T   T   T   N
_Push_47][S S S T   S T T   T   T   T   N
_Push_95][S N
S _Duplicate_95][S N
S _Duplicate_95][S N
S _Duplicate_95][S S S T    S T T   T   S S N
_Push_92][S S S T   S T S N
_Push_10][S S S T   T   T   T   T   S S N
_Push_124][S T  S S T   S N
_Copy_0-based_2nd_(92)][S N
S _Duplicate_92][T  N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate_input][S N
S _Duplicate_input][S N
S _Duplicate_input][S S S T T   T   T   T   S S N
_Push_124][S S S T  S T S N
_Push_10][S T   S S T   S S S N
_copy_0-based_8th_(92)][S N
S _Duplicate_92][T  T   T   _Retrieve][S N
S _Duplicate_input][S N
S _Duplicate_input][S N
S _Duplicate_input][S S S T S T T   T   T   N
_Push_47][S S S T   S T S N
_Push_10][S S S T   S T T   T   S S N
_Push_92][S N
S _Duplicate_92][T  T   T   _Retrieve][S N
S _Duplicate_input][S T S S T   S S N
_Copy-0-based-4th-(47)][S S S T S S S S S N
_Push_32][S S S T   S T S N
_Push_10][S S S T   S T T   T   T   T   N
_Push_95][S N
S _Duplicate_95][S T    S S T   T   N
_Copy-0-based-3rd-(32)][S N
S _Duplicate_32][N
S S N
_Create_Label_LOOP][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

```

Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.

**Try it online**.

**Explanation:**

Since we have to incorporate the input character in the output, I couldn't apply this Whitespace tip of mine which I always use for ASCII-art or other print challenges in Whitespace, which would lower each value and inside the printing loop add it again. So instead this is a pretty simple program which does the following:

1. Push all characters reversed to the stack, including the input-characters
    * With bytes saved using Duplicates and Copy's-of
2. Then loop and print the characters from the top of the stack to the bottom (which is why we push the characters in reverse order).

# Answer
> 0 votes
# Haskell, ~~70~~ 63 bytes

7 bytes down with great help from Laikoni

```
(<$>"  __\n /~~\\\n/~~~~\\\n|~~~~|\n\\____/").(?)
d?'~'=d
d?c=c

```

Try it online!

The function `f` takes a character to paint the egg with.

# Answer
> 0 votes
# Scala, 56 bytes

```
print("""  __
 /~\
/~~\
|~~|
\____/""".replace("~",i+i))

```

Try it online!

# Answer
> 0 votes
# T-SQL, ~~63~~ 61 bytes

```
SELECT REPLACE('  __
 /11\
/1111\
|1111|
\____/',1,v)FROM t

```

Old challenge, but didn't see a SQL solution.

Input is taken via pre-existing table **t** with text field **v**, per our IO standards.

SQL allows line break literals in strings, so a pretty straight-forward replace. Lines 2 and 3 have an extra space after the final `\`, so the line break isn't escaped.

**EDIT**: Discovered that I can save 2 bytes by using a numeral as the replacement character instead of something like `'.'` that needs quotes. Turns out `REPLACE` does the implicit conversion to string.

# Answer
> 0 votes
# nroff, 83 bytes

I found a way to outgolf to get a verbatim output so I could draw ascii art with fewer bytes: it was to use `.nf`.

```
.de F
  __
.nf
 /\\$1\\$1\\\\
/\\$1\\$1\\$1\\$1\\\\
|\\$1\\$1\\$1\\$1|
\\\\____/
..

```

Attempt This Online!

---

# nroff, 103 bytes

```
.de F
  __
.sp 0
 /\\$1\\$1\\\\
.sp 0
/\\$1\\$1\\$1\\$1\\\\
.sp 0
|\\$1\\$1\\$1\\$1|
.sp 0
\\\\____/
..

```

Attempt This Online!

I tried using more macros to shorten but failed. I had to do such annoying escaping a lot.

## Usage

```
.F #

.F %

```

---
Tags: code-golf, ascii-art
---