title: Live a longer life

text:
# Question
Title: Live a longer life
Conways' Game of Life is a well known cellular automaton "played" on an infinite grid, filled with cells that are either alive or dead. Once given an initial state, the board evolves according to rules indefinitely. Those rules are:

* Any live cell with 2 or 3 living neighbours (the 8 cells immediately around it) lives to the next state
* Any dead cell with exactly 3 living neighbours becomes a living cell
* Any other cell becomes a dead cell

Let \\$B\_i\\$ be the board state at the \\$i\\$th step, beginning with \\$B\_0\\$ as the starting configuration, before any of the evolution rules are applied. We then define a "fixed board" to be a board state \\$B\_i\\$ such that there is a board state \\$B\_j\\$, with \\$j \> i\\$, such that \\$B\_i = B\_j\\$ (that is, all cells in both boards are identical). In other words, if a board state is ever repeated during the evolution of the board, it is a fixed board.

Due to the nature of Game of Life, this definition means that a "fixed board" is either constant, or the only evolution is a fixed periodic set of states.

For example, the following board states are fixed, as \\$B\_{217} = B\_{219}\\$, where \\$B\_{217}\\$ is the left board:

The left board state happened to be the 217th generation of this starting state, taken from this challenge.

Note that the empty board is a fixed board, and that any patterns of infinite growth, or spaceship like patterns can never result in a fixed board.

---

This is an challenge where each answer is a starting state, and the number of generations it takes to reach a fixed board must be strictly larger than the previous answer.

The \\$n\\$th answer should be a starting configuration of cells within an \\$n \times n\\$ bounding box such that, if the \\$n-1\\$th answer took \\$p\_{n-1}\\$ generations to reach a fixed board, the \\$n\\$th answer takes \\$p\_n \> p\_{n-1}\\$ generations to reach a fixed board. Note that the "number of generations" is defined as the lowest \\$i\\$ such that \\$B\_i\\$ is a fixed board. For example, the empty board takes \\$0\\$ generations, as \\$B\_0\\$ is already a fixed board.

Each answer's score is \\$i\\$, the number of generations to a fixed board.

I have posted the starting answer, for \\$n = 2\\$, with \\$p = 1\\$, below.

### Rules

* You must wait an hour between posting two answers
* You may not post two answers in a row
* You can edit your answer at any point to change its score. However, keep in mind the following:
    + If your answer is the latest, people may be working on a follow-up answer, so changing yours may invalidate their attempt
    + If your answer is in the middle of the chain, you may edit it to any score, so long as it is within the bounds of the previous and later answers.
* The answer with the highest score (i.e. the latest) at any given point in time is the winner

# Answer
# \\$n = 12, p = 2215\\$

Evolves to beehive + blinker + r-pentomino after 46 generations

```
.o.ooooooo..
....oo..o..o
.o.o...oo...
.ooooo...o..
o.....ooo...
....o..ooo..
..o..oo.o...
o.oo........
...o.o..oo.o
....oo....oo
..o.oo...o.o
..ooo.o...o.

```

RLE:

```
x = 12, y = 12, rule = B3/S23
bob7o$4b2o2bo2bo$bobo3b2o$b5o3bo$o5b3o$4bo2b3o$obo2b2obo2bo$2b2o$3bobo
2b2obo$4b2o4b2o$2bob2o3bobo$2b3obo3bo!

```

Try it online!

I wonder at what value of \\$n\\$ would engineered patterns appear. There are some cool engineered diehards at \\$n=32\\$ and \\$n\approx96\\$.
> 8 votes

# Answer
# \\$n=7, p=456\\$

I can't find a parent of Bubbler's answer. So instead, I found a grandparent of its child.

```
. . . . # . .
. # . . # . #
. # . # # . #
. . . # . # .
# . # . # # #
. # . . . . #
. . . . . . .

```

Or in RLE format:

```
x = 7, y = 7, rule = B3/S23
4bo$bo2bobo$bob2obo$3bobo$obob3o$bo4bo!

```

Try it online!
> 6 votes

# Answer
# \\$n = 10, p = 1353\\$

Search result from a simple script that runs for 1024 gens and then another 4 gens and checks that the bounding box is the same and population is different.

```
oo.....o..
.o.oo.o.o.
.oo.....o.
oo...o..oo
...o....oo
...ooo..o.
....o.o.o.
ooooo.o..o
..oo.ooo.o
ooo..o...o

```

RLE:

```
x = 10, y = 10, rule = B3/S23
2o5bo$bob2obobo$b2o5bo$2o3bo2b2o$3bo4b2o$3b3o2bo$4bobobo$5obo2bo$2b2ob
3obo$3o2bo3bo!

```

Try it online!

Also, it looks like it has no 10x10 predecessors, but it's possible I didn't set the search for that properly.
> 6 votes

# Answer
# \\$n = 2, p = 1\\$

This has board states \\$B\_0, B\_1, B\_2\\$ left-to-right below. This is the preloaded pattern.
> 5 votes

# Answer
# \\$n = 6, p = 455\\$

Found by spamming the random button for two hours. Interestingly, the active pattern converges to my own n=4 solution. This makes me suspect that only very few actual long-lasting patterns exist which result in a valid answer for this challenge.

```
...##.
.##..#
#..#..
###.#.
#.#..#
...#..

```

```
#C Generated by copy.sh/life
x = 6, y = 6, rule = B3/S23
3b2o$b2o2bo$o2bo$3obo$obo2bo$3bo!

```

View it live on copy.sh/life.
> 5 votes

# Answer
# \\$n=11, p=1697\\$

I did some soup search this time.

```
. O . O O O O O O . .
O . O . . . O O . . .
. O . O O O . . O O .
O . . . . . O . . . .
. . O O . . . O . . O
. . . O . O . O . . O
. O . . . O O . . O O
O O O O . O . O . . .
O O O O O . O . . O .
O O . O . . O . . O O
. O . O . . . . . O O

```

Or in RLE format:

```
x = 11, y = 11, rule = B3/S23
bob6o$obo3b2o$bob3o2b2o$o5bo$2b2o3bo2bo$3bobobo2bo$bo3b2o2b2o$4obobo$
5obo2bo$2obo2bo2b2o$bobo5b2o!

```

Try it online!
> 5 votes

# Answer
## *n*=3, *p*=2

```
. . . . .
. # . . .
. . . # .
. . # # .
. . . . .

```
> 4 votes

# Answer
# \\$n=13, p=2600\\$

```
. O O . . O . O O . . O O
O . O O . O . . . O O . .
. . O . O . . . O O . . .
O . . . O . . O . . . O .
O . O . O O . . . O . O .
O . O O . . . O . O O O .
O O . . O . O O . O O O O
. . . O . O O O O . . . .
. . . O O . . O O . O . .
. . . O . . . . O . . O O
. . . . O . . . . O . . .
. . O . O O . . O . O O O
. O . O O . O . . O O O O

```

Or in RLE format:

```
x = 13, y = 13, rule = B3/S23
b2o2bob2o2b2o$ob2obo3b2o$2bobo3b2o$o3bo2bo3bo$obob2o3bobo$ob2o3bob3o$
2o2bob2ob4o$3bob4o$3b2o2b2obo$3bo4bo2b2o$4bo4bo$2bob2o2bob3o$bob2obo2b
4o!

```

Try it online!
> 4 votes

# Answer
# \\$n = 4, p = 431\\$

```
.XXX
....
XX.X
.X.X

```

View it live on copy.sh/life.
> 3 votes

# Answer
# \\$n=8,p=901\\$

Another product of random search. The pattern this time is clearly different from the previous ones, and it *almost* fits in 7x7 board (the bottom left cell can be safely removed).

```
.#...#.#
.#.....#
.#..#.##
..#.....
.#....#.
.#..#.##
...#.#.#
#.....#.

```

```
#C Generated by copy.sh/life
x = 8, y = 8, rule = B3/S23
bo3bobo$bo5bo$bo2bob2o$2bo$bo4bo$bo2bob2o$3bobobo$o5bo!

```

View it live on copy.sh/life.
> 3 votes

# Answer
# \\$n=9, p=903\\$

A grandparent of Bubbler's answer.

```
O . O . O O . O .
O O O . O . O O .
. O . O O . . . .
O . . . . O . . .
. . O . . . . . .
. . . . O O O . .
O O O . O . . O .
O . O O O . O . O
. O . O O . . . .

```

Or in RLE format:

```
x = 9, y = 9, rule = B3/S23
obob2obo$3obob2o$bob2o$o4bo$2bo$4b3o$3obo2bo$ob3obobo$bob2o!

```

Try it online!

All these parents and grandparents are found using my Mathematica package, LifeFind. The code in the package isn't too complicated. You can try it on TIO.
> 3 votes

# Answer
# \\$n = 14, p = 3185\\$

Random soup battle continues.

```
. O . . O . . . O . O . O O
O O . . . O O . . . . . O .
. O O O . . O . . . O . . .
. O O O O O . . . O O O O O
. O O O . . O O . . O O . O
. O O O O . O O O O . . . .
O . . . O O O O O O . . O .
. O . . . O O O . O . O O .
O . . O . . . . . . . . . O
. . . . . O . . O . . . . O
. . O . . . . O O O . . O O
. . O O O . O O . . . . O O
. . . . . . . O . O . O . .
. . . O . . . O O O . . . .

```

RLE:

```
x = 14, y = 14, rule = B3/S23
bo2bo3bobob2o$2o3b2o5bo$b3o2bo3bo$b5o3b5o$b3o2b2o2b2obo$b4ob4o$o3b6o2b
o$bo3b3obob2o$o2bo9bo$5bo2bo4bo$2bo4b3o2b2o$2b3ob2o4b2o$7bobobo$3bo3b
3o!

```

Try it online!
> 3 votes

# Answer
# \\$n = 18, p = 5231\\$

Just one more random soup. 18x18 is better, but still too tight for engineered designs I tried.

```
. . . O . O O . O O . . O . . O O O
O . O O O . . . O O O . . . . . . O
. . . . O . O . . O . . O . . . . .
. . O . O O O . . O . O . O O . . .
O O O O O . . O . O . O O . O O O O
. . . . O . O O . . . . . . . O . .
. O . . . . . . . O . . O O O O O O
O O . . . O . . . O O O . . . O . .
O . O . O O . . . O O . . . . . . O
. . . O . . O . O . . . O . . . O O
O . O O O O O O . O O . O . . . . .
O . . . . . . . . . O O O O O . . .
. O O O . . . O O . . . . . . O . .
. . O O . O . . O O . O O . . . O .
. . O O . . O O O O . . . O . . . .
. O . . O O . . . . O . . O . O O O
. . . O . . . O . . O O O . . O O O
. . O . . . O O . . O . O . . . . .

```

RLE:

```
x = 18, y = 18, rule = B3/S23
3bob2ob2o2bo2b3o$ob3o3b3o6bo$4bobo2bo2bo$2bob3o2bobob2o$5o2bobob2ob4o$
4bob2o7bo$bo7bo2b6o$2o3bo3b3o3bo$obob2o3b2o6bo$3bo2bobo3bo3b2o$ob6ob2o
bo$o9b5o$b3o3b2o6bo$2b2obo2b2ob2o3bo$2b2o2b4o3bo$bo2b2o4bo2bob3o$3bo3b
o2b3o2b3o$2bo3b2o2bobo!

```

Try it online!
> 3 votes

# Answer
# \\$n=5,p=432\\$

A parent of Bubbler's answer.

```
.XX..
.XX.X
XX.X.
.....
..XX.

```

Or in RLE format:

```
x = 5, y = 5, rule = B3/S23
b2o$b2obo$2obo2$2b2o!

```

Try it online!
> 2 votes

# Answer
# \\$n = 16, p = 3456\\$

I've tried a few of engineered designs for that size, but they all were not as good as a random soup.

```
. . . O O . O . O . O O . O . .
. O . O O . . . . . . O O . O .
O O O O . . O O . . . . . O . .
. . O O . O O . . . . . . . . O
O O . . . . O . . O . O . . O .
O . . O . . O . O . O . O O . O
. O . . . O . . . . . . . . . O
O O . . . . . . O O O . . . O .
. . . . . O O O O . . O O . O O
O O O O O O . . . . . . O . O O
. . . O O . . . O . O O . . O O
O O O O O O O O . . . . . O . O
O . . . . . . . O . O . . . . .
. . . . . O . . . O . O . O . O
. . O . O . . O . O . O . . . .
O O . . O O . O . . O . . O . .

```

RLE:

```
x = 16, y = 16, rule = B3/S23
3b2obobob2obo$bob2o6b2obo$4o2b2o5bo$2b2ob2o8bo$2o4bo2bobo2bo$o2bo2bobo
bob2obo$bo3bo9bo$2o6b3o3bo$5b4o2b2ob2o$6o6bob2o$3b2o3bob2o2b2o$8o5bobo
$o7bobo$5bo3bobobobo$2bobo2bobobo$2o2b2obo2bo2bo!

```

Try it online!
> 2 votes

# Answer
# \\$n=17, p=3696\\$

```
O . O O . O . . O . . . O O O . .
. . . O . . . . O O O . O . O O O
. . . . O . O . O . . O . O . . O
. . . . O . . O O . . . O . O O .
O O . O O . . . . O . . O . . O .
O O O . O . . O O . O O O . O O .
. O O . . O . . . O O O O . O . .
O O O O . . O . O O . O O . O . .
. . . . O O O . O O . . O O O O O
O O O . . . . . O O O O . . . . .
O O O O O O O . O . O O . O O . O
O . O . . O . . O O . . . . O . O
O . O O O O O . . O . . . O O O .
. O O . . O . O O . . . O . O . .
O O . . O O . . . . . O O O . . .
O . . . O . . . . . O . O O . . .
. O . . O . . . . O O . O O O . O

```

```
x = 17, y = 17, rule = B3/S23
ob2obo2bo3b3o$3bo4b3obob3o$4bobobo2bobo2bo$4bo2b2o3bob2o$2ob2o4bo2bo2b
o$3obo2b2ob3ob2o$b2o2bo3b4obo$4o2bob2ob2obo$4b3ob2o2b5o$3o5b4o$7obob2o
b2obo$obo2bo2b2o4bobo$ob5o2bo3b3o$b2o2bob2o3bobo$2o2b2o5b3o$o3bo5bob2o
$bo2bo4b2ob3obo!

```

Try it online!
> 2 votes

# Answer
# \\$n = 20, p = 5627\\$

I've tried random symmetric soups this time. Still can't fit engineered solutions into such small a space. This pattern is a 2-generation predecessor of a (variant of a) symmetric pattern found by search.

```
. . O . . . O . . . . . . O . . O . O .
. . . . O O . . O O . O O O . . . . O .
. O O . O . O O O O . . . O . O . O . .
O . . . . . O . O . . O . O . O . . . O
O . O . O . . . . . O . . . . . O O . O
. . O . . . . O O . . O O . O . O . . .
O O . O . O . . . O . O O . O O . O . O
. O O . . O . . O O O O . . O . . O O O
. O O . . . . O . O . . . O . O . . . .
. O . . . O . . O O O . . O . . . O . .
. . . O O . O . O . . O . . O O O O . O
O . . O O . . . . O . . . . O . . . . .
. . . . . O O . . O . O . O O O . . . .
O . O . O O . . O O O . . . . . . O O .
. . . O . O . O O . O . O . . O . . . O
O . O O . . O . . O . . . . . O O . . O
O . . . O . . . O . . O . . O O . . . .
. . O . O . O . . . O O O O . O . O O O
. O . . . . O O O . O O . . O . . . . .
. O . O . . O . . . . . . O . O . O . O

```

RLE:

```
x = 20, y = 20, rule = B3/S23
2bo3bo6bo2bobo$4b2o2b2ob3o4bo$b2obob4o3bobobo$o5bobo2bobobo3bo$obobo5b
o5b2obo$2bo4b2o2b2obobo$2obobo3bob2ob2obobo$b2o2bo2b4o2bo2b3o$b2o4bobo
3bobo$bo3bo2b3o2bo3bo$3b2obobo2bo2b4obo$o2b2o4bo4bo$5b2o2bobob3o$obob
2o2b3o6b2o$3bobob2obobo2bo3bo$ob2o2bo2bo5b2o2bo$o3bo3bo2bo2b2o$2bobobo
3b4obob3o$bo4b3ob2o2bo$bobo2bo6bobobobo!

```

Try it online!
> 2 votes

# Answer
# \\$n=15, p=3239\\$

```
O . O O . . . . . . O O . . .
. O O . . . O . . O . . . . .
. O O . O . O O . . . . . O O
O O . O . . . . . O . . . O O
O . . . O . O O O . O . . O .
. . O O O O . O O O . . O . O
O O . O . O . O O O O . O O .
O O O O O O O . . . O . . . .
O . . O . O . O . . . O O O .
O O . . . . . O . . . . O . .
. . O O . O . . . O O . . . O
O O O . O O . O . . . O O O O
O . O O O . O . . O O . . O O
. . O . . O . . O O . O . O .
. O . . . O O O O . O . . . .

```

```
x = 15, y = 15, rule = B3/S23
ob2o6b2o$b2o3bo2bo$b2obob2o5b2o$2obo5bo3b2o$o3bob3obo2bo$2b4ob3o2bobo$
2obobob4ob2o$7o3bo$o2bobobo3b3o$2o5bo4bo$2b2obo3b2o3bo$3ob2obo3b4o$ob
3obo2b2o2b2o$2bo2bo2b2obobo$bo3b4obo!

```

Try it online!
> 1 votes

# Answer
# \\$n=19, p=5232\\$

A grandparent of the child of Pavgran's answer.

```
. . . . . O . . . . . O O . O . . . .
O . O O . . . . . O . . . . . O O . O
. . . . O O . O O . . O O . O O . O .
O O . . . . . . . O . . . . O O . . .
. . . . . O O . . O O O . . O . . . O
O O O . O O . . . . . O . . . O . . .
. O . . O . O . O . . O . . . O . O .
. O . . O . . . O . . . . . O . . O .
O O . O O O . O O . O . O . O . . O O
. . O . O . . . O . O O O . . . O O .
O . . . . . . . O . O O O O . . . . O
O . O . . . O O . O . . O . . O . O .
. O . O O O . O . . . . . . O O O . .
. . O O . O O O . . O O . O . . O . O
O . . . . O . . O . . . . . . O O . .
. . . O . . O O O . . . O . . . O . .
O . O O O O . . . . O . . O O O O . O
. . . . . . . O O O O O . O . O . . .
O . . . O O . O O . . . . . . . . . O

```

```
x = 19, y = 19, rule = B3/S23
5bo5b2obo$ob2o5bo5b2obo$4b2ob2o2b2ob2obo$2o7bo4b2o$5b2o2b3o2bo3bo$3ob
2o5bo3bo$bo2bobobo2bo3bobo$bo2bo3bo5bo2bo$2ob3ob2obobobo2b2o$2bobo3bob
3o3b2o$o7bob4o4bo$obo3b2obo2bo2bobo$bob3obo6b3o$2b2ob3o2b2obo2bobo$o4b
o2bo6b2o$3bo2b3o3bo3bo$ob4o4bo2b4obo$7b5obobo$o3b2ob2o9bo!

```

Try it online!
> 1 votes

# Answer
# \\$n=21, p=5744\\$

```
O . . . . . . . . . O . O . O . . . O . O
. . . . O . . . . . . . O . O O . . . . .
O . O . . . . . . O O . . . O O . O O . .
. . O . . . O O . . O . . . . O . . . . .
. . . . . . O . . . O . O . . . . . . O .
. O O O . . . . . . O . . . . . . . . . .
O O O . . . . . . O O . . O . . O O . . .
. . . . . . O O . . O . O O . . . O . . .
O O . . O . . O . . . O . . . . . . . . .
. . . . . . . . O O O O . . O . . . O . .
O . O O O O O O . O O O . O O O O O O . O
. . O . . . O . . O O O O . . . . . . . .
. . . . . . . . . O . . . O . . O . . O O
. . . O . . . O O . O . . O O . . . . . .
. . . O O . . O . . O O . . . . . . O O O
. . . . . . . . . . O . . . . . . O O O .
. O . . . . . . O . O . . . O . . . . . .
. . . . . O . . . . O . . O O . . . O . .
. . O O . O O . . . O O . . . . . . O . O
. . . . . O O . O . . . . . . . O . . . .
O . O . . . O . O . O . . . . . . . . . O

```

```
x = 21, y = 21, rule = B3/S23
o9bobobo3bobo$4bo7bob2o$obo6b2o3b2ob2o$2bo3b2o2bo4bo$6bo3bobo6bo$b3o6b
o$3o6b2o2bo2b2o$6b2o2bob2o3bo$2o2bo2bo3bo$8b4o2bo3bo$ob6ob3ob6obo$2bo
3bo2b4o$9bo3bo2bo2b2o$3bo3b2obo2b2o$3b2o2bo2b2o6b3o$10bo6b3o$bo6bobo3b
o$5bo4bo2b2o3bo$2b2ob2o3b2o6bobo$5b2obo7bo$obo3bobobo9bo!

```

Try it online!
> 0 votes

---
Tags: cellular-automata, answer-chaining, busy-beaver, game-of-life
---


title: Is it a lobster number?

text:
# Question
Title: Is it a lobster number?
## Introduction

A "lobster number", by my own designation, is a number that contains within itself all of its prime factors. The "lobster" description was inspired by the recent question "Speed of Lobsters". The basic idea is that each prime factor can be made by lobsters munching away digits of the number until you are left with just the factor.

Example: `51375` is a lobster number, since its prime factors are `[3,5,137]`, which can be made by lobsters thusly: `[**3**, 5**** / ****5, *137*]`. Another lobster number is `62379`, as the factors `[3,29,239]` can be formed as `[**3**,*2**9,*23*9]`.

## Challenge

Given a number as input, return whether it is a lobster number or not. Preferentially this is a boolean output, such as 1 or 0, or True or False.

Astute readers may realize that prime numbers are a trivial solution to this requirement, but since they don't allow the lobsters to eat any digits, they are out. Your program must not identify prime numbers as lobster numbers.

This is similar to OEIS A035140, but has the additional requirement that each digit of the factor must appear at least the same number of times in the number, and in the correct order. In other words, `132` is not a lobster number, since its factors are `[2,3,11]`, and the `11` cannot be made by munching away at just `132`. `312` is also not a lobster number, because its factors are `[2,3,13]`, and `13` is out of order.

I believe the "mathematical" definition would be: "Determine if the number n is a composite number such that all prime factors of n are a subsequence of n".

## Test Cases

```
59177  -> True
62379  -> True
7      -> False
121    -> True
187    -> False
312    -> False

```

As always, Standard Loopholes are forbidden.

## Note:

It has come to my attention that the original reasoning I gave for not needing to handle 0 or 1 as input is faulty. However, requiring the proper output at this point would invalidate a number of answers. Therefore, let it hereby be known that neither 0 nor 1 are lobster numbers, but you also do not need to handle them as input (they are not valid test cases). If your code does handle them correctly, you may give yourself the Lobster Advocate Badge™.

# Answer
# Python 3, ~~155~~, ~~126~~, ~~124~~, ~~123~~, ~~120~~ ~~116~~, 113 bytes

Yes! First python answer!

Saved **21 bytes** due to a suggestion by Dominic van Essen to remove the `for` loop!

Saved **8 bytes** because I realized I could use `t*=True/False` instead of `t+=[True/False]`.

Saved another **2 bytes** right after I finished editing because I realized `t` could simply be set to the same value as `i` and `l`!

Saved **1 byte** based off Danis's python 2 comment.

Saved another **3 bytes** based off Tipping Octopus's comment.

Saved another **4 bytes** due to Tipping Octopus again!

Saved another **3 bytes** thanks to Dominic's suggestion to remove the `t` variable.

# New Answer

```
x=input()
n=int(x)
i=l=2
while~-n:
 if n%i:i+=1
 else:n//=i;l+=1;j=iter(x);l*=2*all(c in j for c in str(i))
print(l>4)

```

# How it works

The `while` loop computes the prime factors of the input. If a prime factor is found, it checks if it is a subsequence of the input. `l` is multiplied by whether or not this is `True`. This takes advantage of the fact that python's `True` and `False` values act like 1s and 0s when you multiply by them. This means that instead of appending `True/False` to `t` and checking whether `all(t)` is `True` like in my old answer, I can just multiply `l` by `2*True/False` and check its value in the `print` statement. The `print` statement prints `True` if `l>4`.

Try it online!

# Old Answer

```
x=n=int(input())
l=[]
i=2
while i<=n:
 if n%i:i+=1
 else:n/=i;l+=[i]
t=[]
for p in l:i=iter(str(x));t+=[all(c in i for c in str(p))]
print(all(t)*len(l)>1)

```

Try it online!
> 16 votes

# Answer
# Brachylog, 5 bytes

That's basically this: "Determine if the number n is a composite number such that all prime factors of n are a subsequence of n".

```
ḋṀ⊆ᵛ?

```

Try it online!

```
ḋṀ⊆ᵛ? (with implicit input n)
ḋ     get the prime factors of n
 Ṁ    they must be Ṁany (at least 2 to filter out primes)
  ⊆ᵛ  all of them must be an (ordered) subset of
    ? the input

```
> 13 votes

# Answer
# Zsh `-e -o glob_subst -o extended_glob`, ~~40~~ 38 bytes

```
>$1:
for i (`factor $1`)>${i///*}*~$i:

```

Try it online!

Outputs via exit code: `0` is a lobster number, `1` is not a lobster number

Explanation:

* `>` \- do nothing, and send the output to:
    + `$1:` \- the input with a `:` appended (e.g. `51375:`). This is because `factor` outputs the input number itself, then a colon, then its factors, and we need to match based on that later.
* `factor $1` \- factorise the input (in the format `51375: 3 5 137`)
* `for i` \- for each element in the factorisation:
    + `${i}` \- take that element
    + `///*` \- prefix each character with a `*` (e.g. `*1*3*7`)
    + append `*~` \+ the input + `:`
    + `>`, `-o glob_subst` \- do nothing, and try to output to a file matching that pattern (there is only one file in the directory, the one we created earlier):
        - at this point the pattern is something like `*1*3*7*~51375:`
        - `*` \- match zero or more characters; so `*1*3*7*` tests for a subsequence.
        - `~`, `-o extended_glob` \- the file must match `*1*3*7*` but *not* `51375:` itself - this is to prevent prime numbers from being matched.
    + `-e` \- exit immediately if there is an error (no files match that pattern) and set the exit code to `1`. If all factors matched a file, there is no error and the exit code is `0`.
> 10 votes

# Answer
# 05AB1E, ~~9~~ 6 bytes

```
æ¨IfåP

```

Try it online! or Try all cases!

**Commented:**

```
æ          # get the powerset / all subsequences of the input
 ¨         # remove the last one (the input itself)
  If       # get all prime factors of the input
    å      # is each prime factor in the powerset?
     P     # take the product

```
> 8 votes

# Answer
# Husk, ~~13~~ ~~10~~ 9 bytes

*(`Πm` -\> `Λ` simultaneously golfed-down by Razetime!)*

```
Λo€hṖd¹dp

```

Try it online!

Returns `0` (falsy) for non-lobster numbers, and a positive nonzero integer (truthy) for lobster numbers.

**How?**

```
Λo       p    # is this true for each prime factor of input:
   €          # index (or zero if absent) of
        d     # its digits among
    hṖ        # all subsets (in order, without full set) of
      d¹      # digits of input

```
> 7 votes

# Answer
# Python 2, 93 bytes

Outputs via exit code: `0` if it is a Lobster number, `1` otherwise.

```
n=m=input()
i=1
while~-m:
 i+=1
 while m%i<1:m/=reduce(lambda s,c:s[c==s[:1]:],`n`,`i`)or i%n

```

Try it online!

The algorithm for determining subsequences was borrowed from @xnor's answer to Is string X a subsequence of string Y?. A `TypeError` is raised when the subsequence check fails, and the `i%n` causes a `ZeroDivisionError` to occur on prime inputs.

### Python 2, 92 bytes

One byte can be saved using `exec`, at the cost of segfaulting on large inputs.

```
n=m=input()
i=1
exec"i+=1\nwhile m%i<1:m/=reduce(lambda s,c:s[c==s[:1]:],`n`,`i`)or i%n\n"*n

```

Try it online!
> 5 votes

# Answer
# Jelly, 10 bytes

```
DŒPḌḟiⱮÆfẠ

```

Try it online!

## How it works

```
DŒPḌḟiⱮÆfẠ - Main link. Takes an integer n on the left
D          - Digits of n
 ŒP        - Powerset of the digits
   Ḍ       - Convert back to integers
    ḟ      - Remove n from this list
       Æf  - Yield the prime factors of n
      Ɱ    - Over each prime factor:
     i     -   Index of the factor in the powerset, or 0
         Ạ - All are true?

```
> 3 votes

# Answer
# Husk, 11 bytes

*I got ninja'd..*

```
§&tΛo€Ṗd¹dp

```

Try it online!

Outputs truthy for a lobster number and falsy otherwise. This would be shorter if `all` returned 0 for empty lists.

## Explanation

```
§&tΛo€Ṗd¹dp
          p prime factorization of the input
§           fork:
  t          is the list not composed of a single element?
 &          and,
   Λo    d   are all the prime factors' digits
     €       present in
      Ṗd¹    the powerset of the input's digits?

```
> 3 votes

# Answer
# Haskell, ~~135~~ 128 bytes

Saved 7 bytes thanks to @ovs!

```
f n=all(\x->x/=n&&(show n%show x))$foldl(\f x->[x|all((>0).mod x)f&&mod n x<1]++f)[][2..n]
(a:b)%(c:d)=b%([c|a/=c]++d)
_%x=x==[]

```

Try it online!
> 3 votes

# Answer
# Pyth, ~~12~~ 15 bytes

```
&!P_Q.A}Ry`Q`MP

```

Try it online!

*-2 bytes by using ``` instead of `+k`, +5 to account for primes needing to return false.*
> 3 votes

# Answer
# Retina 0.8.2, 95 bytes

```
.+
$*_¶$&
%O^$`.

+`^(__+?)(\1)*¶
$#2$*__¶$.1¶
_¶((.)+¶(?=(.+¶)*((?<-2>\2)|.)+$(?(2).))){2,}.+$

```

Try it online! Link includes test cases. Explanation:

```
.+
$*_¶$&

```

Duplicate the input, converting one copy to unary.

```
%O^$`.

```

Reverse both copies. (Reversing the unary copy has no effect, of course, other than being golfier.) Reversing the input allows it to be used for nondestructive subsequence matching (a simple subsequence matching Retina program works by destroying both strings on success).

```
+`^(__+?)(\1)*¶
$#2$*__¶$.1¶

```

Repeatedly extract the smallest proper (and therefore necessarily prime) factor of the unary input, until it is reduced to 1.

```
_¶((.)+¶(?=(.+¶)*((?<-2>\2)|.)+$(?(2).))){2,}.+$

```

Attempt to match the unary 1, followed by at least 2 factors, each of which can be matched against the reversed input by popping its previously captured characters as they are seen, followed by the reversed input.
> 3 votes

# Answer
# , 27 bytes

```
1<[:*/](]#.@E.[-.-.)&":"+q:

```

Try it online!

Takes list of prime factors `q:` and original input, and for each pair, formats each as a string `&":"+` and then applies the following verb in parens: `]#.@E.[-.-.`

This verb set subtracts the factor digits from the input digits `-.` (leaving digits *not* in the factor) and then subtracts those from the input digits `[-.`, leaving only input digits that *are* in factor, with order preserved.

We then check if the factor is a substring match of that `E.`, which returns a boolean list of length input, with a 1 at any index where a match begins. Finally we interpret that as a base 2 number and convert to an integer `#.@`. This means that for a true result we need *all* factors to be greater than or equal to 1, and at least 1 factor to be greater than 1.

So we multiply all the results together `[:*/` and check if that is greater than 1 `1<`.
> 3 votes

# Answer
# Wolfram Language, 118 bytes

```
i|->Catch@AllTrue[MemberQ[a=FactorInteger@i,{i,_}]&&Throw@False;a,LongestCommonSequence@##==#&@@ToString/@{#[[1]],i}&]

```

Try it online!

Pure function; uses the `|->` syntax, which is new in version 12.2. TIO is running version 12.0, so I've used Function FullForm there.

Test cases:

```
59177: expected True, got True
62379: expected True, got True
7: expected False, got False
121: expected True, got True
187: expected False, got False
312: expected False, got False

```
> 3 votes

# Answer
# Python 2, 137 bytes

```
lambda n:(p(n)<1)*all(re.search('.*'.join(`d`),`n`)for d in range(2,n)if n%d<1and p(d))
p=lambda n:all(n%i for i in range(2,n))
import re

```

Try it online!
> 2 votes

# Answer
# JavaScript (ES6),  ~~80~~  79 bytes

Expects a string.

```
f=(n,m=n,k=2)=>n%k?k>n||f(n,m,k+1):m-k&&m.match([...k+''].join`.*`)&&f(n/k,m,k)

```

Try it online!

### Commented

```
f = (              // f is a recursive function taking:
  n,               //   n = initially the input as a string,
                   //       then an integer
  m = n,           //   m = copy of the input
  k = 2            //   k = current divisor candidate
) =>               //
  n % k ?          // if k is not a divisor of n:
    k > n ||       //   stop the recursion if k > n
    f(n, m, k + 1) //   otherwise: do a recursive call with k + 1
  :                // else:
    m - k &&       //   if k is not equal to m
    m.match(       //   and we can find in m:
      [...k + '']  //     the digits of k in the correct order
      .join`.*`    //     possibly with other digits in between
    ) &&           //   then:
    f(n / k, m, k) //     do a recursive call with n / k

```
> 2 votes

# Answer
# C (gcc), ~~264~~ ~~236~~ 219 bytes

-45 bytes thanks to ceilingcat!

```
i,j,k,b,n,r,z;char p[9],c[6];l(int*s){b=1;for(j=k=!strcpy(c,s);p[j]*b;j++)for(b=0;c[k]&&(c[k]==p[j]?c[k]=5,b=1,0:1);k++);b=b;}f(int*s){r=1;n=z=atoi(s);for(i=2;n>1;i++)for(;sprintf(p,"%d",i),n%i<1;n/=i)r&=i-z&&l(s);b=r;}

```

Try it online!

But it's a shame that C needs all those bytes. I believe that a better approach could be found, so here is an ungolfed and highly commented version that you can use to get yourself into the problem and hopefully develop something better.

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// indexes
int i,j,k;

// int copy of the input s, used to find prime factors
int n;

// array to store char* copy of the prime factors of n
char p[20];

// bool telling whether a particular digit of p
// has been successfully "lobsted" in s
int b;

// checks whether a given factor p "lobsters" s
int l(char*s)
{
    // just copy of s, so that we can preserve the input
    // to check whether the next factors "lobster" it or not
    char c[6];

    strcpy(c,s);

    // we don't do it at the start of the k-loop
    // because we want to continue the loop from
    // where we left it. 31 do not "lobster" 12345.
    // After checking for 3, we don't check for 1 from the beginning
    k = 0;

    // until p has digits to check for lobsterness
    for(j=0;p[j];j++) {

        // assume the digit can't be lobsted in c
        b = 0;

        // untill c has digit that could potentially
        // "lobster" the digit of p
        for(;c[k];k++) {

            // if the digit of p double equals one of the digits of c
            if(p[j]==c[k]) {

                c[k] = '*'; // delete the digit of c
                b = 1; // set "lobsted" to true
                break;
            }
        }

        // if a digit couldn't be lobsted
        if(!b) break;
    }

    // return 0 if at least one digit couldn't be lobsted,
    // return 1 if all of them were sucessfully lobsted
    return b;
}

// find factors of s and launch l() for each factor found
int f(char*s)
{
    // n is, initially, the int copy of the input
    n = atoi(s);

    // until a factor can be found in n
    for(i=2;n>1;i++) {

        // if i is a factor of n
        if( !(n%i) ) {

            // if the first factor found is the original number
            if(i==atoi(s)) return 0;

            // until i divides n, divide n by i
            for(;!(n%i);n/=i);

            // make a char[] copy of the factor i, named p
            sprintf(p,"%d",i);

            // if p doesn't "lobster" s
            if(!l(s)) return 0;
        }
    }

    // reachable only if each factor p "lobsted" the original number s
    return 1;
}

int main() {

    char test[6][6] = {
        "59177",
        "62379",
        "7",
        "121",
        "187",
        "312" };

    for(int t = 0; t < 6; t++) {

        printf("%s", test[t]);

        for(int dots = 0; dots < 8-strlen(test[t]); dots++) {

            printf(".");
        }

        printf("%d\n\n", f(test[t]));

        memset(p,0,20);
    }

    return 0;
}

```

And in case you want to golf from here, rather than start a new approach, here is the same code without comments
> 2 votes

# Answer
# PowerShell Core, 126 bytes

```
param($n)(($u=2..($n-1)|?{!($n%($a=$_)-or(2..($a-1)|?{!($a%$_)}))})|?{$n-match(("$_"|% t*y)-join'.*')}).Count-eq$u.count-and$u

```

Try it online!

Takes an integer and returns a boolean

```
($u=2..($n-1)|?{!($n%($a=$_)        # finds the factors of the input
-or(2..($a-1)|?{!($a%$_)}))})       # keep them only if they are prime
|?{$n-match(("$_"|% t*y)-join'.*')} # add a .* between each digits of each prime factors and check if they match the input
.Count-eq$u.count-and$u             # Check that the input has factors and that they all match the input

```
> 1 votes

---
Tags: code-golf, decision-problem, number-theory
---


title: Indexable quine

text:
# Question
Title: Indexable quine
The goal of this challenge is to make a program that outputs the nth letter of its source code where n is given as input to the program. Like most quine challenges, you are not allowed to read your source code as a file or use any builtin quine functions.

## Input

An integer 0 \<= n \< len(program).

## Output

The nth character (not byte) of your program.

## Winning

Like most codegolf questions, you win the challenge by using the lowest number of bytes to solve the challenge.

## Bonuses

-5% If your program supports negative indices python style (e.g. -1 would be the last character of your program). If used with the below bonus, your ranges must support negative indices.
-20% If your program supports ranges as input (any format) in addition to the above requirements.
-25% If your program complete both bonuses.

## Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
# Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
# Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
# Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the leaderboard snippet:

```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=70727,OVERRIDE_USER=32700;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d\.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
# Pyth, 0.75 bytes

(Also happens to be a CJam polyglot, and probably many other languages.)

```
0

```

Expects input on STDIN:

```
llama@llama:~$ echo 0..0 | pyth -c '0'
0

```

Any single digit works, of course. Not exactly the most interesting challenge in Pyth.
> 13 votes

# Answer
# Javascript ES6, 31 bytes

```
$=_=>`$=${$};$()`[prompt()];$()

```

# Explanation

The standard quine framework:

```
$=_=>`$=${$};$()`;$()

```

`[prompt()]`, which is the addon, gets the value at the input index of the resulting quine string.
> 8 votes

# Answer
# , 9 chars / 19 bytes

```
⟮ɕṡ+ᶈ0)⎖ï

```

`Try it here (Firefox only).`

*Ay, 19th byte!*

`0` works too (and is much better), but it's way too trivial for my liking.

In addition, `ℹ ï,⧺ï` would also work, but quine functions aren't allowed.

## Explanation

The standard quine framework is `⟮ɕṡ+ᶈ0`.

`)⎖ï` takes the resulting quine string and gets the character at the input index.

---

# Bonus solution, 11.4 chars / 25.65 bytes

```
⟮ᵖ…ɕṡ+ᶈ0;ôᵍï

```

`Try it here (Firefox only).`

This one qualifies for the 5% bonus, but still does not beat my original submission.

## Explanation

This one uses the stack. `ᵖ…ɕṡ+ᶈ0;` just pushes the quine string's individual characters to the stack, and `ôᵍï` directly outputs the character at the input index (positive or negative) in the stack.
> 6 votes

# Answer
# CJam, 12.35 bytes

```
{s"_~"+ri=}_~

```

The program is **13 bytes** long and qualifies for the **× 0.95** bonus. Try it online!

### How it works

```
{         }      Define a code block.
           _~    Push a copy and execute the copy.
 s               Cast the original code block to string.
  "_~"+          Append "_~".
       ri        Read an integer from STDIN.
         =       Retrieve the character at that index.

```
> 5 votes

# Answer
# Polyglot, 0 bytes

```

```

Try It Online! (you'll have to select a language yourself)

The challenge specifies taking an integer \\$ 0 \le n \lt \text{len}(\text{program}) \\$, but with a 0-byte program there is no integer that is both ≥ 0 and \< 0. This means the program can do whatever it wants.

When I say polyglot, I mean that it works in any language whatsoever.
> 5 votes

# Answer
# Ruby, 53 * 0.75 = 39.75

```
$><<(<<2*2+?2)[eval gets]
$><<(<<2*2+?2)[eval gets]
2

```

Generates a HEREDOC string delimited by a `2` on its own line, concatenates it (`*2`) and then adds in the final `2` via a character literal. Slices into it using Ruby's built in `String#[]`, which supports positive integers, negative integers, and ranges (input in the form `m..n`). `$><<` is output. (`puts` would require an extra space here).
> 4 votes

# Answer
# Ruby, 38.25 bytes

```
a="a=%p;$><<(a%%a)[eval gets]";$><<(a%a)[eval gets]

```

Support negative indices and ranges. I blatantly picked up both `$><<` and the `eval` trick from histocrat, and the quine trick was someone else's to begin with, so I'll make this CW.
> 3 votes

# Answer
# Japt, ~~11~~ 2 bytes

All of the following use 0-based, modular indexing and support negative indexing.

```
gg

```

Try it

```
gg     :Implicit input of integer
g      :Index into
 g     :Literal "g"

```

## Original, 11 bytes

Based on one of ETH's standard Japt quines.

```
gBîQi"gBîQi

```

Try it (Includes full test suite)

```
gBîQi"gBîQi     :Implicit input of integer
g               :Index into
 B              :  11
  î             :  Repeat to length B
   Q            :    Quotation mark
    i           :    Prepend
     "gBîQi     :      String literal

```

### Array input, 13 bytes

Same as above with the `m` at the start being `map` and the `D` being `13`, in place of `11`.

```
mgDîQi"mgDîQi

```

Try it
> 3 votes

# Answer
# RProgN 2, 6 bytes

```
«•.\ü

```

Includes a trailing space.

## Explaination

```
«•.\ü
«      # Push the remainer of the code as a function and continue execution
 •.    # Append a space to the end of the function as a string
   \   # Swap the string under the input value
    ü  # Get the character at that index
       # A trailing space is included to ensure quine validity.

```

Try it online!
> 2 votes

# Answer
# Python 2, 46.55 bytes

```
a="a=%r;print(a%%a)[input()]";print(a%a)[input()]

```

Supports negative indices.
> 1 votes

# Answer
# Haskell, 122 bytes

```
main=getLine>>= \i->putChar$(!!(read i))$p++show p where p="main=getLine>>= \\i->putChar$(!!(read i))$p++show p where p="

```

Ungolfed:

```
main=getLine>>= \i->putChar$(!!(read i))$p++show p
 where p="main=getLine>>= \\i->putChar$(!!(read i))$p++show p\n where p="

```
> 1 votes

# Answer
## Befunge 93, 5 bytes

This is pretty (very) late but I'll post it anyway:

```
&0g,@

```
> 1 votes

# Answer
# Thunno, \\$ 32 \log\_{256}(96) \approx \\$ 26.34 * 0.75 \\$ \approx \\$ 19.75 bytes

```
"D34CXx+xs+s+sAI"D34CXx+xs+s+sAI

```

Attempt This Online!

Based on *@lyxal*'s Thunno quine. Supports negative indices and ranges.
> 1 votes

---
Tags: code-golf, quine
---


title: Print Real Invisible Text

text:
# Question
Title: Print Real Invisible Text
My previous challenge, Print invisible text was quite popular, likely due to how trivial it is.

However those more observant of you may have noticed that you're not really printing invisible text, because it's impossible to read what was inputted given only the output.

So I figured how about a *real* invisible text challenge.

Given a string consisting of only printable ASCII characters (`0x20-0x7E`), convert each character to a distinct Unicode character (in UTF-8 encoding) that is not one of the 95 printable ASCII characters (any UTF-8 character outside of the `0x20-0x7E` range)

## Input

A string of printable ASCII characters, either as a string or character array/list

## Output

The input string with each character replaced with a distinct non-printable character. Each given character must have a corresponding non-printable character that is not used as the substitute for any other character.

If you are unable to print non-printable characters, you can output the character values instead.

For example if your code replaces all lowercase `a`'s with `0x01`, you may not use `0x01` as the substitution for any other characters.

Your code must also be **deterministic**. This means that if, given the string `Hello`, all lowercase `l`'s are replaced with `0x03`, your code must also replace all lowercase `l`'s with `0x03` given any other string.

### Testcases

It's somewhat difficult to write testcases for this challenge, so I'll simply show the output as a list of hexcodes

```
input     -> output
"Hello"   -> [0x01, 0x02, 0x03, 0x03, 0x04]
"Hi!"     -> [0x01, 0x05, 0x06]
""        -> []
"   H   " -> [0x07, 0x07, 0x07, 0x01, 0x07, 0x07, 0x07]
"yo! "    -> [0x08, 0x04, 0x06, 0x07]

```

## Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

```
/* Configuration */

var QUESTION_ID = 123447; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();

    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
```

```
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
```

# Answer
# Whitespace, ~~39~~ 36 bytes

```

```

Try it online!

## Explanation

```
nssn  ; label 'loop'
ssstssn ; push 4 to use as a multiplication operand
sns   ; dup 4 to use as a heap address
sns   ; dup 4 to use as a heap address
tnts  ; getchar and store at address 4
ttt   ; retrieve the value at address 4
tssn  ; multiply the character value by 4
tnss  ; putchar output the new character
nsnn  ; jmp 'loop'

```

Originally I wanted to multiply by -0 or -1 since they would be the shortest digits possible to declare in Whitespace. TIO does not differentiate between -0 and +0 so that's out. Unfortunately while the tutorial/spec is ambiguous about how to interpret a negative value as a char TIO (rightly) throws an error about the invalid argument so that also isn't an option.

The next shortest working constant is 4 so we end up performing the same basic approach as the Powershell/Pyth solutions.

---

# Whitespace, ~~56~~ 53 bytes - maps to tag characters

```

```

Try it online!

## Explanation

Effectively the same approach as the previous version except this uses 0xE0000 as the constant and adds instead of multiplies. This maps the visible ASCII characters to the corresponding Unicode Tag Character (the range U+E0000-U+E007F). The intended use for this range was to indicate the language of the text in a plaintext file however that use is discouraged. This code will output valid labels if you prefix strings with a 0x01 character.

The Unicode Standard says that characters in this range have no visible rendering so I feel this meets the spirit of the challenge better than the previous approach.
> 16 votes

# Answer
# Jelly, 3 bytes

```
O²Ọ

```

Try it online!

Squares each codepoint.
> 14 votes

# Answer
# Japt, ~~5~~ 2 bytes

```
cp

```

Try it online

---

## Explanation

```
     :Implicit input of string U
c    :Map over the character codes of the string.
p    :Square them.
     :Implicit output of result.

```
> 8 votes

# Answer
# Brain-Flak, 33 bytes

Includes +1 for `-c`

```
{((({}){}){}<>)<>}<>{({}<>)<>}<>

```

Try it online!

```
# For each character
{
  # Multiply by 4 and move to the other stack
  ((({}){}){}<>)

# End loop
<>}

# For each character on the other stack
<>{

  # Copy it back (reverse the stack)
  ({}<>)<>

# End loop
}<>

```
> 5 votes

# Answer
# Braingolf v0.6, 17 bytes

```
VRl1-M[R.*>v]R&@

```

Squares each char value then prints.

*-1 byte thanks to Erik the Outgolfer's squaring solution*

# Braingolf v0.7, 6 bytes \[non-competing\]

```
{.*}&@

```

Also squares each value then prints, but v0.7 has the "foreach" `{}` loop
> 4 votes

# Answer
## Mathematica, 48 bytes

```
FromCharacterCode[4Mod[Hash/@Characters@#,978]]&

```

Explanation:

```
                             Characters@#      & - Convert string to array of characters
                       Hash/@                    - Hash them all using default hash
                   Mod[                  ,978]   - apply a modulus which uniquely transforms each potential character's hash into a number
                  4                              - times by 4 to move values out of 0x20-0x7E.
FromCharacterCode[                            ]  - Convert array of numbers back to string

```

Interestingly of the two modulus options less than 1000 which changed the 96 characters into 96 unique values with modulus 978 the lowest two values were 7 then 33. Luckily times by 4 converts this to 28 and 132 which both just fall outside the visible range. If I used the other modulus of 784 then I needed to multiply by 18 to move the numbers outside the range.

Test case.

Note: extra backslashes in there as escape characters for `"` and `\`. Also character 0x7E doesn't seem to want to paste correctly.

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

```

Output:

The use of `Hash` came about as `ToCharacterCode` is really long. However hashing it was nearly as expensive. The easy mathematica way to do this would be 49 bytes:

```
FromCharacterCode[4ToCharacterCode@Characters@#]&

```
> 4 votes

# Answer
# Vyxal `s`, 3 bytes

```
C²C

```

Try it Online!

That is,

```
C   # string to character codes
²C  # square each and convert back to letters
    # the s flag joins as a single string.

```

but if IO was a little less restrictive:

## using `K` flag, 1 byte

```
²

```

Try it Online!

Keg is weird okay. It just is.

```
    # the K flag enables Keg mode, which makes integers and characters interchangeable. It's a tribute to my first golfing language and existed before I saw this challenge
²   # square the code point of each character
    # output that as characters because K flag.

```
> 4 votes

# Answer
# Google Sheets, 68 bytes

```
=ArrayFormula(Join("",IfError(Char(Code(Mid(A1,Row(A:A),1))^2),"")))

```

I wanted to post this to show how awkward it is to do some basic functions in Sheets. Do you want to do an operation to every character in a cell and out the concatenated result? You're at 42 bytes before you even *act* on those characters.

```
=ArrayFormula(Join("",Mid(A1,Row(A:A),1)))

```

Otherwise, this is the same as other solutions: square the code point of each character.
> 3 votes

# Answer
# PowerShell, ~~32~~ 31 Bytes

-1 Thanks to neil, `99+` to `4*`

```
[char[]]"$args"|%{[char](4*$_)}

```

multiplies 9 by each character code and prints it back.
> 2 votes

# Answer
# CJam, ~~8~~ 5 bytes

```
l95f+

```

Try it online!

Adds 95 to each codepoint.
> 2 votes

# Answer
# Pyth, 6 bytes

```
smC*4C

```

Try it here.

Multiplies each codepoint by 4.
> 2 votes

# Answer
# Subleq (8-bit), 11 bytes

```
-1 15 -128
2 15 -1
15 -1 9
15 15

```

Subleq Emulator

## Explanation

```
-1 15 -128 '0: input to 15:, if null exit; use -128 for exit so I can be used to add 128
           '   in the next line saving a byte
2 15 -1    '3: 15: = 15: + 128
15 -1 9    '6: output 15:
15 15      '9: 15: = 0, goto 0; final 0 is not entered saving a byte

```
> 2 votes

# Answer
# 05AB1E, 4 bytes

```
ÇnçJ

```

Try it online!

Squares each codepoint.
> 1 votes

# Answer
# CJam, 4 bytes

```
lWf^

```

XORs each code point with **-1**. CJam's characters are 16 bits wide, so this maps code point **n** to code point **65535 - n**.

Try it online!
> 1 votes

# Answer
# Decimal, 37 bytes

```
91D31030030012255D412D590D543D301291D

```

Explanation:

```
91D             ; declare jump 1
    310         ; push user input to stack
    300         ; duplicate
    300         ; duplicate
    12255D      ; push EOF to stack
    412D        ; compare top two values, pop, push result
    5 90D 5     ; if result == true, quit
    43D         ; multiply top two values, pop, push result
    301         ; print
    2           ; pop
91D             ; goto jump 1

```

Try it online!
> 1 votes

# Answer
# Husk, 5 bytes

```
m(c□c

```

Try it online!
> 1 votes

# Answer
# brainfuck, 12 bytes

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

```

Try it online!

Negate assuming latin1 output
> 1 votes

# Answer
# Grok, 14 bytes

```
:j
}lI_p+wYp
q

```

Modification of this cat program. It adds 95 to every character before it gets outputted, changing the character range from `0x0A - 0x7E` to `0x7F - 0xDD`.
> 1 votes

# Answer
# Python 3, 40 38 bytes

```
print([chr(ord(x)*9)for x in input()])

```

Try It Online!
> 0 votes

# Answer
# C, 42 bytes

```
c;f(){while(~(c=getchar()))putwchar(c*c);}

```

Assumes a UTF-8 locale. Input is squared.

Try it online!
> 0 votes

# Answer
# Clean, 25 bytes

```
import StdEnv

```

#

```
map((+)'~')

```

A partial function literal.

Try it online!

**Realistically:**

```
f s = {# c+'~' \\ c <-: s}

```

Unboxed array comprehension over an unboxed array of the same type (`{#Char} -> {#Char}`). Clean will be able to determine that the uniqueness is transferrable (`!u:{#Char} -> u:{#Char}`), and that the size is the same as the input size. This means that if you pass a `*String`, every character will be destructively updated with the corresponding one in the output, meaning no memory allocation or movement is done and the graph node is fully reused.

Try it online!
> 0 votes

# Answer
# Erlang (escript), 18 bytes

One of the rare cases that Erlang is ever competitive.

```
f(X)->[I*I||I<-X].

```

Try it online!

# Explanation

```
f(X)-> % Function taking a single string as input
[I*I|| % Square the code-point ...
I<-X]. % ... for every character taken from the string

```
> 0 votes

# Answer
# Kotlin, 25 bytes

Subtract **99** from each character value. This ends up moving space to FFBD (as Kotlin uses UTF-16) and most of the ASCII set to control characters and unreadable garbage.

```
{fold(""){s,c->s+(c-99)}}

```

Try it online!
> 0 votes

# Answer
# Duocentehexaquinquagesimal, 5 bytes

```
SYÍ’ü

```

Try it online!
> 0 votes

# Answer
# Python 3, 47 bytes

```
lambda x:''.join(chr(y-32+(y>63)*98)for y in x)

```

Input must be bytes. I know this doesn't win, I'm posting it because the output could fit into an 8-bit ascii extension.

Try it online!
> 0 votes

# Answer
# Thunno `J`, 4 bytes

(Actually \\$ 4 \log\_{256}(96) \approx \\$ 3.29 bytes but the leaderboard doesn't take decimals)

```
O2^C

```

Attempt This Online!

#### Explanation

```
O     # Ordinals of the input
 2^   # Square each ordinal
   C  # Convert back to characters
      # J flag joins the list

```
> 0 votes

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


title: Pi Day, Pi Minute, or Pi Second?

text:
# Question
Title: Pi Day, Pi Minute, or Pi Second?
In this challenge you will need to determine whether it's Pi Day, Pi Minute, or Pi Second.

Because Pi is irrational, it wants your code to be as short as possible.

# Examples

**No input is provided**, your program should use the system time. I've just added it for clarity

```
March 14, 2016 0:00:00
Pi Day
December 25, 2015 3:14:45
Pi Minute
December 29, 2015 0:03:14
Pi Second
January 1, 2016 0:00:00
<No Output>

```

## What is Pi Day / Minute / Second

* `Pi Day` is when the month is March, and the date is the 14th
* `Pi Minute` is when the hour is 3, and the minute is 14
* `Pi Second` is when the minute is 3, and the second is 14
* `Pi Day` should be preferred instead of `Pi Minute` or `Pi Second`, and `Pi Minute` should be preferred instead of `Pi Second`.
* For this challenge you should use 12-hour time (15:14 == 3:14). The date/time used to determine the `Pi Day/Minute/Second` should be based on **system time**.

## Scoring & Bonus

**-15 byte Bonus:** If you print `"No Pi Time"` when it's not Pi time.

---

As always, standard loopholes are disallowed. This is shortest code in bytes wins!

# Answer
> 4 votes
## CJam, 41 bytes

```
et[3E]#"
Pi Day

Pi Minute
Pi Second
"N/=

```

Test it here. Alternatively use this link to stub the result of `et` for easier testing.

### Explanation

```
et   e# Get the current datetime as an array with the following elements:
     e#   - Year
     e#   - Month
     e#   - Day
     e#   - Hour
     e#   - Minute
     e#   - Second
     e#   - Millisecond
     e#   - Weekday
     e#   - Tickrate or something.
[3E] e# Push the array [3 14].
#    e# Find the position of this subarray in the current datetime array. Let's see
     e# what results we can get:
     e#   - Year 3 is in the past and there is no 14th month, so we can't get 0.
     e#   - Pi day will give result 1.
     e#   - Day 3, hour 14 would give 2.
     e#   - Pi minute will give result 3.
     e#   - Pi second will give result 4.
     e#   - Second 3, millisecond 14 would give 5.
     e#   - Weekday and tickrate won't be 14, so we'll never get 6 or 7.
     e#   - If [3 14] isn't found at all we get -1.
"\Pi Day\\Pi Minute\Pi Second\"
     e# Push this string (with linefeeds instead of backslashes.
N/   e# Split into lines.
=    e# Select the corresponding element. The non-existent "pi hour" and "pi millisecond"
     e# would map to empty strings as well as the -1.

```

# Answer
> 9 votes
# Javascript (ES6), 114 112 - 15 = 97 bytes

```
x=>['Pi Day','Pi Minute','Pi Second'].find((x,i)=>[/ar 14/,/(03|15):14:/,/03:14/][i].test(Date()))||'No Pi Time'

```

**Ungolfed:**

```
x=>
['Pi Day', 'Pi Minute', 'Pi Second']  // array of outputs
.find(                                // find first element in the array
    (x, i)=>                          // which returns truthy for this function
    [/ar 14/, /(03|15):14:/, /03:14/] // array of regex patterns
    [i]                               // get corresponding regex based on index
    .test(Date())                     // test it against current date, date is automatically cast to string
) || 'No Pi Time'                     // if no result, then return "No Pi Time"

```

Thanks for -2 bytes @edc65

# Answer
> 5 votes
## Ruby, ~~125~~ 124 chars

```
i=[*[(t=Time.new).month,t.day,t.hour,t.min,t.sec].each_cons(2)].index [3,14];i&&$><<['Pi Day','','Pi Minute','Pi Second'][i]

```

Alas, the cleverer `%i[month day hour min sec].map{|x|Time.new.send x}` is longer.

The key here is the use of `each_cons` to avoid repetition (see the last few lines of the explanation below).

```
i=                          # send i (index) to...
[*                          # convert to array (splat)...
 [
  (t=Time.new).month,       # the current month...
  t.day,t.hour,t.min,t.sec  # etc... (duh)
 ]
 .each_cons(2)              # each consecutive two elements
]                           # [[month, day], [day, hour], [hour, min], etc]
.index [3,14];              # first occurrence of [3, 14]
i&&                         # shorthand for "if i"...
$><<                        # output...
[
 'Pi Day',                  # [month=3, day=14] is Pi Day
 '',                        # [day=3, hour=14] isn't anything
 'Pi Minute',               # [hour=3, min=14] is Pi Minute
 'Pi Second'                # [min=3, sec=14] is Pi Second
][i]                        # index by index (obviously)

```

# Answer
> 4 votes
## Python 2, ~~219~~ ~~186~~ 183 Bytes (198-15)

I tried

Ungolfed:

```
from datetime import datetime

now = datetime.now()
output = ['Pi Day', 'Pi Minute', 'Pi Second', 'No Pi Time']

if now.month == 3 and now.day == 14:
    print output[0]
elif now.hour == 2 and now.minute == 13:
    print output[1]
elif now.minute = 2 and now.second == 13:
    print output[2]
else:
    print output[3]

```

Golfed:

```
from datetime import *
n=datetime.now()
a=n.minute
if n.month==3and n.day==14:print'Pi Day'
elif n.hour==2and a==13:print'Pi Minute'
elif a==2and n.second==13:print'Pi Second'
else:print'No Pi Time'

```

# Answer
> 4 votes
## Japt, 78 - 15 = 63 bytes

```
D=Ð)g ¥3©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

```

Pretty straightforward - just checks the date for every case.

Explanation:

* `D=Ð)g` get the current date (`Ð`), store it in the variable `D` and get the month (`g`). Why store it in the variable, if it's already one-letter? Because since then you can dress any part of date with `Da`, where `a` is the function, returning year, month, date, etc. But otherwise you'd have to do `Ð a`, see the space.
* `¥3` is `==3`, checking if the month is March.
* `©` is `&&`, i.e. "and".
* `Df` is the day of the month.
* `E` is 14
* `?...:...` \- typical sets of ternary operators
* `Dd %C` the reminder of dividing the hour (`Dd`) by 12 (`C`)
* `Dc` is the minutes
* `Db` are seconds

Try it online!

---

To emulate Pi Day:

```
D=Ð"3/14/11 11:11:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

```

To emulate Pi Minute:

```
D=Ð"11/11/11 3:14:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

```

To emulate Pi Second:

```
D=Ð"11/11/11 00:3:14";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te

```

# Answer
> 3 votes
# TI-BASIC, 124 bytes

Thanks to FlagAsSpam for shaving a few bytes.

```
"→Str1
getTime
If min({3,14}={Ans(2),Ans(3
"Pi Second→Str1
getTime
If Ans(2)=14 and max(Ans(1)={3,14
"Pi Minute→Str1
getDate
If min({3,14}={Ans(2),Ans(3)
"Pi Day→Str1
Str1

```

# Answer
> 3 votes
# Perl, 80 - 15 = 65 bytes

```
print'No 'x localtime!~/(ar | 15:|03:)14/,'Pi ',(Time,Day,Minute,Second)["@-"/4]

```

Take 2, parsing the string representation of `localtime`. At present, this looks something like this:

```
Sun Jan  3 15:14:15 2016

```

The position of the matched string is used to determine the correct Pi Time.

---

### Perl, 100 bytes

```
@t=localtime;$t[2]%=12;3-/3/^{@t[$_,$_+1]}->{14}||exit!print'Pi ',(Second,Minute,_,Day)[$_]for 3,1,0

```

`localtime` returns the months zero indexed, hence the need for `3-/3/`.

# Answer
> 3 votes
# 05AB1e, score: 31 (46 bytes \- 15 bonus)

```
žfžeža12%žbDžc)2ôJƵÖk”€º‚Ž™Ù…Þ”#…Pi ìć…No ìªsè

```

Try it online or try it online with emulated datetime.

Adding the `No Pi Time` bonus costed 8 bytes, so it's worth the -15. Here it is without the bonus:
`žfžeža12%žbDžc)2ôJƵÖk”‚Ž™Ù…Þ ”#„Pirèðý` \- Try it online or try it online with emulated datetime.

**Explanation:**

```
žf               # Push the current month
  že             # Push the current day
ža               # Push the current hours (24-hours format)
  12%            # Modulo-12 to make it a 12-hours format
     žb          # Push the current minutes
D                # Duplicate the current minutes
 žc              # Push the current seconds
)                # Wrap all values on the stack into a list
 2ô              # Split it into pairs
   J             # Join each pair together
    ƵÖ           # Push compressed integer 314
      k          # Get the first 0-based index of 314 in this list (or -1 if none are)
”€º‚Ž™Ù…Þ”       # Push dictionary string "Time Day Minute Second"
          #      # Split it on spaces: ["Time","Day","Minute","Second"]
           …Pi ì # Prepend "Pi " in front of each:
                 #  ["Pi Time","Pi Day","Pi Minute","Pi Second"]
ć                # Extract head; pop and push remainder-list and first item separately
 …No ì           # Prepend "No " in front of it: "No Pi Time"
      ª          # Append it to the remainder-list:
                 #  ["Pi Day","Pi Minute","Pi Second","No Pi Time"]
s                # Swap so the earlier index of 314 is at the top
 è               # Use it to index into the list of strings,
                 # where -1 would get the last item
                 # (after which the result is output implicitly)

```

See this 05AB1E tip of mine (sections *How to use the dictionary?* and *How to compress large integers?*) to understand why `”€º‚Ž™Ù…Þ”` is `"Time Day Minute Second"` and `ƵÖ` is `314`.

# Answer
> 2 votes
# Python 3, 137 - 15 = 122 bytes

```
import time
T=list(time.localtime())
T[3]%=12
print({1:'Pi Day',3:'Pi Minute',4:'Pi Second'}.get(bytes(T[1:6]).find(b'\x03\x0e'),'No Pi Time'))

```

The 12-hour requirement was unfortunate, as this would've been 118-15=103 bytes without it:

```
import time
print({1:'Pi Day',3:'Pi Minute',4:'Pi Second'}.get(bytes(time.localtime()[1:6]).find(b'\x03\x0e'),'No Pi Time'))

```

# Answer
> 2 votes
# AppleScript, ~~202~~ ~~190~~ ~~187~~ ~~183~~ 181 bytes

Hey, this isn't so bad after all.

```
set n to current date
set b to n's time string
if n's date string contains"March 14"
log"Pi Day"
else if b contains"3:14:"
log"Pi Minute"
else if b contains"3:14"
log"Pi Second"
end
```

~~I actually found a use for AppleScript's method calling. Go figure.~~ Nope. Just turns out that `I'm an idiot`. Setting a variable is shorter.

(for those wondering, current date command returns a date-type with the contents `"Saturday, January 2, 2016 at 2:46:01 PM"` or the like)

# Answer
> 1 votes
# PHP, 85 - 15 = 70 bytes

```
<?=['No Pi Time','Pi Day','Pi Minute','Pi Second'][strpos(@date(Ymdhi_is),'0314')/4];

```

---

The main trick use here is the `Ymdhi_is` date format, at the time of writing, `date('Ymdhi_is')` returns `201501030258_5828`.

* `md`, `hi` and `is` are the values who will be replaced by `0314` if it's Pi-something. Note that all those strings will be always be replaced by a 4-character long string.
* They are put in that specific order since `strpos` will stop searching at the first occurrence of the needle, so we put them in the order of priority.
* A separator between `hi` and `is` is necessary because we don't want `strpos` to match a value that would overlap both (thanks to primo for saving bytes here).
* The needle is `0314` because `314` would wrongly match 10:31:42 as Pi-Second.

The Y part is the trickiest. We need a prefix to to offset the first occurrence of Pi-something, allowing us to distinguish `strpos`'s return values between `false` (not found, Pi-nothing) and `0` (found at index 0, Pi-day).

And we want this prefix to be either 4 or 5-character long, since we are planning to divide `strpos`'s return value by 4.

Y is 4-character long, but:

* it will be 5-character long someday, and this will break the program (think about year 10314): the PHP documentation says that `Y` will be replaced by 4 digits, but it's not true.
* if you come back in time, at year 314, it will break the program.

Since PHP didn't exist in year 314, and will likely not exist anymore in year 10314, I guess these bugs can be safely ignored.

Note that `0314` can overlap `Ymd` since:

* `Ymmd` configuration: there's no 31st month.
* `YYmm` configuration: there's no 14th month.
* `YYYm` configuration: there are less than 40 months.

---

Also, there's a version without the bugs related to the year, which is **86 - 15 = 71 bytes**:

```
<?=['No Pi Time','Pi Day','Pi Minute','Pi Second'][strpos(@date(D_mdhi_is),'0314')/4];

```

# Answer
> 1 votes
## Pascal, 226 Bytes

See also FreePascal. This `program` requires a processor complying to ISO standard 10206 “Extended Pascal”.

```
program p(output);var t:timeStamp;begin getTimeStamp(t);with t do write(subStr('Pi Day   ',1,9*ord(month=3))+subStr('Pi Minute',1,9*ord(hour in[3,15]))+subStr('Pi Second',1,9*ord(minute=3)):9*ord(14 in[day,minute,second]))end.

```

Ungolfed:

```
program piDMS(output);
    var
        ts: timeStamp;
    begin
        getTimeStamp(ts);
        { `with t do ` is two characters shorter than six times `t.` }
        with ts do
        begin
            writeLn(
                    { subStr(string, firstCharacterIndex, length) }
                    subStr('Pi Day   ', 1, 9 * ord(month = 3)) +
                    subStr('Pi Minute', 1, 9 * ord(hour in [3,15])) +
                    subStr('Pi Second', 1, 9 * ord(minute = 3))
                    : 9 * ord(14 in [day, minute, second])
                );
        end;
    end.

```

---

**216 characters** if

* the *implementation-defined* value of `maxChar` has an ordinal value ≥ 59 and
* neither `chr(3)` or `chr(14)` of the *implementation-defined* set of `char` values indicate an end of line (Pascal does not permit multiline strings).

```
program p(output);var t:timeStamp;begin getTimeStamp(t);with t do year:=index(chr(month)+chr(day)+chr(hour mod 12)+chr(minute)+chr(second),'');write(subStr('Pi SecondPi Minute         Pi Day   ',37-9*t.year):9)end.

```

NB: The `string` literal `''` is `chr(3) + chr(14)`.

# Answer
> 1 votes
# Go, 211 - 15 = 196 bytes

```
import."time"
func f(){N,s:=Now(),"Pi "
M:=N.Minute()
if _,m,d:=N.Date();m==3&&d==14{s+="Day"}else if N.Hour()%12==3&&M==14{s+="Minute"}else if M==3&&N.Second()==14{s+="Second"}else{s="No "+s+"Time"}
println(s)}

```

Attempt This Online!

Prints to STDERR.

# Answer
> 1 votes
# Japt, ~~48~~ ~~47~~ 45 bytes

:\ I can *definitely* do better than this! Outputs `undefined` if it's not a Pi date/time. Second line include a trailing space.

```
`DÃÕsMÔSSeÖ`qÅæÏgKs6 f"%d+" ã2)e#;ìF
©i"Pi

```

Test it, or test:

```
`...`qÅæÏgKs6 f"%d+" ã2)e#;ìF\n©i"Pi
`...`                                     :Compressed string "DaysssMinutesSecond"
     q                                    :Split on
      Å                                   :  "s"
       æ                                  :Get first element to return true
        Ï                                 :When its index is passed through the following function
         g                                :  Index into
          K                               :    Date
           s6                             :    To locale string (M/D/Y, h:m:s A/PM)
              f                           :    Match
               "%d+"                      :      RegEx /\d+/
                     ã2                   :    Sub-arrays of length 2
                       )                  :  End indexing
                        e                 :  Is equal to
                         #;               :    59
                           ì              :    Converted to digit array in base
                            F             :      15
                             \n           :Assign to variable U
                               ©          :Logical AND with
                                i"Pi      :  U prepended with "Pi "

```

# Answer
> 1 votes
# Pascal (FPC), ~~263~~ 229 bytes

```
uses sysutils,RegExpr;var x:array[0..2]of string=('.*:03:14','.* 03:14.*','14-3.*');y:array[0..2]of string=('Second','Minute','Day');i:word;begin
for i:=0to 2do if ExecRegExpr(x[i],DateTimeToStr(Now))then writeln('Pi ',y[i]);end.

```

Try it online! ~~263b~~

Might be shortened by using `if..then..elseif..` instead of complicated arrays & loops.

# Answer
> 0 votes
# Python 3, 179 bytes

```
import functools as F,datetime as D
T,G=D.datetime.now(),getattr
F.reduce(lambda i,j:print("Pi "+i.title())if G(T,i)/G(T,j)==3/14else j,"month day hour minute second".split(" "))

```

# Answer
> 0 votes
# Zsh\*, ~~93~~ ~~88~~ 83 (98-15) bytes

```
case `date` in *Mar\ 14*)t=Day;;*\ 03:14*)t=Minute;;*03:14\ *)t=Second;esac
<<<Pi\ ${t?No Pi Time}

```

Try it online! (98-15 bytes)
~~103-15 bytes~~ ~~93 bytes~~ ~~107-15 bytes, using associative array~~

Used `extendedglob` for matching the `case` patterns. If `$t` wasn't set (`${t?}`), then it prints "No Pi Time" to stderr.

---
Tags: code-golf, date, pi
---


title: Generating the alphabet in JavaScript

text:
# Question
Title: Generating the alphabet in JavaScript
I'm pretty sure there's not a better way to do this but figured it couldn't hurt to ask.

I'm tired of typing out `a='abcdefghijklmnopqrstuvwxyz'`.

Cool languages have `Range('a'..'z')` or similar

What can we come up with with JS that's as short as possible??

```
for(i=97,a='';i<123;){a+=String.fromCharCode(i++)}

```

is longer than just the alphabet - but guarantees I don't screw up somewhere.

I'm hoping there's a nasty bit-shifty way to produce a-z in less than 50 characters.

I messed around with `i=97;Array(26).map(x=>String.fromChar....i++`

but it was always way longer by the time I joined then split the array(26) to be useable

---

Edit: I've gotten it down to

```
[...Array(26)].reduce(a=>a+String.fromCharCode(i++),'',i=97)

```

60 bytes

# Answer
> 18 votes
# Alternative to String.fromCharCode

... if you are happy with a lowercase only alphabet.

```
for(i=9,a='';++i<36;)a+=i.toString(36) // 38, cannot be used in an expression
[...Array(26)].map(_=>(++i).toString(36),i=9).join`` // 52 directly returnig the string desired
[...Array(26)].map(_=>a+=(++i).toString(36),a='',i=9) // 53 assign to a variable
(i=9,[for(_ of Array(26))(++i).toString(36)].join``) // 52 ES7 direct return
i=9,a='',[for(_ of Array(26))a+=(++i).toString(36)] // 51 ES7 assign to a variable

```

# Answer
> 18 votes
**Note:** All of these techniques assign the alphabet string to variable `a`.

---

I am 99% certain that the shortest way to achieve this in JavaScript is indeed:

```
a="abcdefghijklmnopqrstuvwxyz" // 30 bytes

```

But there are several other interesting methods. You can use string compression:

```
a=btoa`i·?yø!?9%?z)ª»-ºü1`+'yz' // 31 bytes; each ? represents an unprintable

```

You can get the compressed string from `atob`abcdefghijklmnopqrstuvwx``. The `'yz'` must be added manually because if you compress the whole string, while the result is only 27 bytes, it will turn out as `abcdefghijklmnopqrstuvwxyw==`.

I believe the shortest way to do it programmatically is also the method you suggested:

```
for(i=97,a='';i<123;)a+=String.fromCharCode(i++) // 48 bytes

```

You can do it with ES6 features (template strings ````, spread operator `...`) if you want:

```
a=[...Array(26)].map(_=>String.fromCharCode(i++),i=97).join`` // 61 bytes
a=[...Array(26)].map((_,i)=>String.fromCharCode(i+97)).join`` // also 61 bytes
a=[...Array(i=26)].map(_=>String.fromCharCode(++i+70)).join`` // again, 61 bytes

```

You can do one better with a variable instead of `.join```:

```
[...Array(26)].map(_=>a+=String.fromCharCode(i++),i=97,a='') // all 60 bytes
[...Array(26)].map((_,i)=>a+=String.fromCharCode(i+97),a='')
[...Array(i=26)].map(_=>a+=String.fromCharCode(++i+70),a='')

```

Or ES7 with array comprehensions, which is another byte shorter:

```
a=[for(_ of Array(i=26))String.fromCharCode(++i+70)].join`` // 59 bytes

```

Creating the variable beforehand saves yet another byte:

```
a='',[for(_ of Array(i=26))a+=String.fromCharCode(++i+70)] // 58 bytes

```

Also, `String.fromCharCode` accepts multiple arguments and will automatically join them. So we can golf each ES6 version down to 57 bytes:

```
a=String.fromCharCode(...[...Array(26)].map(_=>i++,i=97)) // all 57 bytes
a=String.fromCharCode(...[...Array(26)].map((_,i)=>i+97))
a=String.fromCharCode(...[...Array(i=26)].map(_=>++i+70))

```

And the ES7 one down to 55:

```
a=String.fromCharCode(...[for(_ of Array(i=26))++i+70]) // 55 bytes

```

If you'd like to learn more about golfing ranges, check out this set of tips. There's also one about ES7's array comprehensions.

**EDIT:** As edc65 has pointed out, most of these become shorter using `i.toString(36)` instead of `String.fromCharCode(i)`:

```
for(i=9,a='';++i<36;)a+=i.toString(36) // 38 bytes
a=[...Array(26)].map(_=>(++i).toString(36),i=9).join`` // 54 bytes
[...Array(26)].map(_=>a+=(++i).toString(36),i=9,a='') // 53 bytes
i=9,a=[for(_ of Array(26))(++i).toString(36)].join`` // 52 bytes
i=9,a='',[for(_ of Array(26))a+=(++i).toString(36)] // 51 bytes

```

I believe this one is the shortest possible that can be called as a function return value:

```
eval("for(i=9,a='';++i<36;)a+=i.toString(36)") // 46 bytes

```

It's three bytes shorter than manually returning it from a function:

```
x=>eval("for(i=9,a='';++i<36;)a+=i.toString(36)") // 49 bytes
x=>{for(i=9,a='';++i<36;)a+=i.toString(36);return a} // 52 bytes

```

Of course, `x=>"abcdefghijklmnopqrstuvwxyz"` still beats everything else.

# Answer
> 7 votes
Here's another approach, a 51 byte ES6 expression:

```
String.fromCharCode(...Array(123).keys()).slice(97)

```

50 bytes in upper case of course.

# Answer
> 7 votes
```
(36n**26n*351n/1225n-1n).toString(36)

```

37 bytes, as an expression. Uses the same base-36 method as many others, but further, obtaining all the letters from a single number. Requires BigInt support.

# Answer
> 3 votes
36 bytes, using a trick I just learned about (from this post: https://codegolf.stackexchange.com/a/176496/64538):

```
for(i=9;++i<36;)name+=i.toString(36)

```

`window.name` is an empty string by default.

Of course, this is even less practical than the 38-byte solution since it uses a longer variable name.

# Answer
> 1 votes
Using what may or may not be defined at global scope

39 bytes for object properties to array matching `a-z`

```
a=`${Object.keys(top)}`.match(/[a-z]/g)

```

48 bytes for an unsorted `Set`

```
a=new Set(`${Object.keys(top)}`.match(/[a-z]/g))

```

55 bytes for a sorted `Set`

```
a=new Set(`${Object.keys(top)}`.match(/[a-z]/g).sort())

```

67 bytes for a sorted string

```
a=[...new Set(`${Object.keys(top)}`.match(/[a-z]/g).sort())].join``

```

# Answer
> 1 votes
I like this answer from above, but just throwing this small addition out there:

```
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');

```

The other answers are great but consider this example:

```
const excelSheet = sheet('whatever.csv')
const headers = excelSheet.meta.headers // ['First Name', 'Last Name']
headers.map((header, i) => {
    console.log(`${header} is column ${alphabet[i]}`)
})

// First Name is column A
// Last Name is column B

```

It's more usable and readable for beginner/intermediate JavaScript developers. But this **is** code golf so I understand if this gets downvoted.

---
Tags: code-golf, tips, javascript
---


title: Draw the flag of Bangladesh

text:
# Question
Title: Draw the flag of Bangladesh
The flag of Bangladesh is very simple. It looks like below:

The flag will be in bottle green (#006a4e) and rectangular in size in the proportion of length to width of 10:6, with a red circle in near middle. The red circle (#f42a41) will have a radius of one-fifth of the length of the flag. This image will help you to understand the proportions properly:

In this Graphical output challenge, you need to draw the flag of Bangladesh like first image. Standard loopholes apply, Shortest code wins.

Resolution cannot be 0px, or `echo` style answers not supported.

Minimum resolution is `286*176`

# Answer
> 47 votes
# Wolfram Language (Mathematica), 23 bytes

¯\\\__(ツ)\_/¯ of course there is a built in for this...

```
"BD"~CountryData~"Flag"

```

but you can also get the same result with...

# Wolfram Language (Mathematica), 78 bytes

```
Graphics@{(c=RGBColor)@"#006a4e",{0,0}~Cuboid~{5,3},c@"#f42a41",Disk[{9,6}/4]}

```

-8 bytes {first code) thanks to @Makonede for "Bangladesh" to "BD"
-4 bytes (second code) thanks to @att

# Answer
> 34 votes
# SVG, 67 bytes

By tweaking the viewBox, we can take advantage of the fact that the stroke of a shape has a default width. That avoids creating any element for the background.

```
<svg viewBox=-.9,-.6,2,1.2><circle r=.9 fill=#f42a41 stroke=#006a4e
```

# Answer
> 28 votes
# SVG in HTML, 74 bytes

```
<svg viewBox=-9,-6,20,12 style=background:#006a4e><circle r=4 fill=#f42a41
```

-8 bytes by Joey

# Answer
> 28 votes
# Python3 + Turtle, ~~112~~ 84 bytes

```
from turtle import*
setup(286,176)
bgcolor("#006a4e")
ht()
bk(14)
dot(114,"#f42a41")

```

-28B thanks to Digital Trauma

Can't try it online but here is how it looks:

# Answer
> 20 votes
# HTML, 110 bytes

```
<div style=padding:10%35%10%25%;background:#006a4e><nav style=padding:50%;background:#f42a41;border-radius:50%
```

-1 bytes by Adám

Fun fact: percentage values on `padding-top` / `padding-bottom` follow the container’s width (not height).

# Answer
> 15 votes
# Bash + ImageMagick, ~~80~~ 79 characters

```
convert -size 500x300 xc:#006a4e -draw 'fill #f42a41 circle 225,150,225,250' x:

```

Thanks to

* Chris Down for pointing out word I missed in man bash: “a word *beginning* with `#` causes that word and all remaining characters on that line to be ignored”

Sample output:

# Answer
> 12 votes
## CSS, ~~128~~ ~~107~~ ~~104~~ 89 bytes

```
*{background:radial-gradient(200px at 45%,#f42a41 50%,#006a4e 0)0 0/500px 300px no-repeat
```

For best results run the code snippet and then click Full Page. Edit: Worked out that setting the background position and size works better than setting the body size. Saved 3 bytes thanks to @sech1p. Saved 15 bytes by copying @dingledooper's radial gradient.

# Answer
> 11 votes
# PostScript, ~~114~~ 95 bytes

Code:

```
0 .42 .31 setrgbcolor
0 0 300 180 rectfill
.96 .16 .25 setrgbcolor
135 90 60 0 360 arc fill

```

Result:

# Answer
> 10 votes
# Red, 101 bytes

```
Red[Needs:'view]view[base 500x300 0.106.78
draw[pen 244.42.65 fill-pen 244.42.65 circle 225x150 100]]

```

# Answer
> 9 votes
# , ~~143~~ ~~111~~ ~~108~~ 92 bytes

```
plot(0:9,,"n",as=1)
rect(0,0,10,6,,,"#006a4e",NA)
symbols(4.5,3,2,f=NA,bg="#f42a41",i=F,a=T)

```

Try it on rrdr.io

*-32 bytes after looking at @Dominic's answer to related challenge<br>-3 bytes thanks to @Frédéric*

Slighlty ungolfed to show full argument names (R allows partial matching):

```
plot(x=0:9,y=NULL,type="n",asp=1)
rect(0,0,10,6,col="#006a4e",border=NA)
symbols(4.5,3,circles=2,fg=NA,bg="#f42a41",inches=F,add=T)

```

# Answer
> 9 votes
# Perl 5, 89 bytes

Using ANSI escape codes for Linux-like command terminals. WSL in Windows should also work:

```
print"\33[0;3",($_%286-129)**2+($_/286-88)**2<3442?"1m#":"2m#",$_%286?"":"\n"for 1..50336

```

Run it in a terminal like this to get a big or small flag respectively in ansi colors or via a .ppm image file that can show the flag using most image viewers or web browsers:

```
perl -e'print"\33[0;3",($_%286-129)**2+($_/286-88)**2<3442?"1m#":"2m#",$_%286?"":"\n"for 1..50336'
perl -e'print"\33[0;3",($_%72-32)**2+($_/72-22)**2<215?"1m##":"2m##",$_%72?"":"\n"for 1..3168'
perl -E'say"P3 286 176 255 ",map 3442>($_%286-129)**2+($_/286-88)**2?"244 42 65 ":"0 106 78 ",1..50336' > flag.ppm

```

# Answer
> 8 votes
# C + stb\_image\_write, ~~296~~ ~~288~~ ~~278~~ 270 bytes

```
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include"stb_image_write.h"#include<math.h>
main(i){char p[151008];for(i=0;i<151008;i+=3){p[i]=0;p[i+1]=106;p[i+2]=78;if(pow(i/3%286-129,2)+pow(i/3/286-88,2)<3481)p[i]=244,p[i+1]=42,p[i+2]=65;}stbi_write_bmp("b.bmp",286,176,3,p);}

```

Outputs a BMP image called b.bmp:

Thanks to MerseyViking for the suggestion about removing `sqrt`

# Answer
> 7 votes
# HTML, 95 bytes

```
<p style="width:500;height:300;background:radial-gradient(200px at 45%,#f42a41 50%,#006a4e 0)">

```

Try it online!

# Answer
> 7 votes
# Basic (Tandy CoCo3 specifically), 109 Bytes

Firstly, hopefully there isn't a 'hard fast' rule on the exact color when the target computer only has a palette of 64 total... :-) I got as close as I could. I used the darkest green available and the 2nd darkest red.

Also, putting a CoCo3 in graphic mode doesn't "stay" unless you put some kind of pause at the end - but at 0.89 MHz it draws slowly enough you can see the result before it disappears back to text mode.

```
HSCREEN1:PALETTE1,2:PALETTE2,32:HCOLOR1,3:HLINE(0,0)-(299,179),PSET,BF:HCIRCLE(134,89),60,2:HPAINT(99,89),2,2

```

That said, if you did want to "press Enter to erase" and make it re-runnable without retyping in the line, it'll cost 9 bytes:

```
0 HSCREEN1:PALETTE1,2:PALETTE2,32:HCOLOR1,3:HLINE(0,0)-(299,179),PSET,BF:HCIRCLE(134,89),60,2:HPAINT(99,89),2,2:INPUTK

```

then type 'RUN'. Here's a screenshot of the result (emulated via VCC 2.1.0c on Server 2016):

The resolution of the flag is 300x180; the resolution of the video mode is 320x192, hence the (default) brighter green border on the edges.

Lastly, the program technically takes less bytes than I specified as it's tokenized, but I don't feel like doing that math.

# Answer
> 7 votes
# Gnuplot, ~~147~~ ~~140~~ ~~137~~ ~~120~~ 112 bytes

```
se si rat-2
se xr[0:20]
se yr[0:6]
uns ti
uns ke
uns bor
p'-'w cir fs s fc rgb var
9 3 99 27214
9 3 4 16001601
e

```

Written out neatly:

```
# set length unit ratio on 2:1
set size ratio -2

# set axis ranges
set xrange[0:20]
set yrange[0:6]

# make it look less like a chart
unset tics
unset key
unset border

# plot inline data series (everything on the next lines, up to an 'e')
# data cx cy radius color (rgb, decimal)
p '-' with cirles fillstyle solid fillcolor rgb variable
9 3 99 27214
9 3 4 16001601
e

```

Result in the 'qt' terminal:

# Answer
> 4 votes
# PHP, 129 bytes

```
($f=imagecolorallocate)($i=imagecreate(500,300),0,106,78);imagefilledellipse($i,225,150,200,200,$f($i,244,32,65));imagepng($i,a);

```

You cannot try it online as online testers logically disable image creation functions. Here is the result (original file is called "a", I added the extension for the import)

# Answer
> 4 votes
# p5.js, 97 bytes

```
setup=x=>createCanvas(300,180)+background(0,106,78)+fill(244,42,65)+noStroke()+circle(135,90,120)

```

# Answer
> 4 votes
# Python + Pygame, 124 bytes

```
from pygame import*
s=display.set_mode((286,176))
s.fill((0,106,78))
draw.circle(s,(244,42,65),(128,86),57)
display.update()

```

I haven't used Pygame in a long time, so I'm probably missing something obvious here (like setting the background of the window directly) but it's not the shortest answer overall either.

*-7 bytes thanks to @tsh's suggestion* *-31 bytes thanks to @ChrisH and @Sadap*, wow I really need to learn Pygame again

# Answer
> 4 votes
# Ruby with Shoes, 87 characters

```
Shoes.app(width:500,height:300){background'006a4e'
stroke fill'f42a41'
oval 125,50,200}

```

Sample output:

# Answer
> 3 votes
# HTML/CSS, 168 bytes

```
<div><div style=left:125;top:50;width:200;height:200;background:#f42a41;border-radius:50%><style>div{position:fixed;left:0;top:0;width:500;height:300;background:#006a4e

```

You can try it out here (doesn't seem to work as a snippet, for whatever reason...)

-1 byte thanks to Adám by removing the `}` at the end of the style block
-2 bytes thanks to Manish Kandu
-12 bytes thanks to pxeger
-13 bytes thanks to Neil

# Answer
> 3 votes
# Lua \+ LÖVE/Love2D, ~~176~~ 160 bytes

```
l=love;g=l.graphics;c=255;l.window.setMode(500,300)function l.draw()g.setBackgroundColor(0,106/c,78/c)g.setColor(244/c,42/c,65/c)g.circle('fill',225,150,100)end

```

-16 bytes thanks to @manatwork

# Answer
> 3 votes
# Python 3

I tried different solutions, here are my two best attempts...

## Python + turtle, 113 bytes

*Thanks to @Sadap to give me some hints on an "alternative" use of the turtle :)*

```
from turtle import*
s=Screen()
s.screensize(300,180,'#006a4e')
s.setup(305,183)
ht()
setx(-15)
dot(120,'#f42a41')

```

Commented code:

```
from turtle import*
# initialize a new window
s=Screen()
# define the turtle drawing area, with thee green background
s.screensize(300,180,'#006a4e')
# setup the size of the window
# slightly bigger than the drawing area, to avoid the scroll bars
s.setup(305,183)
# hide turtle default image
ht()
# from the center of the image, move to the left
# center of the circle
setx(-15)
# draw the red circle
dot(120,'#f42a41')

```

---

## Python + tkinter, 132 bytes

```
from tkinter import*
c=Canvas(Tk(),bg='#006a4e',width=300,height=180)
c.create_oval(75,30,195,150,fill='#f42a41',width=0)
c.pack()

```

Commented code:

```
from tkinter import*
# initialize a new window, setting the background color and the size
c=Canvas(Tk(),bg='#006a4e',width=300,height=180)
# draw the red circle
c.create_oval(75,30,195,150,fill='#f42a41',width=0)
# add the circle to the canvas
c.pack()

```

# Answer
> 3 votes
# Scratch, ~~230~~ 201 bytes

Try it online!
-26 thanks to @att, who used pen size to skip the lengthy circle formula!

Scratchblocks can't understand that hex values are literally what the value should be, and incorrectly displays a color. Visually, changing `set[C v]to[#123abc` to `set pen color to(#123abc` would work in Scratchblocks (and save bytes in the process), but due to Scratch's HSL system, such a color cannot be reached without hacks. Using the built-in eyedrop tool, we can get close (almost indistinguishable to the human eye) but it is only an approximation. Alternatively, ~~23~~ 15 blocks.

```
when gf clicked
go to x:(240)y:(
erase all
set pen size to(288
set[C v]to(27214
set pen color to(C
pen down
set x to(-240
set[C v]to[#f42a41
set x to(-24
set pen size to(192
set pen color to(C
pen down

```

# Answer
> 3 votes
# stacked, 93 bytes

```
400 setwidth 240 setheight'#006a4e'setbg'#f42a41'allstyle'370px Arial'font 69 226 to'●'text

```

Online interpreter. Here's the output generated (Firefox, latest version):

Or, a screenshot of the webpage:

## Explanation

Simply initializes the canvas with appropriate dimensions, sets the appropriate background color, and then draws a bullet character of the correct font height and location. We have to do this because stacked has no native way of drawing circles arbitrarily. The correctness of these arbitrary values can be verified with the following program, which draws a square on the lower-right quadrant of where the circle ought to be:

```
400 setwidth 240 setheight'#006a4e'setbg'#f42a41'allstyle'370px Arial'font 69 226 to'●'text

'white' allstyle
180 120 to
[80 go 90 turn] 4*

```

# Answer
> 3 votes
# HTML / Pug + Tailwind, 96 bytes

```
.w-80.py-8.pl-20(style='background:#006a4e')
 .rounded-full.w-32.h-32(style='background:#f42a41')

```

Test

# HTML / Pug + Tailwind, slightly changed colors, 64 bytes

```
.w-80.py-8.pl-20.bg-green-800
 .rounded-full.w-32.h-32.bg-red-600

```

Test

# Answer
> 2 votes
# Racket, 110 bytes

```
#lang slideshow
(pin-over(colorize(filled-rectangle 300 180)'(0 106 78))75 30(colorize(disk 120)'(244 42 65)))

```

Can't try it online!, but here's a screenshot:

# Answer
> 2 votes
# FLTK, 135 characters

```
Function{}{}{Fl_Window{}{xywh{0 0 500 300}box BORDER_BOX color 0x6a4eff}{Fl_Box{}{xywh{125 50 200 200}box OFLAT_BOX color 0xf42a41ff}}}

```

Ungolfed:

```
Function {} {} {
    Fl_Window {} {
        xywh {0 0 500 300}
        box BORDER_BOX
        color 0x6a4eff
      } {
        Fl_Box {} {
            xywh {125 50 200 200}
            box OFLAT_BOX
            color 0xf42a41ff
        }
    }
}

```

Sample output:

# Answer
> 2 votes
# p5.js, ~~105~~ ~~98~~ 96 bytes

```
draw=x=>createCanvas(300,180)+background(0,106,78)+noStroke()+fill(244,42,65)+circle(135,90,120)

```

Try it in the editor here.

# Answer
> 1 votes
# Javascript + HTML, ~~167~~ 153

## Javascript: ~~154~~ 140, HTML: 13

```
C.width=w=300
C.height=h=180 // 300 * 0.6
with(C.getContext`2d`)fillStyle="#006a4e",fillRect(0,0,w,h),fillStyle="#f42a41",arc(.45*w,.3*w,.2*w,0,7),fill()
```

```
<canvas id=C>
```

-14 characters from @Ismael Miguel

# Answer
> 1 votes
# Desmos, ~~64~~ 61 bytes

```
r=rgb(244,42,65)
g=rgb(0,106,78)
-9<=x<=11\{yy<36\}
xx+yy<=16

```

Try it on Desmos!

*-3 bytes thanks to Aiden Chow*

# Answer
> 0 votes
# Desmos, 66 bytes

This:

```
r=rgb(244,42,65)
g=rgb(0,106,78)
-9≤x≤11\left\{yy≤36\right\}
xx+yy≤16

```

This is longer than the other one, but that other one didn't work, as `\left` and `\right` seems to be needed.

# Answer
> 0 votes
# Perl 5 \+ `-M5.10.0`, 82 bytes

```
say"P6 300 180 255",map$=>((135-$_%300)**2+(90-$_/300)**2)**.5?".*A":".jN",0..54e3
```

Try it online!

Generates a PBM file by going through every co-ordinate and checking if the current pixel is within the circle, outputting the values for green or red respectively.

# Answer
> 0 votes
# Pikchr, 75 bytes

```
box ht.45fill 27214 color off
circle at-3/80,0rad.15fill 0xf42a41 color off

```

## Output

```
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 112.32 69.12">
<path d="M2,66L110,66L110,2L2,2Z" style="fill:rgb(0,106,78);"></path>
<circle cx="50" cy="34" r="21.6" style="fill:rgb(244,42,65);"></circle>
</svg>
```

---
Tags: code-golf, kolmogorov-complexity, graphical-output
---