title: FizzBuzz: Least unique bytes

text:
# Question
Title: FizzBuzz: Least unique bytes
**Introduction:**

Although it seems challenges scored by least unique characters have been attempted, there are few which were well-received. I think it's a potentially interesting scoring criterion, as long as different languages aren't competing with each other (as with code golf).

**Challenge:**

Create a basic FizzBuzz program or function. The output should be the decimal numbers 1 to 100, inclusive. For multiples of three, print `Fizz` instead of the number, and for the multiples of five print `Buzz`. For numbers which are multiples of both three and five, print `FizzBuzz`.

A trailing newline is allowed, and `\n` or `\r\n` can be used to separate the numbers (and `Fizz`es and `Buzz`es and `FizzBuzz`es).

**Scoring:**

The answer (per language) with the least unique bytes wins. For example,

```
abbcccdeee

```

would have a score of 5, as it contains are 5 distinct bytes.

# Answer
# Unary, score 1 (\\$3.065... × 10^{185}\\$ bytes)

I couldn't resist ;)

The program consists of 306542480187333548229216501998737670100823810347304444087725506753387994506955599380251625023427643514071322084229755566193943772995081070792874713832316221905650936799216302699728340431 times a single character of your own choosing, which translates to the following brainfuck program:

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

```

Port of *@MitchSchwartz*' brainfuck answer for the *1,2,Fizz,4,Buzz* challenge, so make sure to upvote him!

Try it online as brainfuck.

The byte-count is generated with this 05AB1E program I wrote.
> 5 votes

# Answer
# C (gcc), 14 unique bytes (4552 bytes)

The characters I used are: `main(){}prtf+&`.

```
a(i){if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}}n(i){if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}}f(i){if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)&printf(&i)){}}t(i){if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}if(++i&++i&++i&++i&++i&printf(&i)&printf(&i)){}}r(){}p(i){if(r()&&printf(&i)){}if(++i){}}main(i){if(a(p(i))&n()){}if(a(p(p(i)))&n()){}if(f()&n()){}if(a(p(p(p(p(i)))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(i))))))))&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(i))&a(p(i))&n()){}if(f()&n()){}if(a(p(i))&a(p(p(p(i))))&n()){}if(a(p(i))&a(p(p(p(p(i)))))&n()){}if(f()&t()&n()){}if(a(p(i))&a(p(p(p(p(p(p(i)))))))&n()){}if(a(p(i))&a(p(p(p(p(p(p(p(i))))))))&n()){}if(f()&n()){}if(a(p(i))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(i)))&a(p(p(i)))&n()){}if(a(p(p(i)))&a(p(p(p(i))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(p(i)))&a(p(p(p(p(p(p(i)))))))&n()){}if(f()&n()){}if(a(p(p(i)))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(a(p(p(i)))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}if(f()&t()&n()){}if(a(p(p(p(i))))&a(p(i))&n()){}if(a(p(p(p(i))))&a(p(p(i)))&n()){}if(f()&n()){}if(a(p(p(p(i))))&a(p(p(p(p(i)))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(i))))&a(p(p(p(p(p(p(p(i))))))))&n()){}if(a(p(p(p(i))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(p(p(p(i)))))&a(p(i))&n()){}if(f()&n()){}if(a(p(p(p(p(i)))))&a(p(p(p((i)))))&n()){}if(a(p(p(p(p(i)))))&a(p(p(p(p((i))))))&n()){}if(f()&t()&n()){}if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p((i))))))))&n()){}if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p(p((i)))))))))&n()){}if(f()&n()){}if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p(p(p(p((i)))))))))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(p(p(i))))))&a(p(p(i)))&n()){}if(a(p(p(p(p(p(i))))))&a(p(p(p(i))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(i)))))))&n()){}if(f()&n()){}if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}if(f()&t()&n()){}if(a(p(p(p(p(p(p(i)))))))&a(p(i))&n()){}if(a(p(p(p(p(p(p(i)))))))&a(p(p(i)))&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(i)))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(i))&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(i))))&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(i)))))&n()){}if(f()&t()&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(i)))))))&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(i)))&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(i))))&n()){}if(f()&n()){}if(t()&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(i)))))))&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}if(f()&t()&n()){}if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(i))&n()){}if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(i)))&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(i)))))&n()){}if(t()&n()){}if(f()&n()){}if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}if(f()&n()){}if(t()&n()){}}

```

Try it online!

There is a lot of code here (so much that I actually had to add the `-w` flag to prevent exceeded debug output), so I will split the explanation into parts. Simply put, we are printing every character using brute force, since I originally thought that it would cost less bytes, but looking back it might actually have been a lot easier to use a logical method.

## Explanation

The first function `a(i)` takes in a digit `i`, and outputs that digit. We increment `i` 48 times, since the ASCII values for numbers are offset by `+48`, and then use the fact that `printf(&i)` acts the same as `putchar(i)` to print to STDOUT.

```
a(i)
{
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
}

```

---

The second function `n(i)` prints a newline character `\n`. Later when we call this function, we won't actually input any parameter (it will be called by `n()`), which causes `i` to default to 0. Using this fact we essentially do the same thing as in the first function, except we increment by 10, since that is the ASCII value for `\n`.

```
n(i)
{
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
}

```

---

The third function `f(i)` prints `Fizz`. There is not much to say, except we use the same strategy as in the first function, only we need to repeat this 4 times. It also helps that each ASCII value in `Fizz` is greater than the last, allowing us to simply increment `i` throughout the whole function, instead of using an extra character like `-` to decrement.

```
f(i)
{
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)&printf(&i)){}
}

```

---

The fourth function `t(i)` essentially does the same thing as `f(i)`, only it prints `Buzz` instead of `Fizz`.

```
t(i)
{
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
if(++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&++i&printf(&i)){}
if(++i&++i&++i&++i&++i&printf(&i)&printf(&i)){}
}

```

---

The fifth function `p(i)` along with a helper function `r()` returns `i+1`. I know that my function seems overly complicated for such a task, so let me explain. For some reason on TIO, simply using a function like `p(i){if(++i){}}` exploiting the return hack does not work. I suspect this is because the compiler optimizes the code by actually deleting it. Therefore the extra code you see is an attempt to trick the compiler into not deleting it.

```
r(){}
p(i)
{
if(r()&&printf(&i)){}
if(++i){}
}

```

---

The final function `main()` will take all of the functions mentioned previously and combine them to print the FizzBuzz pattern for all 100 lines. Most of it is self-explanatory, except for how to print a number. A number is simply a concatenation of a bunch of digits, so we can use our function `a(i)` to print it. So if we want to print 12, we can do something like `if(a(1)&a(2)){}`. The problem is we don't want to use extra characters like `1` or `2`, which we can solve by repeatdly using the `p(i)` function. Since `p(i)` equals `i+1`, we know that `p(p(...i...))`, would equal `i` plus a constant, which depends on how many `p()`s we are nesting. So if we want to print `12`, we can do `if(a(p(i))&a(p(p(i)))){}`. The `i` variable here is declared as a main parameter, which defaults to 0.

```
main(i)
{
if(a(p(i))&n()){}
if(a(p(p(i)))&n()){}
if(f()&n()){}
if(a(p(p(p(p(i)))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(i))&a(p(i))&n()){}
if(f()&n()){}
if(a(p(i))&a(p(p(p(i))))&n()){}
if(a(p(i))&a(p(p(p(p(i)))))&n()){}
if(f()&t()&n()){}
if(a(p(i))&a(p(p(p(p(p(p(i)))))))&n()){}
if(a(p(i))&a(p(p(p(p(p(p(p(i))))))))&n()){}
if(f()&n()){}
if(a(p(i))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(i)))&a(p(p(i)))&n()){}
if(a(p(p(i)))&a(p(p(p(i))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(p(i)))&a(p(p(p(p(p(p(i)))))))&n()){}
if(f()&n()){}
if(a(p(p(i)))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(a(p(p(i)))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}
if(f()&t()&n()){}
if(a(p(p(p(i))))&a(p(i))&n()){}
if(a(p(p(p(i))))&a(p(p(i)))&n()){}
if(f()&n()){}
if(a(p(p(p(i))))&a(p(p(p(p(i)))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(i))))&a(p(p(p(p(p(p(p(i))))))))&n()){}
if(a(p(p(p(i))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(p(p(p(i)))))&a(p(i))&n()){}
if(f()&n()){}
if(a(p(p(p(p(i)))))&a(p(p(p((i)))))&n()){}
if(a(p(p(p(p(i)))))&a(p(p(p(p((i))))))&n()){}
if(f()&t()&n()){}
if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p((i))))))))&n()){}
if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p(p((i)))))))))&n()){}
if(f()&n()){}
if(a(p(p(p(p(i)))))&a(p(p(p(p(p(p(p(p(p((i)))))))))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(i))))))&a(p(p(i)))&n()){}
if(a(p(p(p(p(p(i))))))&a(p(p(p(i))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(i)))))))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(a(p(p(p(p(p(i))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}
if(f()&t()&n()){}
if(a(p(p(p(p(p(p(i)))))))&a(p(i))&n()){}
if(a(p(p(p(p(p(p(i)))))))&a(p(p(i)))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(i)))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}
if(a(p(p(p(p(p(p(i)))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(i))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(i))))&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(i)))))&n()){}
if(f()&t()&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(i)))))))&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(i))))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(i)))&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(i))))&n()){}
if(f()&n()){}
if(t()&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(i)))))))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(a(p(p(p(p(p(p(p(p(i)))))))))&a(p(p(p(p(p(p(p(p(p(i))))))))))&n()){}
if(f()&t()&n()){}
if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(i))&n()){}
if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(i)))&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(i)))))&n()){}
if(t()&n()){}
if(f()&n()){}
if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(p(p(p(i))))))))&n()){}
if(a(p(p(p(p(p(p(p(p(p(i))))))))))&a(p(p(p(p(p(p(p(p(i)))))))))&n()){}
if(f()&n()){}
if(t()&n()){}
}

```
> 3 votes

# Answer
# GS2, 1 unique byte

Another 1-byte solution. Unlike the other ones though, this one can actually be written down :P.

```
f

```

Try it online!
> 3 votes

# Answer
# Wolfram Language (Mathematica), 22 unique bytes

```
Do[Echo[If[Mod[d,1+1+1+1+1+1+1+1+1+1+1+1+1+1+1]<1,FizzBuzz,If[Mod[d,1+1+1]<1,Fizz,If[Mod[d,1+1+1+1+1]<1,Buzz,d]]]],{d,1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1}]

```

Try it online!
> 2 votes

# Answer
# Python 2, 7 unique bytes

This uses this answer to the "least amount of unique bytes for Turing completeness". I then encoded this well-golfed Python 2 FizzBuzz answer and I got the program that follows.

```
c="%c%%c%%%%c%%%%%%%%c"
ex=c==c
ee=c==""
exec"e=%x%%x"%ex%ex
exec"e%%%%%%%%=%x%%x%%%%x"%ee%ex%ee
exec"ee=%x%%x"%e%ee
exec"ee%%%%=%x%%x"%ex%e
exec"e=%x%%x"%ee%e
exec"ec=ex%cex"%e
exec"xe=ec%cec"%e
exec"xx=xe%cxe"%e
exec"xc=xx%cxx"%e
exec"ce=xc%cxc"%e
exec"cc=ce%cce"%e
exec"xee=ce%cec"%e
exec"cee=ce%cex%%cxe"%e%e
exec"exe=ce%cex%%cec%%%%cxe"%e%e%e
exec"xxe=ce%cxx"%e
exec"cxe=ce%cex%%cxx"%e%e
exec"ece=ce%cec%%cxx"%e%e
exec"cce=ce%cex%%cxe%%%%cxx"%e%e%e
exec"eex=ce%cec%%cxe%%%%cxx"%e%e%e
exec"xex=ce%cex%%cec%%%%cxe%%%%%%%%cxx"%e%e%e%e
exec"cex=ce%cxc"%e
exec"exx=ce%cex%%cxc"%e%e
exec"xxx=ce%cec%%cxc"%e%e
exec"cxx=ce%cex%%cec%%%%cxc"%e%e%e
exec"ecx=ce%cxe%%cxc"%e%e
exec"xcx=ce%cex%%cxe%%%%cxc"%e%e%e
exec"ccx=ce%cex%%cec%%%%cxx%%%%%%%%cxc"%e%e%e%e
exec"eec=ce%cex%%cxe%%%%cxx%%%%%%%%cxc"%e%e%e%e
exec"xec=cc%cec"%e
exec"cec=cc%cec%%cxe"%e%e
exec"exc=cc%cex%%cce"%e%e
exec"xxc=cc%cex%%cec%%%%cce"%e%e%e
exec"cxc=cc%cex%%cxe%%%%cce"%e%e%e
exec"ecc=cc%cec%%cxe%%%%cce"%e%e%e
exec"xcc=cc%cxx%%cce"%e%e
exec"ccc=cc%cex%%cxx%%%%cce"%e%e%e
exec"eeee=cc%cec%%cxx%%%%cce"%e%e%e
exec"xeee=cc%cxe%%cxx%%%%cce"%e%e%e
exec"ceee=cc%cec%%cxe%%%%cxx%%%%%%%%cce"%e%e%e%e
exec"exee=cc%cex%%cec%%%%cxe%%%%%%%%cxx%%%%%%%%%%%%%%%%cce"%e%e%e%e%e
exec"xxee=cc%cxc%%cce"%e%e
exec"cxee=cc%cec%%cxc%%%%cce"%e%e%e
exec"ecee=cc%cex%%cec%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"xcee=cc%cxe%%cxc%%%%cce"%e%e%e
exec"ccee=cc%cex%%cxe%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"eexe=cc%cec%%cxe%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"xexe=cc%cxx%%cxc%%%%cce"%e%e%e
exec"cexe=cc%cec%%cxx%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"exxe=cc%cec%%cxe%%%%cxx%%%%%%%%cxc%%%%%%%%%%%%%%%%cce"%e%e%e%e%e
exec"""x=""
"""
exec"x%c=c%%cxc%%xexe%%cxc%%xxc"%e
exec"x%c=c%%xee%%xee%%eex%%eeee"%e
exec"x%c=c%%exee%%ccc%%ceee%%xxe"%e
exec"x%c=c%%xxc%%xcc%%cxee%%xxe"%e
exec"x%c=c%%cxc%%eexe%%exc%%xeee"%e
exec"x%c=c%%xxe%%xxc%%cxe%%cxe"%e
exec"x%c=c%%ecc%%exee%%cxee%%ce"%e
exec"x%c=c%%xxc%%ce%%ccc%%ceee"%e
exec"x%c=c%%ce%%xxc%%xexe%%eex"%e
exec"x%c=c%%ecee%%xxee%%xeee%%ccc"%e
exec"x%c=c%%xcee%%xxe%%cxe%%cxe"%e
cx="""ccc
eec
cex
ccx
cxc
xexe
cxc
xxc
xee
xxee
cxee
ccc
ceee
xcee
ce
ccc
cee
cxx
xex
xxx
ece
exe
cec
ccc
cexe
cexe
exe
e
ccc
cee
xcx
xex
ecx
ece
exe
xec
ccee
cexe
cexe
exe
exee
cxee
cce
exxe
ccc
ccx
ccc
e
eec
exx
ccx
xee
ece
exx
cex
cex"""
exec"exec%cx"%ce

```

Try it online!
> 1 votes

# Answer
# Lenguage, 1 distinct character

Now you see, the problem is that my program is *so large* that I kinda can't find a way to represent the byte count other than binary. So, uh, here is what I calculated my score as, represented in base 2:

```
[encoded data, 27810 characters]

```

BF used for conversion, but place a `[]` at the start of the program -- my browser is already lagging enough without me trying to open the large link again.

In other words, take any random character of your choosing and repeat it `n` times, where `n` is the binary number above converted to base 10. I may have accidentally miscalculated the byte count, but I know it's only 1 distinct character.
> 1 votes

---
Tags: code-challenge, kolmogorov-complexity
---


# Question
Title: Draw an ASCII oak tree (or a woman with curly hair?)
# Task

Your task is to draw these beautiful oak trees:

```
1 ->
 @@@
@@@@@
@|.|@
_|_|_

2 ->
   @@
 @@@@@@
@@@@@@@@
@@| .|@@
  |  |
__|__|__

3 ->
   @@@@@
 @@@@@@@@@
@@@@@@@@@@@
@@@|   |@@@
  @|  .|@
   |   |
___|___|___

4 ->
      @@
   @@@@@@@@
 @@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@|    |@@@@
  @@|   .|@@
    |    |
    |    |
____|____|____

5 ->
      @@@@@
   @@@@@@@@@@@
 @@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
@@@@@|     |@@@@@
  @@@|    .|@@@
     |     |
     |     |
     |     |
_____|_____|_____

6 ->
      @@@@@@@@
   @@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@
@@@@@@|      |@@@@@@
  @@@@|      |@@@@
     @|     .|@
      |      |
      |      |
      |      |
______|______|______

```

(that one sandbox commenter felt were similar to women with curly hair!)

The trees are allowed to be surrounded by any extra whitespace your solution creates *as long as that doesn't break the tree*, of course.

# Algorithm

As per the examples above, we take `n` to represent the width of the trunk and the specs of the tree will be given in terms of that.

Given `n`:

1. the height of the trunk is `n + 1`;
2. the width of the trunk in space characters is `n`;
3. the top row of the trunk is `n` times the character `@`, followed by `|`, `n` times the space character , another vertical pipe `|` and then `n` times `@`.
4. from the reference row up to the top of the crown, we only use `@` as follows:
    * there is one row with the same width as the reference row and each subsequent row above is shortened by one `@` than the previous shortening;
5. from the reference row downwards, we chop 2 `@` from each side and then each row we go down, we chop one more `@` than the previous row;
6. the last trunk row that is surrounded by a `@` has a `.` immediately to the left of the right vertical pipe `|`;
7. the bottom most row has the underscore `_` in all the tree width, except where the trunk vertical pipes `|` are.

# Answer
> 18 votes
# JavaScript (ES8),  ~~215 ... 199~~  197 bytes

```
f=(n,k=(W=3*n+2)**.5-.5|0,x=.5-k-(W-n)**.5,R=(n,k)=>S=''.padEnd(n,'.@_'[k]))=>k+n+2?(w=k*-~k/2,k<0?(x>0?s=R(n,k+n+3):R(w+=~k,s=R(n-1)+R(1,~~x))+R(n-w,1))+`|${s}|`+S:R(w)+R(W-w*2,1))+`
`+f(n,k-1):''

```

Try it online!

or Test it online! against an ungolfed, straightforward implementation

### How?

We define \\$H\\$ as the height of the upper part of the crown (where the width is increasing) and \\$h\\$ as the height of the lower part (where the width is decreasing).

*Example for \\$n=6\\$:*

We have:

$$H\_n=\left\lfloor\sqrt{3n+2}+\frac{1}{2}\right\rfloor$$

and:

$$h\_n=\left\lfloor\sqrt{2n+2}-\frac{1}{2}\right\rfloor$$

By computing these values beforehand, we can draw the tree from top to bottom with a single loop, which is implemented here as a recursive function.

The total height of the tree is \\$H\_n+n+1\\$. We use a counter \\$k\\$ going from \\$H\_n-1\\$ to \\$-n-1\\$.

```
 3 | ......@@@@@@@@       | upper crown
 2 | ...@@@@@@@@@@@@@@    |
 1 | .@@@@@@@@@@@@@@@@@@  |
 0 | @@@@@@@@@@@@@@@@@@@@ |
---+----------------------+-------------
-1 | @@@@@@|      |@@@@@@ | lower crown
-2 | ..@@@@|      |@@@@   |
-3 | .....@|     .|@      |
---+----------------------+-------------
-4 |       |      |       | trunk only
-5 |       |      |       |
-6 |       |      |       |
---+----------------------+-------------
-7 | ______|______|______ | roots

```

The number of leading spaces for the upper part of the crown is the \\$k\\$-th triangular number:

$$T\_k=\frac{k\times(k+1)}{2}$$

The number of leading spaces for the lower part of the crown is given by:

$$\frac{(k+1)\times(k-2)}{2}=T\_k-k-1$$

### Commented

```
f = (                         // f is a recursive function taking:
  n,                          //   n = input
  k = (W = 3 * n + 2)         //   W = 3n + 2 = total width of the tree
      ** .5 - .5 | 0,         //   k = counter, initialized to floor(sqrt(W) - 1/2)
  x = .5 - k - (W - n) ** .5, //   x = 1/2 - k - sqrt(W - n)
  R = (n, k) =>               //   R is a helper function returning and saving in S:
    S =                       //     a character identified with k ('.', '@', '_' or
      ''.padEnd(n, '.@_'[k])  //     a space) repeated n times
) =>                          //
  k + n + 2 ?                 // if k is not equal to -n - 2:
    ( w = k * -~k / 2,        //   initialize w to the k-th triangular number
      k < 0 ?                 //   if k is negative:
        ( x > 0 ?             //     if x is positive (trunk only or roots):
            s =               //       set s to:
              R(n, k + n + 3) //         '_' * n if k = -n - 1, or space * n otherwise
          :                   //     else (lower crown):
            R(                //       append ...
              w += ~k,        //         ... w - k - 1 spaces
              s = R(n - 1) +  //         and set s to n - 1 spaces followed by
                  R(1, ~~x)   //         '.' if floor(x) = 0, or another space otherwise
            ) +               //
            R(n - w, 1)       //       append '@' * (n - w)
        ) +                   //
        `|${s}|` +            //     append s surrounded by '|' characters
        S                     //     append S
      :                       //   else (upper crown):
        R(w) +                //     append w spaces
        R(W - w * 2, 1)       //     append '@' * (W - 2w)
    ) +                       //
    `\n` +                    //   append a line-feed
    f(n, k - 1)               //   append the result of a recursive call with k - 1
  :                           // else:
    ''                        //   stop recursion

```

# Answer
> 11 votes
# Python 3, ~~249~~ \\$\cdots\\$ ~~211~~ 210 bytes

Saved ~~6~~ \\$\cdots\\$ ~~17~~ 18 bytes thanks to Kevin Cruijssen!!!

```
def f(n):
 i=j=1
 t,y,e,w,s,x,S=[],n*'_','|',0,3*n+2,n*' ',n
 while s>1:t=[w*' '+s*'@']+t;s-=2*i;w+=i;i+=1
 while S>0:j+=1;t+=[x[S:]+S*'@'+e+x[1:]+'. '[S>j]+e+S*'@'];S-=j
 return t+[(x+e)*2]*(n-j+1)+[(y+e)*2+y]

```

Try it online!

**Before golfing**

```
def f(n):
    w=s=3*n+2
    t=[]
    i=1
    while s>1:
        t=[' '*((w-s)//2)+'@'*s]+t
        s-=2*i
        i+=1
    b=s=n
    i=2
    while s>0:
        t+=[(n-s)*' '+s*'@'+'|'+~-n*' '+'. '[s-i>0]+'|'+s*'@']
        s-=i
        b-=1
        i+=1
    while b:
        t+=[n*' '+'|'+n*' '+'|']
        b-=1
    t+=[n*'_'+'|'+n*'_'+'|'+n*'_']
    return t

```

# Answer
> 9 votes
# Charcoal, ~~78~~ 71 bytes

```
Ｎθ≔×¹·⁵⊕θηＷ›ηⅈ«↑Ｐ×⁻ηⅈ@Ｍⅉ←»Ｊ⁰θ×θ_Ｐ×⊘⁺³θ_↑⊕θ⸿Ｗ›θⅈ«Ｐ×⁻θⅈ@Ｍ⁺²ⅉ¹»Ｊθⅉ↗‖ＯＯ﹪θ².

```

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

```
Ｎθ

```

Input `n`.

```
≔×¹·⁵⊕θη

```

Calculate the half width of the reference row.

```
Ｗ›ηⅈ«

```

While there is still canopy left to print, ...

... move up a line, ...

```
Ｐ×⁻ηⅈ@

```

... print some canopy, ...

```
Ｍⅉ←»

```

... and move to the start of the next row of canopy.

```
Ｊ⁰θ

```

Jump to the left side of the base.

```
×θ_

```

Print the left side of the base.

```
Ｐ×⊘⁺³θ_

```

Print half of the middle of the base, allowing space for the trunk.

```
↑⊕θ

```

Print the trunk.

```
⸿

```

Move to the beginning of the reference row.

```
Ｗ›θⅈ«

```

While there is still foliage to print, ...

```
Ｐ×⁻θⅈ@

```

... print some foliage, ...

```
Ｍ⁺²ⅉ¹»

```

... and adjust the width of the foliage according to the number of lines of foliage already printed.

```
Ｊθⅉ↗

```

Move to the mirror location of the `.`.

```
‖ＯＯ﹪θ²

```

Reflect the half tree drawn so far to almost complete the tree and also move the cursor to the location of the `.`.

```
.

```

Complete the tree.

# Answer
> 8 votes
# Java 11, ~~282~~ 273 bytes

```
n->{String r="",y="_".repeat(n),e="|",N="\n",S=" ",q=S.repeat(n-1),z;int i=1,w=0,s=3*n+2;for(;s>1;s-=2*i,w+=i++)r=S.repeat(w)+"@".repeat(s)+N+r;for(i=1,s=n;s>0;s-=i)r+=S.repeat(n-s)+(z="@".repeat(s))+e+q+(s>++i?S:".")+e+z+N;return r+((q+=S+e)+q+N).repeat(n-i+1)+y+e+y+e+y;}

```

Port of *@Noodle9*'s Python answer, after I helped him golf it a bit.
-9 bytes thanks to *@Arnauld*.

Try it online.

**Explanation:**

```
n->{                     // Method with integer parameter and String return-type
  String r="",           //  Result-String, starting empty
    y="_".repeat(n),     //  Temp-String `y`, consisting of the input amount of "_"
    e="|",               //  Temp-String `e`, containing "|"
    N="\n",              //  Temp-String `N`, containing a newline
    S=" ",               //  Temp-String `S`, contain a space
    q=S.repeat(n-1),     //  Temp-String `q`, consisting of the input-1 amount of spaces
    z;                   //  Temp-String `z`, uninitialized
  int i=1,               //  Integer `i`, starting at 1
    w=0,                 //  Integer `w`, starting at 0
    s=3*n+2;             //  Integer `s`, starting at 3 times the input + 2
  for(;s>1               //  Continue looping as long as `s` is larger than 1:
      ;                  //    After every iteration:
       s-=2*i,           //     Decrease `s` by `i` twice
       w+=i              //     Increase `w` by `i`
           ++)           //     And increase `i` by 1
     r=S.repeat(w)       //   Prepend `w` amount of spaces;
       +"@".repeat(s)    //   `s` amount of "@";
       +N                //   and a newline
         +r;             //   to the result-String
  for(i=1,               //  Reset `i` to 1
      s=n;               //  Reset `s` to the input
      s>0;               //  Continue looping as long as `s` is larger than 0:
      s-=i)              //    After every iteration: decrease `s` by `i`
    r+=                  //   Append the result-String with:
       S.repeat(n-s)     //    The input minus `s` amount of spaces;
       +(z="@".repeat(s))//    `s` amount of "@";
       +e                //    a "|";
       +q                //    the input-1 amount of spaces;
       +(s>++i?          //    If `s` is larger than `i+1`
                         //    (by first increasing `i` by 1 with `++i`)
          S              //     a space;
         :               //    Else:
          ".")           //     a ".";
       +e                //    a "|";
       +z                //    the input minus `s` amount of spaces again;
       +N;               //    and a newline character
  return r               //  After both loops: return the result-String,
          +              //  appended with:
           ((q+=S+e)     //   `q` with an additional space and "|" appended
                    +q   //   twice
                      +N)//   and a newline
           .repeat(n-i+1)//   Repeated `n-i+1` amount of times
          +y+e+y+e       //   As well as two times `y` and "|"
                  +y;}   //   And an additional third `y`

```

# Answer
> 7 votes
# 05AB1E, ~~106~~ ~~105~~ ~~103~~ ~~99~~ ~~97~~ ~~95~~ ~~93~~ 92 bytes

```
$×0I>;úR©«D1s∍ILηOD¦<‚vyvDðyL<ǝ}r}r)ʒ1å}`'.I>ǝ)DJ0¢Iα®иIú0'_I×ì¬®¦∍«)˜IÉi.ºëº}»T„@|‡I≠i'.ð.;

```

Try it online or verify the first 10 test cases.

**Explanation:**

```
$                # Push 1 and the input-integer
 ×               # Pop both, and push a string consisting of the input amount of "1"s
  0              # Push a 0
   I>;           # Push the (input+1)/2
      ú          # Prepend that many spaces to the "0" (truncates decimals)
       R         # Reverse it so the spaces are trailing
        ©        # Store it in variable `®` (without popping)
         «       # Append it to the string of 1s
D                # Duplicate it
 1               # Push a 1
  s              # Swap the two values on the stack
   ∍             # Extend the "1" to a size equal to the string-length
    IL           # Push a list in the range [1, input]
      η          # Get the prefixes of this list
       O         # And sum each inner prefix
        D        # Duplicate this list of integer
         |       # Remove the leading 1
          <      # Decrease each value by 1
           ‚     # And pair the two lists together
v                # Loop over this pair of list of integers:
 yv              #  Inner loop `y` over each of those lists of integers:
   D             #   Duplicate the string at the top of the stack
     yL          #   Push a list in the range [1, `y`]
       <         #   Decrease it by 1 to make it [0, `y`)
    ð   ǝ        #   And replace the characters at those indices with a space
  }r             #  After the inner loop: reverse all values on the stack
}r               # After the outer loop: reverse all values on the stack
  )              # And wrap all values on the stack into a list
   ʒ             # Filter this list by:
    1å           #  Only keep lines which contain a "1"
   }`            # After the filter: Push all values separated to the stack again
     '.I>ǝ      '# Replace the space at index input+1 with a "."
          )      # And re-wrap all values on the stack into a list again
D                # Duplicate this list of lines
 J               # Join them all together
  0¢             # Count the amount of "0"s in this string
    Iα           # Get the absolute difference with the input
      ®и         # Repeat `®` (the "|" with trailing spaces) that many times as list
        Iú       # Prepend the input amount of spaces to each string
0                # Push a 0
 '_I×ì          '# Prepend the input amount of "_"
      ¬          # Push its first character (without popping), which is a "_"
       ®¦∍       # Repeat it the length of `®` - 1 amount of times
          «      # Append it to the "0" with leading "_"
)                # Wrap all values on the stack into a list again
 ˜               # Flatten it
  IÉi            # If the input is odd:
     .º          #  Mirror each line with the last character overlapping
    ë            # Else:
     º           #  Mirror each line without overlap
}»               # After the if-else: join all lines by newlines
  T              # Push 10
   „@|           # Push string "@|"
      ‡          # Transliterate all "1" to "@" and all "0" to "|"
  I≠i            # If the input is NOT 1:
     '.ð.;      '#  Replace the first "." with a space
                 # (after which the result is output implicitly)

```

`r)ʒ1å}`'.I>ǝ)D` could alternatively be `)ʒþà}ć'.N>ǝšÂs` for the same byte-count.

# Answer
> 2 votes
# 05AB1E, ~~86~~ ~~81~~ ~~77~~ 67 bytes

```
Î×2.ø$×.ø©DSdJD.ΓN>·.$}`r[D¬≠#NÌF¦¨]\\0'..;R®1K¹;.D®TS'_:).c2Ý… @|‡

```

Try it online!

~~-5~~ ~~-9~~ -19 @ Kevin Cruijssen, thanks!

---

This is some unorthodox stuff, definitely not my best answer... It's been awhile, I'm rusty. Also tried to use some of the new commands like `Δ` which did not go as planned, and I had to use a global register. Still trying to golf that whole part out.

---

For the purpose of the explanation `I` will mean input for the duration.

```
[       Code      ] #     [        Explanation        ]
====================#========================================
$                   # Push 1 and I.
 3*Ì                # (3 * I) + 2
    ×               # "1" repeat (3 * I) + 2 times.
     Ð              # Triplicate.

====================# Setting up the first line of the bottom crown.
¹x                  # Push I and 2I.
  ‚                 # [I, 2I]
   >                # [I + 1, 2I + 1]
    o               # [2 ^ (I + 1), 2 ^ (2I + 1)]
     ¥              # 2 ^ (I + 1) - 2 ^ (2I + 1)
      b             # Convert to binary (I=2: 11000)
       -            # Subtract from previous value (I=2: 11111111-11000=11100111)
        н           # Remove from array (get first element)

====================# Setting up the first line of the bottom crown.
¹                   # Push I.
 x>‚                # [I, 2I + 1)
    o               # [2 ^ I, 2 ^ (2I + 1)]
     b              # Convert to binary (I=2: [100,100000])
      O             # Sum (I=2: 100100)
       +            # Add to previous (I=2: 11200211)
        ©ˆ          # Store in register, push to global array.

====================# Setting up the first line of the top crown.
ˆ                   # Push the line of 1's that starts the top crown.

====================# Creating the top crown.
Δ                   # Until this code stops changing the value...
 N>·                # (Iteration + 1) * 2
    .$              # Remove (Iteration + 1) * 2 characters
      Dˆ            # Dupe and push to global array.
        }¯R`        # Push global array reversed, flatten.

====================# Creating the bottom crown.
[                   # Infinite loop...
 D¬≠#               # Duplicate last value, break if it doesn't start with 1.
     NÌ             # (2 * Iteration) + 1
       F¦¨          # Loop (2 * Iteration) + 1 time and remove head/tail.
          ]\\       # End loop, remove 2 values.

====================# Adding the knot of the tree.
0'..;               # Find and replace first 0 with a period.
     R              # Reverse it from the left side to the right.

====================# Creating the trunk.
®                   # Push the register.
 1K                 # Remove the extra leaves (1's).
   ¹;.D             # Push I/2 copies of this.

====================# Creating the ground.
®                   # Push register for bottom
 TS'_:              # Replace all leaves (1's) and spaces (0's) with '_' (3's)

====================# Pulling it all together.
)                   # Wrap stack to array.
 .c                 # Center.
   2Ý               # Push [0,1,2].
     … @|           # Push " @|".
         ‡          # Replace 0 with ' ', 1 with '@' and 2 with '|'.

====================# Done!

```

*working on updating the explanation, I am on my cell phone at the moment.*

# Answer
> 1 votes
# Perl 5, 215 bytes

```
$n=pop;$y=$n*3+2;while($y>0){$_=$"x$x.'@'x$y.$/.$_;$x+=++$z;$y-=2*$z}print;$i=$x=$n++;$k=2;while($n--){$_=$"x$j.'@'x$i.'|'.$"x$x.'|'.'@'x$i.$"x$j;$k>=$i?($i&&s/ \|@/.|@/,$i=0,$j=$x):($i-=$k,$j+=$k++);$n||y/ /_/;say}

```

Try it online!

Takes size of tree as single command-line argument.

I'm sure it can probably be improved.

Ungolfed:

```
$n = pop;                                   # get tree size from command line

## Crown section ##

$x = 0;                                     # initial number of leading spaces to print
$y = $n * 3 + 2;                            # initial number of @s to print
$z = 0;                                     # used for increment/decrement value

while($y > 0)                               # build from bottom up as long as we have @s to add
{
        $_ = ' 'x$x . '@'x$y . "\n" . $_;   # new row of crown, prepended to existing crown
        $z++;                               # increase increment/decrement counter
        $x += $z;                           # increase leading spaces for next row
        $y -= 2*$z;                         # decrease number of @s for next row
}

print;                                      # print the crown (don't use say to avoid extra LF)

## Trunk section ##

$x = $n++;                                  # width of trunk
$i = $x;                                    # number of @s before/after trunk
$j = 0;                                     # number of leading/trailing spaces
$k = 2;                                     # number of leading/trailing @s to remove in next row

while($n--)                                 # build each row of the trunk
{
        $_ = ' 'x$j . '@'x$i . '|' . ' 'x$x
           . '|' . '@'x$i . ' 'x$j;         # new row of trunk

        if($k >= $i) {                      # if next row won't have any @s
                s/ \|@/.|@/ if($i);         # set dot in trunk for last row with any @s
                $i=0;                       # no @s in next row
                $j=$x;                      # spaces in next row equal to trunk width
        }
        else {
                $i -= $k;                   # reduce @s for next row
                $j += $k;                   # increase spaces for next row
                $k++;                       # increase increment/decrement counter
        }

        if($n == 0) {                       # if this is the last row
                y/ /_/;                     # replace spaces with underscores
        }

        say;                                # print the row
}

```

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


title: Boil eggs using hourglasses

text:
# Question
Title: Boil eggs using hourglasses
These are the classical puzzles:

> You need to boil eggs for exactly 9 minutes, or else the visiting Duchess will complain, and you will lose your job as head chef.
>
> But you have only 2 Hourglasses, one measures 7 minutes, and the other measures 4 minutes. How can you correctly measure 9 minutes?
>
> (taken from here)

Let's write a program which will produce a solution for any such puzzle.

Input: 3 numbers a, b, x

Here a and b are the durations of the hourglasses, and x is the required time for boiling the eggs. Let's assume the following:

* 0 \< a \< b (without loss of generality)
* x is not divisible by a or b (to make the problem non-trivial)
* x \> 0
* x is divisible by gcd(a, b) (to ensure a solution exists)

Output: a string which contains commands, such that after executing the commands, we get our eggs boiled for exactly x minutes.

The possible commands are:

* 'A' - turn hourglass A
* 'B' - turn hourglass B
* 'a' - wait until hourglass A runs out
* 'b' - wait until hourglass B runs out
* 's' - start boiling the eggs

You may use any single non-whitespace character to encode each command.

You may also use longer strings to encode commands, but then the string of commands must contain separators between each pair of commands.

You may also add a special command "stop boiling the eggs" if it makes implementation easier (naturally, you cannot restart the boiling - the "stop" command is for the case your algorithm cannot restrain itself from printing additional commands after it prints the solution).

You don't need to optimize your string of commands: it may use an inefficient algorithm or contain unnecessary commands, as long as the result is correct.

Test cases:

```
3, 5, 1 => ABaAbBsa
4, 7, 9 => ABaAbBsaAaAa
7, 11, 15 => ABaAsbBb
69, 105, 42 => ABaAbBaAaAbBaAbBaAaAbBaAsb
60, 256, 2020 => ABaAaAaAaAbBaAaAaAaAbBaAsaAaAaAbBaAaAaAaAaAbBaAaAaAaAbBaAaAaAaAbBaAaAaAaAbBaAaAaAaAaAbBaAaAaAaAbBb

```

Note: these solutions were generated by a script, so they contain completely unnecessary commands.

# Answer
# 05AB1E, 29 bytes

```
∞*.Δ³-²Ö}©ƒN¹Ö₃*N²Ö₂*®³-NQJ0K

```

Port of *@SurculoseSputum*'s Python answer, so make sure to upvote him!!

Takes the inputs in the same order as the challenge description: `a,b,x`.
Outputs `95261` instead of `aAbBs` respectively.

Try it online or verify all test cases or verify the results with the Python script.

**Explanation:**

```
∞           # Push an infinite positive list: [1,2,3,...]
 *          # Multiply each by the (implicit) input `a`: [a,2a,3a,...]
  .Δ        # Get the first item in this list which is truthy for:
    ³-      #  Subtract the third input `x`
      ²Ö    #  And check if it's divisible by the second input `b`
  }©        # After we've found our value: store it in variable `®` (without popping)
    ƒ       # Loop `N` in the range [0, `®`]:
     N¹Ö    #  Check if `N` is divisible by the first input `a`
        ₃*  #  Multiply this by 95 (so 95 if truthy; 0 if falsey)
     N²Ö    #  Check if `N` is divisible by the second input `b`
        ₂*  #  Multiply this by 26 (so 26 if truthy; 0 if falsey)
     ®³-NQ  #  Check if `®` minus the third input `x` is equals to `N`
            #  (1 if truthy; 0 if falsey)
     J      #  Join all values on the stack together
      0K    #  And remove all 0s
            # (after the loop, the result is output implicitly)

```
> 2 votes

# Answer
# Python 2, ~~157~~ ~~154~~ ~~108~~ 103 bytes

```
a,b,c=input()
t=c
while t%a:t+=b
print"".join("aA"[i%a*2:]+"bB"[i%b*2:]+"s"[i^t-c:]for i in range(t+1))

```

Try it online! or Check all test cases!

**Input**: from `STDIN`, 3 positive integers `a,b,c` representing the 2 hourglass times and the time needed for the egg to boil.
**Output**: print to `STDOUT` a string of commands following the specification.

### Big idea

There exists positive integers \\$x,y\\$ such that: $$ax-by=c$$ (Proof in the last section)

Thus, if we continuously flip both hourglasses, the time between when the second hourglass finishes \\$y\\$ flips and when the first hourglass finishes \\$x\\$ flips is exactly equal to the time needed to boil the egg.

### Code overview

`t` keeps track of \\$by+c\\$. We increment \\$y\\$ until \\$\frac{by+c}{a}\\$ is an integer. When a valid value of `t` is found, `t` will be the time needed to flip the first hourglass \\$x\\$ times, and also the time when the egg should be done. `t-c` is the time when the second hourglass finishes \\$y\\$ flips, and also the time when the egg should start to be boiled.

The command string is created by increasing the time `i`, and insert `"aA"` or `"bB"` every time \\$a\\$ or \\$b\\$ divides the current time. `"s"` is inserted when the time is `t-c`.

### Proof of the existence of \\$x\\$ and \\$y\\$.

Since \\$c\\$ is a multiple of \\$gcd(a,b)\\$, Bézout's identity claims that there exists integers \\$k\_1, k\_2\\$ (which can be negative) such that: $$k\_1a-k\_2b=c$$ Since \\$ba - ab = 0\\$, we can increase \\$k\_1\\$ and \\$k\_2\\$ by \\$b\\$ and \\$a\\$ without changing the result: $$(k\_1+b)a-(k\_2+a)b=c$$ Thus, we can keep increasing \\$k\_1\\$ and \\$k\_2\\$ until they are both positive.
> 8 votes

# Answer
# JavaScript (ES6), 93 bytes

Takes input as `(a)(b)(x)`.

```
A=>(B,k=0)=>g=X=>(k+X)%A?"bB"+(h=n=>"aA".repeat(n+1))(-~~(~-k/A+1)+(k+=B)/A)+g(X):"bs"+h(X/A)

```

Try it online!

or Check the results online! with @SurculoseSputum's script

### How?

The algorithm used requires to count the number of multiples of \\$A\\$ between \\$k\\$ (a multiple of \\$B\\$) and \\$k+B\\$ (included). This is done with the following formula:

$$\left\lfloor\frac{k+B}{A}\right\rfloor-\left\lceil\frac{k}{A}\right\rceil+1$$

which is translated as the following JS code:

```
(k + B) / A - ~~(~-k / A + 1) + 1

```

whose result is implicitly floored.

### Commented

\\$h\\$ is a helper function that repeats `"aA"` \\$n+1\\$ times:

```
h = n => "aA".repeat(n + 1)

```

Main function:

```
A =>                     // A = duration of hourglass A
(B, k = 0) =>            // B = duration of hourglass B; k = counter
g = X =>                 // g is a recursive function taking the boiling time X
  (k + X) % A ?          // if k + X is not a multiple of A:
    "bB" +               //   append "bB"
    h(                   //   repeat "aA" as many times as there are ...
      -~~(~-k / A + 1) + //     ... multiples of A between k and k + B (included),
      (k += B) / A       //     using the formula described above
    ) +                  //
    g(X)                 //   append the result of a recursive call
  :                      // else:
    "bs" +               //   append "bs"
    h(X / A)             //   repeat "aA" floor(X / A) + 1 times

```
> 3 votes

# Answer
# Charcoal, 44 bytes

```
ＮθＮηＮζ⭆⊗×θη⁺⎇﹪ιθω⁺aA⎇﹪⁺ιζηωs⎇﹪ιηω⁺bB⎇﹪⁻ιζθωS

```

Try it online! Link is to verbose version of code. Uses `S` to stop boiling, so the actual boiling time is from the first `s` to the first `S` after the first `s`. Explanation:

```
ＮθＮηＮ

```

Input `a`, `b` and `x`.

```
ζ⭆⊗×θη⁺

```

Loop from `0` to `2ab`.

```
⎇﹪ιθω⁺aA

```

If this is a multiple of `a` then stop and start the `a` hourglass.

```
⎇﹪⁺ιζηωs

```

In addition if this plus `x` is a multiple of `b` then start boiling.

```
⎇﹪ιηω⁺bB

```

If this is a multiple of `b` then stop and start the `b` hourglass.

```
⎇﹪⁻ιζθωS

```

In addition if this minus `x` was a multiple of `a` then stop boiling.
> 2 votes

# Answer
# Python 3.7, 158 bytes

I'm very new to this, so if there's some convention on explanations/proofs that should be included please helpfully point me in the right direction.

**My Solution:**

1.) Not including 's', there is only one move that can be done without returning to a previous point. Wait for a timer to run out if both are running, or if a timer is empty flip that timer. Since timer 'a' is shorter than 'b', you start both, keep flipping 'a' until 'b' runs out, keep flipping 'b' until 'a' runs out (only once), and repeat this cycle indefinitely. It will of course return eventually to a previous position, but if a solution exists it will be found first.

2.) Keeping track of the time left on 'a' when 'b' runs out, you see that it is always some number 'd' less than or equal to 'a'. If a solution exists, eventually the time to cook the egg is a multiple 'n' of 'a' plus or minus 'd'.

3.) If the time to cook is 'n' x 'a' + 'd', start the egg, continue cycling 'a' until the egg is done. If the time to cook is 'n' x 'a' - 'd', start the egg, flip 'a' so it runs *backwards* 'd' minutes, and continue cycling 'a' until the egg is done.

**My Code:**

```
a,b,c=3,5,1
d,i,j,k=a,2,'AB','Aa'
while i:
 i+=1;d,j=((b-d)%a,j+k*((b-d)//a+1)) if i%2 else (a-d,j+'bB')
 if c%a==d:j+='s'+'A'*(i%2)+'a'+k*(c//a);i=0;print(j)

```

Try it online
> 2 votes

# Answer
# Java 8, 115 bytes

```
(a,b,c)->{int t=c,i=0;for(;t%a>0;)t+=b;for(;i<=t;)System.out.print((i%a<1?"aA":"")+(i%b<1?89:"")+(i++==t-c?1:""));}

```

Port of *@SurculoseSputum*'s Python answer, so make sure to upvote him!!

Outputs `891` instead of `bBs` respectively.

Try it online or verify the results with the Python script.
> 1 votes

---
Tags: code-golf, arithmetic
---


title: Convert to and from Base 94

text:
# Question
Title: Convert to and from Base 94
# The challenge

Make 2 programs which convert decimal to and from base 94, or a bidirectional program.

# Base 94?

Base 94 is like any other base, but instead of 0 to 9 and letters, it uses ASCII characters 33 to 126. Not 127 because `chr(127)` is DEL. Not 32 because that's a *space*.

# Examples

```
0 - ! or empty string
1 - "
93 - ~
94 - "!
2020 - 6O
14233221 - 2-n8

```

# Scoring

For two programs, the score will be the sum of the byte count of both of the programs.

The bidirectional program is simply just the byte count. Consider it like a -50% to the score.

# Answer
# Haskell, 42 + 31 = 73 bytes

**To base 94: 42 bytes**

```
(l!!)
l="":tail[s++[c]|s<-l,c<-['!'..'~']]

```

Try it online!

Instead of using modular arithmetic, we generate the list `l` of all strings in the desired order and index into it.

The recursive definition of `l` is similar to this one for generating all strings, but modified to output strings in the desired order by appending the new character, and with a `tail` to prevent the analogue of leading zeroes.

**From base 94: 31 bytes**

```
foldl(\n->(94*n-33+).fromEnum)0

```

Try it online!

Iterates over the characters `c` of the string, updating the current value `n` to `94*n-33+fromEnum c`.
> 8 votes

# Answer
# Python 2, 40 + 45 = 85 bytes

**To base 94: 40 bytes**

```
f=lambda n:n*"?"and f(n/94)+chr(n%94+33)

```

Try it online!

Python 3 would need 1 extra byte for `//` in place of `/`.

**From base 94: 45 bytes**

```
g=lambda s:s>''and g(s[:-1])*94+ord(s[-1])-33

```

Try it online!

**Both to and from base 94: 86 bytes**

```
h=lambda x:x*'?'and h(x/94)+chr(x%94+33)if x<''else x>''and h(x[:-1])*94+ord(x[-1])-33

```

Try it online!

A Frankenstein's monster stitched from the two above functions that turns out just barely longer than their byte total. Since this function accepts both numbers and strings, care must be taken not to produce an error caused by an illegal operation by acting on the wrong type.
> 6 votes

# Answer
# C (gcc), (34 + 44) = 78 bytes

The 'Decimal to Base94' function prints the Base94 number to STDOUT, whereas the 'Base94 to Decimal' function actually returns the integer.

---

### Decimal to Base94:

```
f(n){n&&f(n/94)+putchar(n%94+33);}

```

Try it online!

### Base94 to Decimal:

```
n;f(char*s){for(n=0;*s;n=n*94+*s++-33);n=n;}

```

Try it online!
> 5 votes

# Answer
# Bash \+ GNU utilities, Score 37 + 70 = 107 bytes

---

# Base 10 to Base 94: 37 bytes

```
dc<<<94o$1p|sed 's/\b \|$/ 33+P/g'|dc

```

Try the test suite online!

Input is passed as an argument, and output is on stdout.

This works for inputs from \\$0\\$ through \\$94^{23}-1.\\$

This is probably sufficient, since \\$94^{23}-1\\$ is a huge number (46 decimal digits long — `2409576021839340871044919550282633620681129983` in base 10, or `~~~~~~~~~~~~~~~~~~~~~~~` in base 94), and this is already much larger than most languages can handle.

---

If you want it to work for arbitrarily large inputs, subject only to memory limitations, use

`dc<<<94o$1p|sed 's/\\//g;s/\b \|$/ 33+P/g'|dc`

instead (which is 45 bytes long).

---

# Base 94 to Base 10: ~~78~~ 70 bytes

```
n=$1;for((;${#n};)){ r=$[94*r+`printf %d "'$n"`-33];n=${n:1};};echo $r

```

Try the test suite online!

Input is passed as an argument, and output is on stdout.

This works for inputs up to \\$2^{63}-1\\$ (bash's maximum integer). That's `9223372036854775807` in base 10, or `1**0#VEx9D` in base 94.

If you would like it to work for arbitrarily large inputs (subject to resource limitations), use

```
o()([ "$1" ]&&(printf %dz "'$1";o ${1:1}))
dc<<<`o $1|sed s/z/\ 33-+94*/g`94/p

```

(78 bytes long) instead.
> 3 votes

# Answer
# 05AB1E, Score 10 bytes

*-4 bytes overall thanks to @KevinCruijssen*

## 05AB1E, 5 bytes

```
žQ¦Åв

```

Try it online!

# 05AB1E, 5 bytes

```
žQ¦Åβ

```

Try it online!
> 3 votes

# Answer
# , 4 bytes

Encoding/Decoding program, it's bidirectional.

```
lpQB

```

# Explanation

```
lp   % All printable characters, including the space.
  Q  % Extract all of the string except for the first item.
   B % Convert the input to/from base 94 using the custom base.

```
> 3 votes

# Answer
# Haskell, ~~44~~ 43 + 32 = 75 bytes

-1 byte thanks to xnor.

**Base 10 to base 94:**

```
g 0=""
g n=g(div n 94)++[['!'..]!!mod n 94]

```

Try it online!

**Base 94 to base 10:**

```
foldl(#)0
n#c=n*94+fromEnum c-33

```

Try it online!
> 3 votes

# Answer
# Japt, 4 bytes

Base-94 I/O as an array of characters. Output for `0` is an empty array, input for `0` can either be an empty array or `["!"]`.

```
;ìEÅ

```

Try it
> 3 votes

# Answer
# C (gcc), 34 + 43 = 77 bytes

# Encoder

```
f(n){n&&f(n/94)|putchar(n%94+33);}

```

Try it online!

# Decoder

```
r;f(int*s){for(r=0;*s;)r=r*94+*s++-33;s=r;}

```

Takes a wide string as argument.

Try it online!
> 3 votes

# Answer
# Wolfram Language (Mathematica), 80 bytes

```
{FromCharacterCode[#~IntegerDigits~94+33]&,FromDigits[ToCharacterCode@#-33,94]&}

```

Try it online!
> 2 votes

# Answer
# Charcoal, 11 or 7 bytes

## Base 10 to base 94: 5 bytes

```
⍘Ｎ✂γ¹

```

Try it online! Link is to verbose version of code. Takes input as a string of decimal digits optionally wrapped in `[]`. Explanation:

```
 Ｎ      Cast input to number
⍘       Base conversion from custom base
   γ    Printable ASCII (including space)
  ✂ ¹   Slice off the first character
        Implicitly print

```

## Base 94 to base 10: 6 bytes

```
Ｉ⍘Ｓ✂γ¹

```

Try it online! Link is to verbose version of code. Note: Due to the way Charcoal parses input, if the input looks like JSON then Charcoal will input it as JSON instead of a literal string. To avoid that, quote the input and wrap it in `[]`s, e.g. to input `[0]` use `["[0]"]`. Explanation:

```
  Ｓ     Cast input to string
 ⍘      Base conversion from custom base
    γ   Printable ASCII (including space)
   ✂ ¹  Slice off the first character
Ｉ       Cast from integer
        Implicitly print

```

## Bidirectional: 7 bytes

```
⁺ω⍘Ａ✂γ¹

```

Try it online! Link is to verbose version of code. Takes input as JSON wrapped in `[]`s. Explanation:

```
   Ａ    Input JSON element
  ⍘     Base conversion to or from custom base
     γ  Printable ASCII (including space)
    ✂ ¹ Slice off the first character
⁺ω      Concatenate empty string (casts result to string)
        Implicitly print

```
> 2 votes

# Answer
# Python 2, 53 + 46 = 99 bytes

**Base 10 to base 94:**

```
n=input();r=''
while n:r=chr(n%94+33)+r;n/=94
print r

```

Try it online!

**Base 94 to base 10:**

```
lambda s:reduce(lambda a,b:a*94+ord(b)-33,s,0)

```

Try it online!
> 2 votes

# Answer
# Python 2, ~~47 + 51 = 98~~ 40 + 42 = 82 bytes

*Saved 12 bytes, inspired by @ovs 's suggestion.*
*Saved 1 byte by replacing `len(s)` with `s>[]`, stolen from @xnor's Python answer.*

```
f=lambda n:n*`n`and f(n/94)+chr(n%94+33)
g=lambda s:s>[]and ord(s.pop())-33+g(s)*94

```

Try it online!

`f` takes in an integer, and returns the base 94 string. Returns the empty string for `0`.
`g` takes in a list of characters, and returns an integer. If input is a empty list (representing an empty string), `False` is returned in stead of `0`, which is functionally equivalent in Python.

### Python 2, 82 bytes

This is the bidirectional function that combines the previous 2 functions, with the same total byte count. Utilize the fact that in Python 2, `0 < positive int < empty list < non-empty list`.

```
f=lambda n:n>[]and ord(n.pop())-33+f(n)*94or n<[]and n*`n`and f(n/94)+chr(n%94+33)

```

Try it online!

**Input/output**: If `n` is a list of characters, return the converted integer. If `n` is an integer, returns its base 94 string.
> 2 votes

# Answer
# Ruby, 33 + 34 = 67 bytes

## Encode (33):

```
f=->n{n>0?f[n/94]+""<<n%94+33:""}

```

Try it online!

## Decode (34):

```
->s{i=0;s.bytes{|x|i=i*94+x-33};i}

```

Try it online!

Thanks Value Ink, as usual, for some byte trimming.
> 2 votes

# Answer
## K (ngn/k), 9 + 10 = 19 bytes

## To base 94, 9 bytes

```
`c$33+94\

```

Try it online!

## From base 94, 10 bytes

```
94/-33+`i$

```

Try it online!

## , 15 + 13 = 28 bytes

## To base 94, 15 bytes

```
[:u:33+94&#.inv

```

Try it online!

## From base 94, 13 bytes

```
94#._33+a.i.]

```

Try it online!
> 2 votes

# Answer
# x86 32-bit machine code, 14 + 17 = 31 bytes

atoi: explicit-length string input, pointer and length. Returns `uint32_t`
itoa: pointer to the end of a buffer, returns pointer to the first digit. Only works for non-negative `int32_t` \- would cost 1 extra byte to `xor edx,edx` before div instead of `cdq` to sign-extend.

objdump -d -Mintel disassembly of both functions with machine code (the actual answer) and the source. Comments added manually.

```
    ;; input: char *RDI, size_t RCX
    ;; returns: unsigned EDX
    ;; clobbers: EAX temporary to load digits
08049000 <atoi_b94>:
 8049000:       31 c0                   xor    eax,eax               ; EAX = 0 so lodsb zero-extends to 32-bit
 8049002:       99                      cdq                          ; EDX = 0 = total
08049003 <atoi_b94.loop>:
 8049003:       ac                      lods   al,BYTE PTR ds:[esi]
 8049004:       6b d2 5e                imul   edx,edx,0x5e          ; total *= base
 8049007:       8d 54 02 df             lea    edx,[edx+eax*1-0x21]  ; total += char_to_int(digit)
 804900b:       e2 f6                   loop   8049003 <atoi_b94.loop>
 804900d:       c3                      ret

```

You could call atoi from C if you declare the return value as a 128-bit integer, or a struct. itoa uses different calling convention.

```
    ;; input: unsigned EAX, char *RDI=end_ptr
    ;; result: converts into base94 in printing order in the buffer
    ;; returns: RDI=pointer to the first digit.  Caller knows where the end is because it passed that arg
    ;; clobbers: EDX
0804900e <itoa_end_base94>:
 804900e:       6a 5e                   push   0x5e
 8049010:       59                      pop    ecx      ; ECX = base
08049011 <itoa_end_base94.toascii_digit>:                         ; do{
 8049011:       99                      cdq
 8049012:       f7 f1                   div    ecx                  ; EAX = quotient, EDX = remainder
 8049014:       83 c2 21                add    edx,0x21
 8049017:       4f                      dec    edi
 8049018:       88 17                   mov    BYTE PTR [edi],dl    ; *(--p) = digit
 804901a:       85 c0                   test   eax,eax            ; }while(x)
 804901c:       75 f3                   jne    8049011 <itoa_end_base94.toascii_digit>
 804901e:       c3                      ret

```

next address is 0x1f, total size = 0x1f - 0 = 31 bytes.

Some of the comments use 64-bit registers; I switched to 32-bit to save 2 bytes in single-byte `dec edi` vs. `dec rdi` REX opcode modrm.

**Try it online!** with a test harness that converts an assemble-time-constant value to a string and back, prints the result, and checks for integer equality. Change the assembler command line option to `-dTESTVAL=94` or whatever to test other values. If it prints the right string and exit status is `0`, it worked.

I used FASM on TIO so I could make 32-bit code; TIO's will only assemble 64-bit object files with NASM/YASM, but FASM can output an executable directly, no linker involved.

---

For "normal" asm atoi and itoa, see my answers on those linked SO questions. Golfing them was straightforward, with only one significant change: use explicit-length strings for itoa so we can use `loop` instead of having to check for a terminator before `tot = tot*base + digit`. And turning `itoa` into a function that just does the conversion into the caller's buffer.

I also made the `94` and `33` assemble-time symbolic constants (in the TIO link)

I had hoped we might get some use out of `stosb`, but we need to go backwards, and I couldn't justify having `atoi` depend on DF=0 while having `itoa` use `std` without `cld`. Also, getting the remainder into AL means swapping with EDX, but then we need to swap back for the next `div`.

```
;; alternate worse version for after DIV
     std
     xchg   eax, edx
     add    al, ZERODIGIT        ; 2 bytes
     stosb                       ; *p-- = digit.  would also need a scasb or inc edi at the end to fix
     xchg   eax, edx
     cld

```

That's *nearly* break-even, IIRC one byte longer, but does `*p-- = digit` instead of the `*--p = digit` that we actually want. (Caller could change to pass a pointer to the last element of the buffer, instead of past the end, but I don't think we can justify returning a pointer to the uninitialized space below the first digit. So that would cost an extra `inc edi` after the loop.
> 2 votes

# Answer
# Raku (raku -p) 60+42 Bytes = 102 Bytes

```
# convert base-10 to base-94
$!='';while $_ {$!=(chr $_%94+33)~$!;$_=$_.Int div 94};$_=$!

# convert base-94 to base-10
$!=0;$!=94*$!+$_-33 for $_.comb».ord;$_=$!

```
> 1 votes

# Answer
# Red, 68 + 58 = 126 bytes

## To base 94, 68 bytes

```
f: func[n][head either n > 0[append f n / 94 #"!"+(n % 94)][copy""]]

```

Try it online!

## From base 94, 58 bytes

```
g: func[s][either""= s[0][(-33 + take/last s)+(94 * g s)]]

```

Try it online!
> 1 votes

# Answer
# Perl 5, ~~36~~ 32 + ~~26~~ 23 = 55 bytes

**To base 94:** (Commandline options: `-Minteger -n`)

```
do{print chr$_%94+33}while$_/=94

```

Try it online!

**From base 94:** (Commandline Options: `-pF`)

```
map$\=$\*94-33+ord,@F}{

```

Try it online!
> 1 votes

# Answer
# PowerShell, 62 + 27 = 89 bytes

**To Base 94:**

```
param($a)for(;$a){$a-=$r=$a%94
$a/=94
$n=[char]($r+33)+$n}"$n"

```

Try it online!

**From Base 94:**

```
$args|%{$n=$n*94+$_-33}
+$n

```

Expects input via splatting.

Try it online!
> 1 votes

# Answer
# Julia 1.0, 40+46=86 bytes

### To Base 64, 40 bytes

```
!x=reverse(join('!'.+digits(x,base=94)))

```

### From Base 64, 46 bytes

```
~x=sum(@. 94^(length(x)-1:-1:0)*((x...,)-'!'))

```

Try it online!
> 1 votes

# Answer
# Python 3, 172 bytes

```
def t(n):return"0"if n<1 else t(n//94).lstrip("0")+''.join(map(chr,range(33,127)))[n%94]
def f(n):return ord(n)-33 if len(n)<2 else f(n[1:])+(ord(n[0])-33)*(94**(len(n)-1))

```

Try it online!

Based off this answer on StackOverflow
> 0 votes

---
Tags: code-golf, number, base-conversion
---


title: Is it bipartite?

text:
# Question
Title: Is it bipartite?
A bipartite graph is a graph whose vertices can be divided into two disjoint set, such that no edge connects two vertices in the same set. A graph is bipartite if and only if it is 2-colorable.

---

# Challenge

Your task is to, given the adjacency matrix of an undirected simple graph, determine whether it is a bipartite graph. That is, if an edge connects vertices i and j, both (i, j) and (j, i) entry of the matrix are 1.

Since the graph is undirected and simple, its adjacency matrix is symmetric and contains only 0 and 1.

# Specifics

You should take an N-by-N matrix as input (in any form, e.g. list of lists, list of strings, C-like `int**` and size, flattened array, raw input, etc.).

The function/program should return/output a truthy value if the graph is bipartite, and falsy otherwise.

# Test Cases

```
['00101',
 '00010',
 '10001',
 '01000',
 '10100'] : False
['010100',
 '100011',
 '000100',
 '101000',
 '010000',
 '010000'] : True (divide into {0, 2, 4, 5} and {1, 3})
['00',
 '00'] : True

```

# Scoring

Builtins that compute the answer directly are banned.

This is , so the shortest program (in bytes) by the end of this month wins!

# Answer
> 4 votes
# Husk, 17 bytes

```
§V¤=ṁΣṠMSȯDfm¬ṀfΠ

```

Prints a positive integer if the graph is bipartite, `0` if not. Try it online!

## Explanation

This is a brute force approach: iterate through all subsets **S** of vertices, and see whether all edges in the graph are between **S** and its complement.

```
§V¤=ṁΣṠMSȯDfm¬ṀfΠ  Implicit input: binary matrix M.
                Π  Cartesian product; result is X.
                   Elements of X are binary lists representing subsets of vertices.
                   If M contains an all-0 row, the corresponding vertex is never chosen,
                   but it is irrelevant anyway, since it has no neighbors.
                   All-1 rows do not occur, as the graph is simple.
      ṠM           For each list S in X:
              Ṁf   Filter each row of M by S, keeping the bits at the truthy indices of S,
        S  fm¬     then filter the result by the element-wise negation of S,
         ȯD        and concatenate the resulting matrix to itself.
                   Now we have, for each subset S, a matrix containing the edges
                   from S to its complement, twice.
§V                 1-based index of the first matrix
  ¤=               that equals M
    ṁΣ             by the sum of all rows, i.e. total number of 1s.
                   Implicitly print.

```

# Answer
> 20 votes
# Wolfram Language (Mathematica), ~~26~~ 25 bytes

```
Tr[#//.x_:>#.#.Clip@x]<1&

```

Try it online!

## How it works

Given an adjacency matrix A, we find the fixed point of starting with B=A and then replacing B by A2B, occasionally clipping values larger than 1 to 1. The kth step of this process is equivalent up to the `Clip` to finding powers A2k+1, in which the (i,j) entry counts the number of paths of length 2k+1 from vertex i to j; therefore the fixed point ends up having a nonzero (i,j) entry iff we can go from i to j in an odd number of steps.

In particular, the diagonal of the fixed point has nonzero entries only when a vertex can reach itself in an odd number of steps: if there's an odd cycle. So the trace of the fixed point is 0 if and only if the graph is bipartite.

Another 25-byte solution of this form is `Tr[#O@n//.x_:>#.#.x]===0&`, in case this gives anyone ideas about how to push the byte count even lower.

## Previous efforts

I've tried a number of approaches to this answer before settling on this one.

**26 bytes: matrix exponentials**

```
N@Tr[#.MatrixExp[#.#]]==0&

```

Also relies on odd powers of the adjacency matrix. Since x\*exp(x2) is x + x3 \+ x5/2! + x7/4! + ..., when x is a matrix A this has a positive term for every odd power of A, so it will also have zero trace iff A has an odd cycle. This solution is very slow for large matrices.

**29 bytes: large odd power**

```
Tr[#.##&@@#~Table~Tr[2#!]]<1&

```

For an n by n matrix A, finds A2n+1 and then does the diagonal check. Here, `#~Table~Tr[2#!]` generates 2n copies of the n by n input matrix, and `#.##& @@ {a,b,c,d}` unpacks to `a.a.b.c.d`, multiplying together 2n+1 copies of the matrix as a result.

**53 bytes: Laplacian matrix**

```
(e=Eigenvalues)[(d=DiagonalMatrix[Tr/@#])+#]==e[d-#]&

```

Uses an obscure result in spectral graph theory (Proposition 1.3.10 in this pdf).

# Answer
> 4 votes
# APL (Dyalog Extended), ~~16~~ 13 bytes

```
⍱1 1⍉∨.∧⍣2⍣≡⍨

```

Try it online!

-3 bytes thanks to @H.PWiz.

Uses the algorithm from Misha Lavrov's top Mathematica answer: initialize `A = B = M`, left-multiply `B` twice to `A` and clamp it until it reaches the fixed point, and test if the diagonal entries are all zero.

The regular matrix product `A+.×B` counts the *number* of two-step paths from node `m` to node `p` passing through any intermediate node `n`. If we change the code to `A∨.∧B`, we instead get a boolean matrix indicating if there *exists* any two-step path from node `m` to node `p`. We don't need extra "clamping" operation that way.

### How it works

```
⍱1 1⍉∨.∧⍣2⍣≡⍨  ⍝ Input: adjacency matrix M
          ⍣≡⍨  ⍝ Find the fixed point, with
               ⍝     Starting point A = Left arg B = M...
     ∨.∧⍣2     ⍝   Left-multiply (matmul) B twice to A
               ⍝   indicating existence of paths (boolean)
 1 1⍉          ⍝ Extract the main diagonal
⍱              ⍝ Test if all elements are zero

```

# Answer
> 3 votes
# JavaScript, 78 bytes

```
m=>!m.some((l,i)=>m.some((_,s)=>(l=m.map(t=>t.some((c,o)=>c&&l[o])))[i]&&s%2))

```

Input array of array of 0 / 1, output true / false.

```
f =

m=>!m.some((l,i)=>m.some((_,s)=>(l=m.map(t=>t.some((c,o)=>c&&l[o])))[i]&&s%2))

run = () => o.value=f(i.value.trim().split('\n').map(v=>v.trim().split('').map(t=>+t)))
```

```
<textarea id=i oninput="o.value=''" style="width:100%;display:block;">010100
100011
000100
101000
010000
010000
</textarea>
<button type=button onclick="run()">Run</button>
<div>Result = <output id=o></output></div>
```

# Answer
> 2 votes
# Pyth, 25 bytes

```
xmyss.D.DRx0dQx1d.nM*FQss

```

**Try it online!**

This returns `-1` for falsy, and any non-negative integer for truthy.

## How it works

```
xmyss.D.DRx0dQx1d.nM*FQss ~ Full program, receives an adjacency matrix from STDIN.

                    *FQ   ~ Reduce (fold) by cartesian product.
                 .nM      ~ Flatten each.
 m                        ~ Map with a variable d.
         R   Q            ~ For each element in the input,
       .D                 ~ Delete the elements at indexes...
          x0d             ~ All indexes of 0 in d.
     .D                   ~ And from this list, delete the elements at indexes...
              x1d         ~ All indexes of 1 in d.
    s                     ~ Flatten.
   s                      ~ Sum. I could have used s if [] wouldn't appear.
  y                       ~ Double.
x                         ~ In the above mapping, get the first index of...
                       ss ~ The total number of 1's in the input matrix.

```

This works in commit d315e19, the current Pyth version TiO has.

---
Tags: code-golf, decision-problem, graph-theory, binary-matrix
---


# Question
Title: Who's that pokemon (based on its etymology)?
As we all know, most Pokemon are created by combining some English (or Japanese) words; these words are the Pokemon's "etymology." For example, "charmander" is "char" and "salamander" put together.

Your task is, given a Pokemon's etymology and number, output the original Pokemon name. A short answer will be able to compress the 890 Pokemon into much fewer characters by exploiting the fact that the etymologies and the names themselves use mostly the same characters.

**Input:** The Pokemon number, and an array/list of etymologies, all lowercase

**Output:** The Pokemon's name, also lowercase

The full list of test cases can be found here: https://pastebin.com/B3rRdiPn. Each line is a test case with the format:

```
<pokemon number>;<comma separated etymology list>;<pokemon name>

```

This list was created from https://pokemondb.net/etymology by running the following code:

```
let collectedRows = [];
let rows = $(".data-table tr").slice(1)
let isOddPrev = false;
// Replacements due to typos, remove 'palindrome' since girafig doesn't come from the word 'palindrome', 'palindrome' is just a descriptor
var repl = {"anacondo": "anaconda", "armadilo": "armadillo", "[palindrome]": ""}
rows.each((_, row) => {
  let isOdd = row.classList.contains("odd");
  let etym = $(row).find(".cell-etym-word").text().toLowerCase();
  if (repl.hasOwnProperty(etym)) etym = repl[etym];
  if (isOdd !== isOddPrev) {
    collectedRows.push({name: $(row).find(".cell-name").text().toLowerCase(), etymology: [etym], num: parseInt($(row).find(".cell-num").text().replace(/\s/g, ''), 10)});
  } else {
    collectedRows[collectedRows.length - 1].etymology.push(etym);
  }

  isOddPrev = isOdd;
});

// Output:
collectedRows.map(pokemon => pokemon.num + ";" + pokemon.etymology.join(",").replace(/\,$/, '') + ";" + pokemon.name).join("\n")

```

**Examples**:

The full list of test cases can be found at the pastebin link, but here are some example inputs and outputs:

```
1, ['bulb', '-saur'] --> 'bulbasaur'
122, ['mr.', 'mime artist'] --> 'mr. mime'
29, ['nidoru' ,'rhino', '♀'] --> 'nidoran♀'
16, ['pigeon'] --> 'pidgey'
17, ['pigeon'] --> 'pidgeotto'
23, ['snake'] --> 'ekans'

```

Note that due to 'nidoran♀' and its family, you need to be able to handle input/output in UTF-8.

The winner is the entry with the highest accuracy, with ties broken by code length. In practice, this means that the challenge is code-golf -- you need to get 100% accuracy to be a competitive entry -- since you can trivially create a lookup table, but feel free to post a sub-100% accuracy answer if you think it does something creative (someone else might extend it to handle the edge cases).

If you wish, you may also include a data file, and the number of bytes of that file is added to your byte count. This is just if you want to keep your code and data separate.

# Answer
> 7 votes
# JavaScript (Node.js 11.7+), 100%, 2094 bytes

Same as below, with the data file compressed with Brotli instead of zlib.

```
n=>a=>(require('zlib').brotliDecompressSync(require('fs').readFileSync('a'))+'').split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr(p,++l||9))

```

Try it online! (not working on TIO)

---

# JavaScript (Node.js), 100%,  ~~2176 2158~~  2151 bytes

This is similar to the self-contained version below but uses an external data file of 2010 bytes named `'a'`. The TIO link generates a local copy of this file.

The final size was computed according to the rules for scoring multiple files:

$$2010+140+1=2151$$

```
n=>a=>(require('zlib').inflateRawSync(require('fs').readFileSync('a'))+'').split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr(p,++l||9))

```

Try it online!

---

# JavaScript (Node.js), 100%,  ~~2701 ... 2359~~  2356 bytes

Takes input as `(id)([etymology0, etymology1, ...])`.

The source contains many unprintable characters.

```
n=>g=(a,i=2,s="aZOEDQ]^4+24><e_<ZZ)aku[XdFyXdttoXdt|63a%}5ks/arbok_[__S♀E2a_S♂E_]]Sx_Sy`SytuffS[K~_SB]NO[h~[]?4PS@NB;2ZW)H~~pBR_]3!AA[r~?6G/@W@GA;5'dOOXel?3U~rXk~d,/!Z%~/@82arXix_S)ZD_~?3=I?3=CO;ak*@*@&tuV2)offHUXy`Xy`WseyWelaSs18/Ta*R[WyuWmie4~r/jyUS(~r[WosWkZXarados/lapras~eveeG_NXrT/omy/om(~~ps}5_XT3`[]*i&te[~P2Z[2efD/cyF(4]Q%NB4r>KW_/leledikXi([0Tu_$~f0,`Ye`Ye`/n/x`MXZ!ORR+22T3`oed[]]/ai!/2HV2^3~J_[_]W@+vXP]SarigWH2K3P+ce*&x/qwF`YzH2>Y(QW_M5]N+KW@]$NN`2K4XrT42OBR*@~um[M[y[2u~cZeWYSXgiho-ohWbiRWy,>E2^4C;3NBN^4%euFVM<17M]2|6XV4N3	SryD]Q/TtsJG+~8VA/U4,VE[ME]]2dEWH~]Q~[NOXVRRN<CQ5~leWn[Jse~lJQYvIQail`3aK]Z$NQ]B/3T3YnZ2e]2[/z=IO	],/corphH_[M3]Y2I?4ldo]2/4I/P4`)ec,XZ}7RMNSyut[KR]]2n/@eI]]{64/luv`XIQ{VC/P30TR__]_YiZYiZ)yogre_*zjir01Ss]K]_MO_KSy]XdZ2f|VCL6ZL6ZWx&oMONAA/buVZ]/H4Z{TnGXizC~zC?7{6{VW!Q[yO*iISkZ	M?2Uy_>N]Sjr.]]A/gZ@6$[E/=olu/luca=o~sE222kFuP2%_NA[N]MWa0b4[S&yXyV]SivZ]_]3__+Yo`XrT-zBB__/r0Im/uV$5/az`Ylgpalkia]3_QiphV~phyRYyminOni$[>WgMO/oshaw!*{TW=S<pDGQK###XnV2?5r222$~lYez,>[5aXggen3aXT2`	__2Wr/guFr`3rDAWhawkMWlI]%>DJeeS4|VZ2Y0UIK5)=ko=kL4C^3;niBM>~QEO|72ri18/tiFoPYF`WenWH3sXZ_YuaYoZYccV/ccV>QSt18DME2,]~Jite^3^3]aws`0UlH)FT3ZR/fooUYs{6/alo0U0P&k^5GGLLL4ZXVkC3kkC222lgyem/beheeyem[D<Z~wYxHXxo24MQQ2rk~fooXZ3iTQOQRJlHRK^IWH3]/doQ?4F23]ENSkZWzZASZ$4am~kVm~ormM}53aR}53BGRNK2ieD]Dby~sby^5AG<`RD[O];M3sQR+++OR]ENe<V&xNMK4XI^4kFVeMerQE>OBY082a?50aYv`[5X0TneRKYg`*LkiEMSa17	M/xZ3eas/Z3lt25/zy`Yncie~aA/VRKW(<Z~pC3}5Xk2k_^3/yC3^52?7Wj(Xk(]R8Yc0PGO321_{T4iO[[|5OO3H/fo`ONW23RR~ul/!01_/H5072RaWey]D]GYos`/py=17@Vu~: `_D?2FIQ~de`Wkyu]K/d`4T-o-oL4-o3o~ V4iSg{UYg(]G]<V/xkH3eeaXrUNXcT2zC$[[_a=ka[7nYaZ	Qy/U5`_OK{7{6kwZB{6GG_lerO&t{VWW=/dF`Q;2VXIRFolQnRGRDWk{P07[2%>SskVB3<aSanremZ&@1]3~m`SgC/pZ2V]3%5'd~ riI~rig17K|Vmie/fF,Ym_RisP2eJT2%~f,A~zZWozZ~vZWovZAXVZQ/zaciU/za0UzTJtus~/}W1|Y1{S1`10_}0^J1]}1[|0Z11Y~3X~2W~4V12U0!03S~5R}2Q}3P04O|1N{1M|2L)01K|3J~6I13H05G{0FU2E{2D}4C14B{3A^1@20?/`>{4=0V<~7;YP,15+[4*[3)/k(a`&~i%|4$X`#/P3`_!2Ti`J`_3U3~eYk{5_4/T4~ `Z;20006/wa/09/s^2}6_2	][16na/eanur~tWi")=>i<127?g(a,i+1,/[\r\n "'\--:\\a-z]/.test(c=Buffer([i]))?s:(l=s.split(c)).join(l.pop())):s.split`/`[n-1].replace(/\d.\d?/g,([i,p,l])=>a[i].substr('0x'+p,l||9))

```

Try it online!

### How?

Each name is encoded as a sequence of sub-strings from the etymology words, with some possible hard-coded characters in between.

Example:

For the first name, we are given:

```
n = 1, a = ['bulb', '-saur']

```

The name `bulbasaur` is first encoded as `004a114`, which is interpreted as:

```
'004' -> a[0].substr(0, 4) -> 'bulb'
'a'   -> hard-coded character 'a'
'114' -> a[1].substr(1, 4) -> 'saur'

```

But the length of the sub-string is omitted whenever this is possible without resulting in any ambiguity. When the length is omitted, the decoder assumes that the word must be read to its end.

Both lengths can be omitted in this case, so the final encoding is:

```
00a11

```

All the 890 encoding sequences are concatenated together, using `/` as a separator. This results in a string with a lot of repeated patterns which can be efficiently crushed:

```
00a11/00211/00412/00314/00313/00311/00514/00210324/00414/006e/00310/.../za001z03/005tus

```

# Answer
> 4 votes
# Python 3, 100%, ~~3817 ... 2463~~ 2351 bytes

```
import base64,bz2,re
def f(n,e):
 s=re.findall("[A-Z].+?(?=[A-Z])",str(bz2.decompress(base64.b85decode("LRx4!F+o`-Q(2lYjJyB>_?>`2gMW}e@IU|m@L&gzfB<{l>MaducV>;xcV1v3r}_v9qd}l1g$bb0WFnp>O&STHDd{yaqyPYlr~6YAQwdMh*(7?5KmarbspRyU5D6YB>Ux_~Kpvn20BND4Mk62^05mXaen^xm000000ENyXhobxV`;X?{ExyPLkgLKDP|*Q^?o*e5XuP4M=5UaiAd|`2;!L-!vGCJPj#;Mo=2>TVCBV{l6DI6B_r0dGFBRQ-O|~`xNM7ayY%9|*JDHKx)H%`3m$P%bfxU(EeEGzleQ$#&o^1*0>`mQyWinz&K_h&|r)n^J<>jzrwUxNpN$qXir0}FVs_7L(Ks|=pmD2iIahTy>RB*k9#U=BSIWVqS3gGbVZpVtyD8dEs&<v#@cP}dhn`W7qib`>cvCEjl7e+vZP!cd9feP7KUJ||~0FQFad}w6bGbS;17~RfNW=AZ-?8t28AOz_wt~OR85Loar%*#lVF{BpPkTAlKBBJq&5IIzogmT3wP=ZP{!d>aETG<_DSc2Oj4duuj%a?ggAaH<lR3|AC9N>Wyq;np^W5Gyus`ED9MYY}3laCeQ@R052^8Lt6chhHS=PKG_o@*~ICBX~8XnxM69}KpBRk}!|Nkn*aP*I+cKKWij;l3&FfZofSuJl}P%9C^dABC%JEw(S#R(||vwYR%OltbAF<bRs2UeKzeXleyw=czoWGHjSn^SmprWPH?|!-=07#O)v9FyZb)D!mGeg_aEbQnWd~Sv^0$(U>TLiQx_d0ZJEj?In+L@`K%YQUM1cbI1*C-ukR(DngIFmkJ^qE)Dc7>Wf?`7`YWLwM+J3Hpu`;F&p=WjHW=<cygYHc+}GOFgXO0=*q=k*RxL<?d{EH8V4g`oTFz#A1JX|L%1mW4s9(}kh|5%etRW3y*^(Q&Mub5?StGw?m&hT`PpTVGkv0+%N&w8d?ggL)Ky9rZ8uH0a~(k|k`(~|tJR@r`Py({Cly12W3l@e49in_AV<B$_48M82_#A8ioZF>x|_<d(GLXB%jJ#EoKM06qbF(%n-K(Rh5e30T@Lbt{U*=!(Vcc#m4fBN7PDDvY$Pv4VTb{T(kB_s=w_u*#yj&@6l`rQXuD>`3P==#x=l$E<$n%q;IJ`mp-930B+gn;Bw~$S@uKjrO%gEn=_!H>jn55^PfqZnK$wh^Q%|5gfsZ)n9|~pWd!n2xtMt2I+?2ybbWX#r;c3lwdR<%>6el#lge`*LM&McY@3Y(8$TKqOuoJnn4{kGvOY`c!@j7RIPUnBgv;NFWAAR3qb%r^dGr@IwwatK&meM}r5|G_r#F3<P+>Nzy0!bbI{4>gVo26MfTFI`C@jc8zgpXx@Eu<fGa<wX6eL_2i8;e3I;@L&r?bvJ&n9*mM$TElv(p5-@<V|c)7Hh_mrIE^YW36V^x@rbi>N9>_?WJ(ii7B=8@~z_)Zl+NInDcLe&b(UFUJoeXew<(w$4#fgQ*fF{D3~kj6vA}cEN9}xk}Ir+0Vg_L^9n-^vcK5|CIvx|znAi67u1Qo_x6j*K7CT**02u68QTS=v(l;tc&k3OHuc0|C|js)<DE)X04p&I%}|W-9UO;KGP$#5p9i@xrhM?-wd^{M==!3!eCtaBfyiZOyT#Z^3ERpfx}!MSu`4>PT~-A$yuO=4(hifs0Km6AkP+jd_0jSi3#ItzIy8y!Q{W$crxZ*Z*)QlMCV)VYI@mq{>v-ooMA$^@MqM5!5Gp9(wn0o=t=X)0EVIjJfhjdmfsDEjj-ge71G&1nz{?F-UqFQ!Ui_ylWX9VVX~g9$*qLc(M;YIknZP~9Iqz)r`19X%(%&7^tyi<i09Sx!2&v&7?OPu^wjVl&4RkTK`0EIzahitH>(Z=jE!=0TrmYUTXk!@-0EVT7Z$Dk^k?mU9s=n!;sXeJgsmArC7?v`d>o?r3z7o;iEO1Fh%AJ{a43j`h@{VSzjQ2rV6BP@&gj9>5W^oRe^l@a-MKjx!_Em$F2!;9_1iF}v7FOAU5MhebG!cm!#tDiAHx_=BBoyR~nT-<02#y;N1qH_>8^t3Gu2k+kP#9cRS>VnNLqLE|Fyulvo#`c=FH6J$2A-0V!(nsHf$#pb$SzC+bx%8>H$mCL5MtK&@WCh^k#Bi<=$%9ljrqSIqYVXCLeT0UO8{)!sRB>f->^P%M|mf^+&6ALwl)hsRm$4<rgGU<1DfY8|KjdQrwS4iMiG~Q"))))[n-1]
 return e[:ord(s[0])-65]+s[2:]+e[len(e)-int(s[1]):]

```

Try it online!

## Explanation

We could print all of the Pokemon with just the number, but the etymology allows us to improve the compression algorithm. Take the first input: `1;bulb,-saur;bulbasaur`. The first etymology `bulb` and the actual Pokemon have a common prefix. Most Pokemon in the list also have this property. So instead of compressing the entire name of the Pokemon, we only compress the right half of it (`asaur` in the example), starting from the longest common prefix of it and the first etymology. Then for the left half we can just directly take a prefix of the first etymology (`bulb` in the example). We also precompute the longest common suffix to further reduce the size. Then, we will encode the string like this: `44a`. The first and second characters represent the longest common prefix and suffix. The rest represent the rest of the characters not accounted.

# Answer
> 4 votes
# Python 3, ~~2526 ... 2485~~ 2477 bytes

```
import bz2,zlib,base64
b=base64.b85decode
p=bz2.decompress(b('LRx4!F+o`-Q(59BF!%rhj7R`*0Ds_61b*t7X+T7%iw!XbsxUw_05wnA5{ieYKr{d~PxKN}nvw5(BOjwtq%XftFY)%vlw$tuZI%9;4^7W^?|qN$^KHzUfTa1Tr63Y7r1jva6}^`q2S@hzE%f$eIEbHP$OqG_3SuF>V&&a2$k(oE#{VBmKW+Svm$v*~C^qWuF)k0y?|H~yTPf~!?wrgjhb&<eM^-^OI;(1`q-?Z<qzNrohfQ{Dj81Xiau!gFnMm=jU$kb-uz}rmWO5((Vh03kk%%mYEuZmlvGX6_$^WzTJCh7Hy+7CHc=YRx{QgoqG>`7FyT+mj+KfPl(=}z5nkicW9_jyi#oUj+1pt2Zy5~V&)(O@NB3@G*YRp{Y5yh8F(mPfTzhcqIpQWOApqcBDH-sdIW9L_on;F8Z)_fm*IYekeJSOk9WfqRg+zu5(LBP!vy{<xI$>jOvYGP%sVU+fDc7*izAgV1MIwhk+37)dQtR$ut3@6&%$XyH0BBLm<c9>%GPa=!bg{V#uL4%RsD6#`A-;@5%7)~}vs<Cp)eUFlBHiXIb^TiL*!_9AEc(vE!gk3-ylSFvc9vStpc27mncv+2CeeuQ%MU;U9O-dsn8Ci0wMK?I^3jC_H?kx3)h>VA_!Qw8oGiG|0{qDzI_ao-fMT~Eq(t=11(jj~sTAf+6HxA=oo9lM4X||FImXnI)Ec3xrnEb5)&dqGmLA63lR0gb2;&FLHyOcyVeFSa|%FBDJbqz)`MO*^0^yx-={jS1pqP`l6adD$JFUKx0o9E4AS+)~2vdwIDIO4(M@rF{8{Pa%t<<&k`uiatcw!sYaM2Dk_jjI|#ZFbtwNHBtD!axZ5{r;2nc)gx7J<4#**_%xXq9=l^O%(e%P}<T!l2*mtVtNR28TAS<P1US-rrh{l$rRy2Lx`Be-~')).decode()
f=lambda n,e:e[:int(p[n*2-2])]+zlib.decompress(b('c$`&LLAIkf47^G<db8?T%yMocKrwC`L>oK#<n&WzC%=10Fg#-{RjE{{jH9}U@g`|%yNWEqE)HJts9&XORW7ll`zcx`PyJopCGOuB9+zCT-S6_pQP;6F^(e9bB)uONv#HNp!Ac#IcdPUI7bnG@!S^6|xQJhv3bqI34r7Zi3t<f6PnFI0e#YAHR&r*7l;i{?%POa=UQSb4iuP=`D7P(ch6tB%%CWB&T^u+MF0zO91dI5l`^8b@I0-DyecX{vtX!15NapfuU-Vat9Zd{c`;9Hvq!=UkLWm?0JH>roy%97}g^(|T7P6^&zhAOyaRx)wvn~E~UmP`ibD2onAkv@UsF*$)murbZW(U8u*m=r%XqhEw!An!ic?{2(<%OJyoXO5w0^}g4XZ@6qOdYH4M<1nJD9As2K%QI2bpbf;=C<3rz5&quhp#e4vMgi@*~Vk+>5i4HZ2kTVTTR8pGeehaz|mZZ<4lp{;d%Z;GxEP<UKKmdwIE9F+?|p!{{XI-H&CSCdI8Uw2(YRkhm5pe1L};7%R#MzV6%f2*Svt54J^%iR<ZdL^4hhHnnpRS<SuXsy*)U$%Vc?J+gM9JE)UH5S5rj$8H=31(}(UJRKntZN3;YOXqERx;%8ZtCo47khHWtal9x2n+vOosj+>a0zD+|MXzNJwXZd?1Lh_;mbZ#hh1m90;wjJM5dJn{m*jKMx#}inH8PR=||HoT#6}dD>tDr{ul8naGoPeb$1$<hL)DHi0ZS0c$6X;y^34@W(`92Q5_<PvlM`!@LlGqDxp~guizyt~<it-S8124NnQ1~wx6WQ;Lv5KNC@+cL=IWrdEWyukG&9tpl92_{Wv^6yOHyaw*MzO#M(FLfhdGGuNt;jsHdAkKrJ_v$5hYuj?DYiK@tA!@wF0irDnb|iVwMhISheT&3G+y9S;WE^6HRF}X7tnlpzYQqEUGCTr6aw?IM9P^*h6KA(UN1B!Efcw{7fj(D4GdzVbBzTJ1GpO$k8VN?tMuOE<KmhkVOXAEozrirN(r1F4JRK~C4TXpO-XrT*92*>wU0M7M1{ysG$eGl!hCIKpwPV~WxJ<1lsAo646Uj1uw0?ReMT<IZX9clOx@B;m<nv((E#{QNd70bBimctb%GVlyr)u8s;2_@NC<7XM|@A->A?q$xu4Z+2Of+{Q|kwIzFKM<PWku7z}ykcCN5YlZ}BwH{iC0F$jdE3QgX|N9By*Ecin^Mpr3NW)=Ccr6|<|0zwl{$OC2Dp0?2Hz+>GjukMD)%&ELkHp5t0GNkaz$2aMNY_7F##_{F4MWV*9_f1ndA)t(CgvMWwV&*w^|TcpFW<0>VAHd*3!ba^0gexKQK?@#lsL}6?2G0KB)*DRC-Hkn)31U|ek0jP)gqlbmh&Jn`~r>GFaf062$Ap')).decode().split('%')[n-1]+e[len(e)-int(p[n*2-1]):]

```

Try it online!

Based on idea of @dingledooper (thanks!), but making it a step further by using the longest common suffix to help as well. Also used zlib & base85 to further reduce size a bit.

# Answer
> 4 votes
# Pyke, 100%, 835 bytes

Sorry folks, Pyke contains a built-in Pokémon dictionary. Unfortunately, it only contains up to `#802: marshadow`, so 88 names had to be hard-coded.

Should work for all inputs, but the TIO environment seems to have a slightly different version of Pyke than on the "Pyke Interpreter" website, so inputs greater than 802 only work on the latter (see below).

```
Q0@802>"poipole,naganadel,stakataka,blacephalon,zeraora,meltan,melmetal,grookey,thwackey,rillaboom,scorbunny,raboot,cinderace,sobble,drizzile,inteleon,skwovet,greedent,rookidee,corvisquire,corviknight,blipbug,dottler,orbeetle,nickit,thievul,gossifleur,eldegoss,wooloo,dubwool,chewtle,drednaw,yamper,boltund,rolycoly,carkol,coalossal,applin,flapple,appletun,silicobra,sandaconda,cramorant,arrokuda,barraskewda,toxel,toxtricity,sizzlipede,centiskorch,clobbopus,grapploct,sinistea,polteageist,hatenna,hattrem,hatterene,impidimp,morgrem,grimmsnarl,obstagoon,perrserker,cursola,sirfetch'd,mr. rime,runerigus,milcery,alcremie,falinks,pincurchin,snom,frosmoth,stonjourner,eiscue,indeedee,morpeko,cufant,copperajah,dracozolt,arctozolt,dracovish,arctovish,duraludon,dreepy,drakloak,dragapult,zacian,zamazenta,eternatus"\,cQ0@803-@&Q0@~_+1-.ol1|

```

Try it here! (This site doesn't seem to support unicode, so output for `nidoran♀` will be in UTF-8)

Try it online! (Supports unicode, but throws an error for inputs \> 802)

Takes input in the form `[1, "bulb", "-saur"]`

**Some relevant portions of the program:**

```
Q0@

```

Read from STDIN, ignoring everything besides the pokemon number

```
Q0@802>...&

```

*IF* (pokemon #) \> 802, Do the following:

```
"poipole,naganadel..."

```

\- Using this long string of hardcoded names,

```
\,c

```

-- split on commas, and

```
Q0@803-@

```

-- return the name at index ((pokemon #) - 803)

```
Q0@~_+1-...|

```

*ELSE*: Find the index of this pokemon in the dictionary

```
.o

```

\- Lookup in the built-in pokemon dictionary, and:

```
l1

```

\- convert to lowercase, implicitly print

---
Tags: code-golf, kolmogorov-complexity, natural-language, test-battery
---