title: Output 2015 as QR code

text:
# Question
Title: Output 2015 as QR code
Mission is simple. Just output number 2015 as QR code and write it to file named `newyear.png` in PNG format. Code must be valid any day, so maybe you shall not use current year.

QR code as text looks like this:

```
# # # # # # #   # # # #     # # # # # # #
#           #           #   #           #
#   # # #   #   # #     #   #   # # #   #
#   # # #   #       #   #   #   # # #   #
#   # # #   #       #   #   #   # # #   #
#           #               #           #
# # # # # # #   #   #   #   # # # # # # #
                #   # #
#   #     # #     # #     # #       #   #
  # # #   #   #   #   # #   #     #   # #
#   # #   # # #   # # # # # #   #       #
# # #         # #         # # # #
# # # # #   #   #     #     #   #     #
                      # # # #
# # # # # # #       #   # #   # #   #   #
#           #   #         # # # #
#   # # #   #         #     #   #     #
#   # # #   #     #     # # # # #
#   # # #   #   #   #   # #   # #   #   #
#           #     # #       # # #   # # #
# # # # # # #   #           #   #   #   #

```

The result written in `newyear.png` must contain that QR code with white 5 pixel borders and one pixel sized dots. It must not contain anything else than QR code.

# Answer
# Raw file, 184 bytes = 173-byte file + 11-byte filename

I hope this does not break any standard loopholes. But the output "has a high and the shortest way to produce it would (most likely) be to just print it literally...".

Base 64 of the file:

```
iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfAQAAAAA31SuUAAAAdElEQVR4XnXOMQ5BQRRA0euVRFgGCq1ubIyJpSh11I
qJWIjo+fnt/JnJe55WornlycXMVAB+Qp49A7U/J8rqlIQReG5Quz6Rx8eA6VaF5R7a5arooXg2LaKvd8KGRyBPJLoy
D640pxZ3pay/creL5KnEvwcfvE46ggJMibIAAAAASUVORK5CYII=

```

---

Instead of golfing a program I golfed the resulting PNG image. QR code is a very flexible format, there are many parameters that can be fiddled: the encoding of the input, the error correction level, and the masking image. These will all generate different symbols and thus compressed to files of different sizes.

So I have written a program to generate all these combinations (resulting 6720 files), and then use PNGOUT to pick the one which compressed to the smallest file. It turns out to be a file that:

* First write "20" in alphanumeric mode
* Then write "1" in numeric mode
* Then write "5" in numeric mode
* Use the "H" (High) error correction level
* Use the "110" data masking

This is called `test-3-1-H-Diamonds.bmp` if you used the program below. This image is 175-byte long after running PNGOUT. With "high" error correction level in "version 1" QR code, we can modify up to 8 pixels in the data part without ruining the data. With a bit of manual trial-and-error I can reduce it further to 173 bytes presented above. It can probably be smaller but exhausting all combinations requires 208C8 ~ 7.5 × 1013 checks which I'm not going to do ;)

---

The Rust (0.13.0-nightly (5ba610265)) program that generates all combinations:

```
/*

Also put these into your Cargo.toml:

[dependencies]
qrcode = "0.0.3"
bmp = "0.0.3"

*/

extern crate qrcode;
extern crate bmp;

use qrcode::bits::Bits;
use qrcode::optimize::Segment;
use qrcode::types::{Version, EcLevel, Mode};
use qrcode::ec::construct_codewords;
use qrcode::canvas::{Canvas, MaskPattern, Module};

use bmp::{Image, Pixel};

use std::num::Int;

const BLACK: Pixel = Pixel { r: 0, g: 0, b: 0};
const WHITE: Pixel = Pixel { r: 255, g: 255, b: 255 };

static SEGMENT_SEPARATIONS: [&'static [(uint, uint)]; 8] = [
    &[(0, 1), (1, 2), (2, 3), (3, 4)],
    &[(0, 1), (1, 2), (2, 4)],
    &[(0, 1), (1, 3), (3, 4)],
    &[(0, 2), (2, 3), (3, 4)],
    &[(0, 1), (1, 4)],
    &[(0, 2), (2, 4)],
    &[(0, 3), (3, 4)],
    &[(0, 4)],
];

const ALL_EC_LEVELS: &'static [EcLevel] = &[EcLevel::L, EcLevel::M, EcLevel::Q, EcLevel::H];
const ALL_MODES: &'static [Mode] = &[Mode::Numeric, Mode::Alphanumeric, Mode::Byte];
const ALL_MASK_PATTERNS: &'static [MaskPattern] = &[
    MaskPattern::Checkerboard,
    MaskPattern::HorizontalLines,
    MaskPattern::VerticalLines,
    MaskPattern::DiagonalLines,
    MaskPattern::LargeCheckerboard,
    MaskPattern::Fields,
    MaskPattern::Diamonds,
    MaskPattern::Meadow,
];

fn run(ec_level: EcLevel, mask_pattern: MaskPattern, segments: &[Segment], filename: &str) {
    let version = Version::Normal(1);
    let mut bits = Bits::new(version);
    if bits.push_segments(b"2015", segments.iter().map(|s| *s)).is_err() {
        return;
    }
    if bits.push_terminator(ec_level).is_err() {
        return;
    }
    let data = bits.into_bytes();
    let (encoded_data, ec_data) = construct_codewords(&*data, version, ec_level).unwrap();
    let mut canvas = Canvas::new(version, ec_level);
    canvas.draw_all_functional_patterns();
    canvas.draw_data(&*encoded_data, &*ec_data);
    canvas.apply_mask(mask_pattern);
    let canvas = canvas;

    let width = version.width();
    let real_image_size = (width + 10) as uint;
    let mut image = Image::new(real_image_size, real_image_size);
    for i in range(0, real_image_size) {
        for j in range(0, real_image_size) {
            image.set_pixel(i, j, WHITE);
        }
    }
    for i in range(0, width) {
        for j in range(0, width) {
            if canvas.get(i, j) == Module::Dark {
                image.set_pixel((i + 5) as uint, real_image_size - (j + 6) as uint, BLACK);
            }
        }
    }
    image.save(filename);
}

fn main() {
    for (z, separations) in SEGMENT_SEPARATIONS.iter().enumerate() {
        let mut segments = separations.iter().map(|&(b, e)| Segment {
            mode: Mode::Numeric, begin: b, end: e
        }).collect::<Vec<_>>();

        let variations_count = ALL_MODES.len().pow(segments.len());
        for i in range(0, variations_count) {
            let mut var = i;
            for r in segments.iter_mut() {
                r.mode = ALL_MODES[var % ALL_MODES.len()];
                var /= ALL_MODES.len();
            }
            for ec_level in ALL_EC_LEVELS.iter() {
                for mask_pattern in ALL_MASK_PATTERNS.iter() {
                    let filename = format!("results/test-{}-{}-{}-{}.bmp", z, i, *ec_level, *mask_pattern);
                    run(*ec_level, *mask_pattern, &*segments, &*filename);
                }
            }
        }
        println!("processed {}/{}", z, 8u);
    }
}

```
> 15 votes

# Answer
# Mathematica, ~~217~~ ~~177~~ ~~176~~ 166 bytes

Here is a start:

```
"newyear.png"~Export~ImagePad[Image[IntegerDigits[36^^fl6ibg25c8z00uef53p4657dgd6hjzg41e5joead1qgz0l2xchqgso5r1a51v5no4zkw9v22okklg0cymmy2,2,441]~Partition~21],5,1]

```

Less golf:

```
"newyear.png"~Export~ImagePad[
 Image[
  IntegerDigits[
    36^^fl6ibg25c8z00uef53p4657dgd6hjzg41e5joead1qgz0l2xchqgso5r1a51v5no4zkw9v22okklg0cymmy2,
    2,
    441
  ]~Partition~21
 ],
 5,
 1
]

```

The QR code is encoded in a base 36 number. Of course, I could encode it in extended ASCII (base 256), but that would only shorten the string by 30 bytes, and I'm not sure I can do the conversion at the cost of much less than that.

Of course, this is Mathematica, so there's also the **63-byte**

```
"newyear.png"~Export~ImagePad[BarcodeImage["2015","QR",21],5,1]

```

but I guess that's a standard loophole. ;) (This produces a different QR code than the one in the challenge, so I guess the QR code isn't unique?)
> 5 votes

# Answer
# Python 3, 261 bytes

```
from PIL import Image
h=Image.new("1",[21]*2)
h.putdata([int(u)for u in list("".join(format(ord(i),"08b")for i in'\x01\x0c\x03ï¯\x91MD\x8bª$]Q>þø\x05P\x1féÿY\x99ÔU-\x12 \\<ððVÖÿðü\x07IO¯\x0fEíj-\x83ÑT\x94û8\x80\x17Õ'))])
h.save("newyear.png")

```

Needs a better way of encoding

## Explanation

```
from PIL import Image    # Import the Pillow library for images
ima = Image.new("1", [21, 21])    # Create a new 21x21 Image in B/W mode
ima.putdata(    # Function to write a sequence to the pixels
    [int(u) for u in list(    # convert string into list of bits to write
        "".join(    # join into single string
            format(ord(byte),"08b"    # format a unicode character into list of bits
                )for byte in'\x01\x0c\x03ï¯\x91MD\x8bª$]Q>þø\x05P\x1féÿY\x99ÔU-\x12 \\<ððVÖÿðü\x07IO¯\x0fEíj-\x83ÑT\x94û8\x80\x17Õ'    # Loop through encoded qr data
        )
    )]
)
ima.save("newyear.png")    # Save image

```
> 5 votes

# Answer
# Matlab 545 Bytes

Hardcoded in painstaking manual work and ***without any fancy builtin string compression/conversation***. I know it still is not as good as the other answers but I am still happy=)

```
b=[[61:67,69,71:73,75:81,92,98]+100,
    1,3:4,6,12,23,25:27,29,31:35,37,39:41,43,54,56:58,60,63:64,66,68,70:72,74,85,87:89,91,97,99]+200,
    [1:3,5,16,22,24:26,30,36,47:53,55,57,59,61:67,87:89]+300,
    [9,11,15:16,20:21,24,27,29,40,42,48:50,57,59,71,74:75,77:79,81,85,89:90]+400,
    [2,9,11:12,14:15,18,34:37,39,42:43,46:47,50:51,72,74:75,77:79,81:82,95:99]+500,
    [0:1,3:8,10:12,14:15,26,32,37,40:41,43:45,57,59:61,63,67:69,71:77,88,90:92,94,97]+600,
    [19,21:23,25,27,33,37:39,50,56,59,62,66,69,81:87,89:91,95,99:101]+700];
z=zeros(31);z(b)= 1;imwrite(~z,'newyear.png')

```

More unreadable (the actual 545 version):

```
z=zeros(31);
z([
    [61:67, 69, 71:73, 75:81, 92, 98] + 100,
    [1, 3:4, 6, 12, 23, 25:27, 29, 31:35, 37, 39:41, 43, 54, 56:58, 60, 63:64, 66, 68, 70:72, 74, 85, 87:89, 91, 97, 99] + 200,
    [1:3, 5, 16, 22, 24:26, 30, 36, 47:53, 55, 57, 59, 61:67, 87:89] + 300,
    [9, 11, 15:16, 20:21, 24, 27, 29, 40, 42, 48:50, 57, 59, 71, 74:75, 77:79, 81, 85, 89:90] + 400,
    [2, 9, 11:12, 14:15, 18, 34:37, 39, 42:43, 46:47, 50:51, 72, 74:75, 77:79, 81:82, 95:99] + 500,
    [0:1, 3:8, 10:12, 14:15, 26, 32, 37, 40:41, 43:45, 57, 59:61, 63, 67:69, 71:77, 88, 90:92, 94, 97] + 600,
    [19, 21:23, 25,27, 33, 37:39, 50, 56, 59, 62, 66, 69, 81:87, 89:91, 95, 99:101] + 700
])= 1;
imwrite(~z,'newyear.png')

```

We create a 31 x 31 zero matrix, but access it as vector to set all cells with the indices of `b` to `1`. The tricks I used were the notation of consecutive integers (like `[1,2,3,4] = 1:4`) and removing one the 100-digit by adding a scalar to every value of the vector.

Let's see if anyone can beat that=)
> 3 votes

# Answer
# Bash, 206 252 257 Bytes

Using the `convert` command bundled in `imagemagick` saves 46 more bytes.

```
base64 -d<<<UDQKMzAgMzAKAAAAAAAAAAAAAAAAAAAAAAAAAAAH9L+ABBkggAXULoAF2S6ABdOugAQeoIAH+r+AB9zVAABIlwABHU6AAsIaAAFXS4AAD+QAB/ywAAQT5QAF3pIABd6SAAXdTgAEHBsAB/1OAAAAAAAAAAAAAAAAAAAAAAAAAAAA|convert - newyear.png

```

Converts the base64-encoded `pbm` image to a `png` image with `imagemagick`'s `convert`.

> You may need to adjust the `decode (-d)` parameter to your specific `base64` binary. Tested on my Ubuntu 14.04 LTS.

Saved 5 bytes by using `<<<`/*here-string*.

```
base64 -d>newyear.png<<<iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeAQMAAAAB/jzhAAAABlBMVEX///8AAABVwtN+AAAAX0lEQVQI12PACdi/7G9gYJFUaGBgvaIHJG6CiMvrgGJyCxoY2H/tBxJ3rgIVekxnYGCU9WtgYDokBWSFezcwMPA/ARrwZwMDA4vwUwYG1nuTYMRdP6CYjDRQ9q8fbrsBLRkaYOOP83wAAAAASUVORK5CYII=

```

Old version (257 bytes):
`echo iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeAQMAAAAB/jzhAAAABlBMVEX///8AAABVwtN+AAAAX0lEQVQI12PACdi/7G9gYJFUaGBgvaIHJG6CiMvrgGJyCxoY2H/tBxJ3rgIVekxnYGCU9WtgYDokBWSFezcwMPA/ARrwZwMDA4vwUwYG1nuTYMRdP6CYjDRQ9q8fbrsBLRkaYOOP83wAAAAASUVORK5CYII=|base64 -d > newyear.png`

Just a simple shell command chain that writes the base64 encoded `png` file into stdin of `base64` that decodes it because of the `-d` flag and writes its stdout to newyear.png.
> 2 votes

# Answer
# Python 2 + PIL, ~~216~~ 215

Basically a port of the Mathematica solution.

```
from PIL import*
b=Image.new("1",[21]*2)
b.putdata(map(int,'0'*7+bin(int('FL6IBG25C8Z00UEF53P4657DGD6HJZG41E5JOEAD1QGZ0L2XCHQGSO5R1A51V5NO4ZKW9V22OKKLG0CYMMY2',36))[2:]))
ImageOps.expand(b,5,255).save("newyear.png")

```
> 2 votes

# Answer
# HTML (Stack Snippet), 367

Edit: Oops! I forgot about the filename requirement. This makes a download link that prompts the user to download newyear.png. Due to browser security, I'm pretty sure I can't bypass that prompt.

I tested this on Firefox, but FYI, the closing `</a>` tag doesn't seem to be required for this to still work:

```
<a href="data:png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAAAs0lEQVRIie2U4QrAIAiEff+Xdn9FPD1ta7AljJHhfVqm6IsmB37gqqoiAr9on42j4RN/O64S8xVbP4KjuFvgGfQbcNY/jRt3O/ovd3tlqPHaOpW49XXWSKeEWzH2qKNkUVIpHAlnU455FTQcZVz5O31Ad7utIDpeZp+Cd2xScQpn32vWG36/Bc/8j9+5F8ygWXLtO2fg0YDZUnk1aB69cw/xPpQ8De9MMJ/cUuW77MD/B78AsoJkRZwIeDUAAAAASUVORK5CYII=" download="newyear.png">a
```

Original answer that just displays the png:

```
<img src="data:png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAAAs0lEQVRIie2U4QrAIAiEff+Xdn9FPD1ta7AljJHhfVqm6IsmB37gqqoiAr9on42j4RN/O64S8xVbP4KjuFvgGfQbcNY/jRt3O/ovd3tlqPHaOpW49XXWSKeEWzH2qKNkUVIpHAlnU455FTQcZVz5O31Ad7utIDpeZp+Cd2xScQpn32vWG36/Bc/8j9+5F8ygWXLtO2fg0YDZUnk1aB69cw/xPpQ8De9MMJ/cUuW77MD/B78AsoJkRZwIeDUAAAAASUVORK5CYII=">
```
> 1 votes

# Answer
# Common Shell tools + Imagemagick, 215

```
(echo "P1
21 21"
base64 -d<<<H95/ggoN1lduirt0VdggIP9V/ALAFMzFdVpdu/R4YeH1JSAB4H8W1goeF0JSuk+F1W1gmO/9BVA=|xxd -c99 -p|tr a-f A-F|dc -e2o16i?p|tr -d '\n\\'|fold -21)|convert -border 5 -bordercolor white - newyear.png

```

A bit convoluted, but shorter than the other shell answer.

* Base64 converts from base64 to base 256 (extended ASCII)
* xxd converts to hex
* tr makes hex uppercase, suitable for dc
* dc reads hex and prints binary string of 1s and 0s
* tr removes \ and whitespace
* fold makes lines 21 chars (21 pixels) long
* This output, along with `P1\n21 21` is the PBM P1 format
* convert (Imagemagick) converts this to .png with a 5 pixel border:
> 0 votes

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


title: Up 12 at 4 it's

text:
# Question
Title: Up 12 at 4 it's
## Introduction

On BBC Radio 2, on Saturdays there's a show hosted by Tony Blackburn called **Pick of the Pops**. Here, Tony selects a random week from a random year (in the range 1960-1989), and plays the songs which were in the top 20 charts at the time.

## Challenge

Given a list of songs played on one Pick of the Pops episode, you must determine the year which Tony has chosen.

## Further Information

### Input

The input will be given as a string (either by STDIN or function arguments), with each list item separated by a comma.

The input will sorted with the number one single first, carrying on in order until the list ends with the number 20 single.

On the actual show, Blackburn plays the charts for two different years. This will not be the case for your input, only the chart for your one year will be supplied.

If song usually has a comma in its name, then the comma will be omitted.

### Output

Your output should simply be the year in the format `YYYY` (`1989`, `2365`, `1901`).

If for any reason, multiple years are found (say if the charts are form the first week of the year), then either select the *first* year or output both, comma separated.

### Rules

You can read from either a file or the internet.

If you use the internet, you must only use pages on the website `officialcharts.com`.

***Note:* if you read from a Wikipedia page, the page must have been created before the 23rd of August 2015.**

The charts will be from the *national UK charts*, not international or of any other country.

Your output must be in the range of 1960 - 1989.

## Examples

### Input

```
Ticket to Ride,Here Comes the Night,The Minute You're Gone,Concrete and Clay,Little Things,Catch the Wind,For Your Love,King of the Road,The Last Time,Pop Go the Workers,Bring It On Home to Me,Stop in the Name of Love,Times They Are A-Changin',You're Breakin' My Heart,I Can't Explain,I'll Be There,Everybody's Gonna Be Happy,It's Not Usual,A World of Our Own,True Love Ways

```

### Output

```
1965

```

## Winning

The person with the shortest program in bytes wins.

## Note

At the moment, I'm still downloading all of the chart information, but you can use the following Python 2 code to retrieve the necessary information and create the file. (Requires the *requests* module)

```
import requests, re, datetime, time

date = datetime.date(1960,1,1)
prevyear=0
year = 1960

delay = # Set the delay yourself. So far 4 seconds still makes the download fail

while date.year != 1990:

    response = requests.get("http://www.officialcharts.com/charts/singles-chart/%d%02d%02d"%(date.year, date.month, date.day)).text
    time.sleep(delay)

    tags = re.findall("<a href=\"/search/singles/.+\">.+</a>", response)[:20]
    top20s = []

    for i in tags[:]:
        tag = re.sub("<a href=\"/search/singles/.+\">", "", i)
        tag = re.sub("</a>","",tag)
        top20s.append(tag)

    top20s = list(map(lambda x:x.replace(",",""), top20s))

    with open("songs.txt", "a") as f:
        if year != prevyear:
            string = str(year)+"\n"
        else:
            string = ""

        chart = ",".join(top20s)

        f.write(string+chart+"\n")

    prevyear = year
    date += datetime.timedelta(days=7)
    year = date.year

```

# Answer
> 2 votes
## C# (~~277, 271,~~ 223 compacted bytes)

After six years, this deserves an answer, so I'm going to make some assumptions:

* The data is stored in the file: `C:\songs.txt`.
* The songs for each week are stored on a new line in the following format:
    + `yyyy:song,song,song,...`

---

```
var @in = Console.ReadLine();
var d = File.ReadAllText(@"C:\songs.txt");
foreach (var w in d.Split('\n')) {
    var wd = w.Split(':');
    if (wd[1].Split(',').Any(a => @in.Split(',').ToList().Any(i => i.Equals(a)))) {
        Console.Write(wd[0]);
        break;
    }
}

```

---

***Note**: Compacted in this case means removing all line breaks and unnecessary whitespace. I'm retaining proper formatting for the sake of readability.*

---
Tags: code-golf
---


title: What's my PIN number?

text:
# Question
Title: What's my PIN number?
My PIN number is 1077, but that's too difficult to remember. I know from muscle memory that it's a digit, followed by a different digit, then followed by two of the same digit, which is different to the other two digits before it. As a pattern, we can say it is `ABCC` (where each letter represents a digit, and the same letter represents the same digit).

There are 15 possible PIN patterns. They are, along with some examples:

```
AAAA -> 5555    AAAB -> 7773    AABA -> 4484    AABB -> 3377    AABC -> 2265
ABAA -> 0300    ABAB -> 5252    ABAC -> 2325    ABBA -> 7667    ABBB -> 4888
ABBC -> 4880    ABCA -> 1041    ABCB -> 7080    ABCC -> 2600    ABCD -> 0857

```

You are to take 4 values as input representing the pattern of my PIN number. These values can be any reasonable value, such as the integers `1`, `2`, `3`, `4`, the letters `A`, `B`, `C`, `D` as strings, etc. You may choose what these values are, but please be mindful of this standard loophole when choosing values that aren't as simple as digits or characters.

You should then output all possible 4 digit combinations that fit the input pattern. You may output in any order, and in any format that clearly shows the 4 digits of each (so as integers doesn't work as you'll exclude leading zeros), and that clearly shows each combination together. One example could be outputting each digit separated by newlines and each combination separated by 3 newlines, or outputting a list of lists.

This is , so the shortest code in bytes wins.

## Test cases

There is a fixed set of inputs, so we can have a comprehensive set of test cases. However, the output for `ABCD` has 5040 numbers, which is rather long. This program generates the complete I/O set. Below are just the first 25 (all 10 for `AAAA`), in lexicographic order:

```
AAAA -> 0000, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999
AAAB -> 0001, 0002, 0003, 0004, 0005, 0006, 0007, 0008, 0009, 1110, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 2220, 2221, 2223, 2224, 2225, 2226, 2227
AABA -> 0010, 0020, 0030, 0040, 0050, 0060, 0070, 0080, 0090, 1101, 1121, 1131, 1141, 1151, 1161, 1171, 1181, 1191, 2202, 2212, 2232, 2242, 2252, 2262, 2272
AABB -> 0011, 0022, 0033, 0044, 0055, 0066, 0077, 0088, 0099, 1100, 1122, 1133, 1144, 1155, 1166, 1177, 1188, 1199, 2200, 2211, 2233, 2244, 2255, 2266, 2277
AABC -> 0012, 0013, 0014, 0015, 0016, 0017, 0018, 0019, 0021, 0023, 0024, 0025, 0026, 0027, 0028, 0029, 0031, 0032, 0034, 0035, 0036, 0037, 0038, 0039, 0041
ABAA -> 0100, 0200, 0300, 0400, 0500, 0600, 0700, 0800, 0900, 1011, 1211, 1311, 1411, 1511, 1611, 1711, 1811, 1911, 2022, 2122, 2322, 2422, 2522, 2622, 2722
ABAB -> 0101, 0202, 0303, 0404, 0505, 0606, 0707, 0808, 0909, 1010, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020, 2121, 2323, 2424, 2525, 2626, 2727
ABAC -> 0102, 0103, 0104, 0105, 0106, 0107, 0108, 0109, 0201, 0203, 0204, 0205, 0206, 0207, 0208, 0209, 0301, 0302, 0304, 0305, 0306, 0307, 0308, 0309, 0401
ABBA -> 0110, 0220, 0330, 0440, 0550, 0660, 0770, 0880, 0990, 1001, 1221, 1331, 1441, 1551, 1661, 1771, 1881, 1991, 2002, 2112, 2332, 2442, 2552, 2662, 2772
ABBB -> 0111, 0222, 0333, 0444, 0555, 0666, 0777, 0888, 0999, 1000, 1222, 1333, 1444, 1555, 1666, 1777, 1888, 1999, 2000, 2111, 2333, 2444, 2555, 2666, 2777
ABBC -> 0112, 0113, 0114, 0115, 0116, 0117, 0118, 0119, 0221, 0223, 0224, 0225, 0226, 0227, 0228, 0229, 0331, 0332, 0334, 0335, 0336, 0337, 0338, 0339, 0441
ABCA -> 0120, 0130, 0140, 0150, 0160, 0170, 0180, 0190, 0210, 0230, 0240, 0250, 0260, 0270, 0280, 0290, 0310, 0320, 0340, 0350, 0360, 0370, 0380, 0390, 0410
ABCB -> 0121, 0131, 0141, 0151, 0161, 0171, 0181, 0191, 0212, 0232, 0242, 0252, 0262, 0272, 0282, 0292, 0313, 0323, 0343, 0353, 0363, 0373, 0383, 0393, 0414
ABCC -> 0122, 0133, 0144, 0155, 0166, 0177, 0188, 0199, 0211, 0233, 0244, 0255, 0266, 0277, 0288, 0299, 0311, 0322, 0344, 0355, 0366, 0377, 0388, 0399, 0411
ABCD -> 0123, 0124, 0125, 0126, 0127, 0128, 0129, 0132, 0134, 0135, 0136, 0137, 0138, 0139, 0142, 0143, 0145, 0146, 0147, 0148, 0149, 0152, 0153, 0154, 0156

```

# Answer
> 12 votes
# Jelly, 8 bytes

```
⁵Œ!’³ịⱮQ

```

Times out on TIO, takes about two minutes on my machine:

```
% time python3 -m jelly eu '⁵Œ!’³ịⱮQ' "[1,2,3,1]"
[[0, 1, 2, 0], [0, 1, 3, 0], [0, 1, 4, 0], [0, 1, 5, 0], [0, 1, 6, 0], [0, 1, 7, 0], [0, 1, 8, 0], [0, 1, 9, 0], [0, 2, 1, 0], [0, 2, 3, 0], [0, 2, 4, 0], [0, 2, 5, 0], [0, 2, 6, 0], [0, 2, 7, 0], [0, 2, 8, 0], [0, 2, 9, 0], [0, 3, 1, 0], [0, 3, 2, 0], [0, 3, 4, 0], [0, 3, 5, 0], [0, 3, 6, 0], [0, 3, 7, 0], [0, 3, 8, 0], [0, 3, 9, 0], [0, 4, 1, 0], [0, 4, 2, 0], [0, 4, 3, 0], [0, 4, 5, 0], [0, 4, 6, 0], [0, 4, 7, 0], [0, 4, 8, 0], [0, 4, 9, 0], [0, 5, 1, 0], [0, 5, 2, 0], [0, 5, 3, 0], [0, 5, 4, 0], [0, 5, 6, 0], [0, 5, 7, 0], [0, 5, 8, 0], [0, 5, 9, 0], [0, 6, 1, 0], [0, 6, 2, 0], [0, 6, 3, 0], [0, 6, 4, 0], [0, 6, 5, 0], [0, 6, 7, 0], [0, 6, 8, 0], [0, 6, 9, 0], [0, 7, 1, 0], [0, 7, 2, 0], [0, 7, 3, 0], [0, 7, 4, 0], [0, 7, 5, 0], [0, 7, 6, 0], [0, 7, 8, 0], [0, 7, 9, 0], [0, 8, 1, 0], [0, 8, 2, 0], [0, 8, 3, 0], [0, 8, 4, 0], [0, 8, 5, 0], [0, 8, 6, 0], [0, 8, 7, 0], [0, 8, 9, 0], [0, 9, 1, 0], [0, 9, 2, 0], [0, 9, 3, 0], [0, 9, 4, 0], [0, 9, 5, 0], [0, 9, 6, 0], [0, 9, 7, 0], [0, 9, 8, 0], [1, 0, 2, 1], [1, 0, 3, 1], [1, 0, 4, 1], [1, 0, 5, 1], [1, 0, 6, 1], [1, 0, 7, 1], [1, 0, 8, 1], [1, 0, 9, 1], [1, 2, 0, 1], [1, 2, 3, 1], [1, 2, 4, 1], [1, 2, 5, 1], [1, 2, 6, 1], [1, 2, 7, 1], [1, 2, 8, 1], [1, 2, 9, 1], [1, 3, 0, 1], [1, 3, 2, 1], [1, 3, 4, 1], [1, 3, 5, 1], [1, 3, 6, 1], [1, 3, 7, 1], [1, 3, 8, 1], [1, 3, 9, 1], [1, 4, 0, 1], [1, 4, 2, 1], [1, 4, 3, 1], [1, 4, 5, 1], [1, 4, 6, 1], [1, 4, 7, 1], [1, 4, 8, 1], [1, 4, 9, 1], [1, 5, 0, 1], [1, 5, 2, 1], [1, 5, 3, 1], [1, 5, 4, 1], [1, 5, 6, 1], [1, 5, 7, 1], [1, 5, 8, 1], [1, 5, 9, 1], [1, 6, 0, 1], [1, 6, 2, 1], [1, 6, 3, 1], [1, 6, 4, 1], [1, 6, 5, 1], [1, 6, 7, 1], [1, 6, 8, 1], [1, 6, 9, 1], [1, 7, 0, 1], [1, 7, 2, 1], [1, 7, 3, 1], [1, 7, 4, 1], [1, 7, 5, 1], [1, 7, 6, 1], [1, 7, 8, 1], [1, 7, 9, 1], [1, 8, 0, 1], [1, 8, 2, 1], [1, 8, 3, 1], [1, 8, 4, 1], [1, 8, 5, 1], [1, 8, 6, 1], [1, 8, 7, 1], [1, 8, 9, 1], [1, 9, 0, 1], [1, 9, 2, 1], [1, 9, 3, 1], [1, 9, 4, 1], [1, 9, 5, 1], [1, 9, 6, 1], [1, 9, 7, 1], [1, 9, 8, 1], [2, 0, 1, 2], [2, 0, 3, 2], [2, 0, 4, 2], [2, 0, 5, 2], [2, 0, 6, 2], [2, 0, 7, 2], [2, 0, 8, 2], [2, 0, 9, 2], [2, 1, 0, 2], [2, 1, 3, 2], [2, 1, 4, 2], [2, 1, 5, 2], [2, 1, 6, 2], [2, 1, 7, 2], [2, 1, 8, 2], [2, 1, 9, 2], [2, 3, 0, 2], [2, 3, 1, 2], [2, 3, 4, 2], [2, 3, 5, 2], [2, 3, 6, 2], [2, 3, 7, 2], [2, 3, 8, 2], [2, 3, 9, 2], [2, 4, 0, 2], [2, 4, 1, 2], [2, 4, 3, 2], [2, 4, 5, 2], [2, 4, 6, 2], [2, 4, 7, 2], [2, 4, 8, 2], [2, 4, 9, 2], [2, 5, 0, 2], [2, 5, 1, 2], [2, 5, 3, 2], [2, 5, 4, 2], [2, 5, 6, 2], [2, 5, 7, 2], [2, 5, 8, 2], [2, 5, 9, 2], [2, 6, 0, 2], [2, 6, 1, 2], [2, 6, 3, 2], [2, 6, 4, 2], [2, 6, 5, 2], [2, 6, 7, 2], [2, 6, 8, 2], [2, 6, 9, 2], [2, 7, 0, 2], [2, 7, 1, 2], [2, 7, 3, 2], [2, 7, 4, 2], [2, 7, 5, 2], [2, 7, 6, 2], [2, 7, 8, 2], [2, 7, 9, 2], [2, 8, 0, 2], [2, 8, 1, 2], [2, 8, 3, 2], [2, 8, 4, 2], [2, 8, 5, 2], [2, 8, 6, 2], [2, 8, 7, 2], [2, 8, 9, 2], [2, 9, 0, 2], [2, 9, 1, 2], [2, 9, 3, 2], [2, 9, 4, 2], [2, 9, 5, 2], [2, 9, 6, 2], [2, 9, 7, 2], [2, 9, 8, 2], [3, 0, 1, 3], [3, 0, 2, 3], [3, 0, 4, 3], [3, 0, 5, 3], [3, 0, 6, 3], [3, 0, 7, 3], [3, 0, 8, 3], [3, 0, 9, 3], [3, 1, 0, 3], [3, 1, 2, 3], [3, 1, 4, 3], [3, 1, 5, 3], [3, 1, 6, 3], [3, 1, 7, 3], [3, 1, 8, 3], [3, 1, 9, 3], [3, 2, 0, 3], [3, 2, 1, 3], [3, 2, 4, 3], [3, 2, 5, 3], [3, 2, 6, 3], [3, 2, 7, 3], [3, 2, 8, 3], [3, 2, 9, 3], [3, 4, 0, 3], [3, 4, 1, 3], [3, 4, 2, 3], [3, 4, 5, 3], [3, 4, 6, 3], [3, 4, 7, 3], [3, 4, 8, 3], [3, 4, 9, 3], [3, 5, 0, 3], [3, 5, 1, 3], [3, 5, 2, 3], [3, 5, 4, 3], [3, 5, 6, 3], [3, 5, 7, 3], [3, 5, 8, 3], [3, 5, 9, 3], [3, 6, 0, 3], [3, 6, 1, 3], [3, 6, 2, 3], [3, 6, 4, 3], [3, 6, 5, 3], [3, 6, 7, 3], [3, 6, 8, 3], [3, 6, 9, 3], [3, 7, 0, 3], [3, 7, 1, 3], [3, 7, 2, 3], [3, 7, 4, 3], [3, 7, 5, 3], [3, 7, 6, 3], [3, 7, 8, 3], [3, 7, 9, 3], [3, 8, 0, 3], [3, 8, 1, 3], [3, 8, 2, 3], [3, 8, 4, 3], [3, 8, 5, 3], [3, 8, 6, 3], [3, 8, 7, 3], [3, 8, 9, 3], [3, 9, 0, 3], [3, 9, 1, 3], [3, 9, 2, 3], [3, 9, 4, 3], [3, 9, 5, 3], [3, 9, 6, 3], [3, 9, 7, 3], [3, 9, 8, 3], [4, 0, 1, 4], [4, 0, 2, 4], [4, 0, 3, 4], [4, 0, 5, 4], [4, 0, 6, 4], [4, 0, 7, 4], [4, 0, 8, 4], [4, 0, 9, 4], [4, 1, 0, 4], [4, 1, 2, 4], [4, 1, 3, 4], [4, 1, 5, 4], [4, 1, 6, 4], [4, 1, 7, 4], [4, 1, 8, 4], [4, 1, 9, 4], [4, 2, 0, 4], [4, 2, 1, 4], [4, 2, 3, 4], [4, 2, 5, 4], [4, 2, 6, 4], [4, 2, 7, 4], [4, 2, 8, 4], [4, 2, 9, 4], [4, 3, 0, 4], [4, 3, 1, 4], [4, 3, 2, 4], [4, 3, 5, 4], [4, 3, 6, 4], [4, 3, 7, 4], [4, 3, 8, 4], [4, 3, 9, 4], [4, 5, 0, 4], [4, 5, 1, 4], [4, 5, 2, 4], [4, 5, 3, 4], [4, 5, 6, 4], [4, 5, 7, 4], [4, 5, 8, 4], [4, 5, 9, 4], [4, 6, 0, 4], [4, 6, 1, 4], [4, 6, 2, 4], [4, 6, 3, 4], [4, 6, 5, 4], [4, 6, 7, 4], [4, 6, 8, 4], [4, 6, 9, 4], [4, 7, 0, 4], [4, 7, 1, 4], [4, 7, 2, 4], [4, 7, 3, 4], [4, 7, 5, 4], [4, 7, 6, 4], [4, 7, 8, 4], [4, 7, 9, 4], [4, 8, 0, 4], [4, 8, 1, 4], [4, 8, 2, 4], [4, 8, 3, 4], [4, 8, 5, 4], [4, 8, 6, 4], [4, 8, 7, 4], [4, 8, 9, 4], [4, 9, 0, 4], [4, 9, 1, 4], [4, 9, 2, 4], [4, 9, 3, 4], [4, 9, 5, 4], [4, 9, 6, 4], [4, 9, 7, 4], [4, 9, 8, 4], [5, 0, 1, 5], [5, 0, 2, 5], [5, 0, 3, 5], [5, 0, 4, 5], [5, 0, 6, 5], [5, 0, 7, 5], [5, 0, 8, 5], [5, 0, 9, 5], [5, 1, 0, 5], [5, 1, 2, 5], [5, 1, 3, 5], [5, 1, 4, 5], [5, 1, 6, 5], [5, 1, 7, 5], [5, 1, 8, 5], [5, 1, 9, 5], [5, 2, 0, 5], [5, 2, 1, 5], [5, 2, 3, 5], [5, 2, 4, 5], [5, 2, 6, 5], [5, 2, 7, 5], [5, 2, 8, 5], [5, 2, 9, 5], [5, 3, 0, 5], [5, 3, 1, 5], [5, 3, 2, 5], [5, 3, 4, 5], [5, 3, 6, 5], [5, 3, 7, 5], [5, 3, 8, 5], [5, 3, 9, 5], [5, 4, 0, 5], [5, 4, 1, 5], [5, 4, 2, 5], [5, 4, 3, 5], [5, 4, 6, 5], [5, 4, 7, 5], [5, 4, 8, 5], [5, 4, 9, 5], [5, 6, 0, 5], [5, 6, 1, 5], [5, 6, 2, 5], [5, 6, 3, 5], [5, 6, 4, 5], [5, 6, 7, 5], [5, 6, 8, 5], [5, 6, 9, 5], [5, 7, 0, 5], [5, 7, 1, 5], [5, 7, 2, 5], [5, 7, 3, 5], [5, 7, 4, 5], [5, 7, 6, 5], [5, 7, 8, 5], [5, 7, 9, 5], [5, 8, 0, 5], [5, 8, 1, 5], [5, 8, 2, 5], [5, 8, 3, 5], [5, 8, 4, 5], [5, 8, 6, 5], [5, 8, 7, 5], [5, 8, 9, 5], [5, 9, 0, 5], [5, 9, 1, 5], [5, 9, 2, 5], [5, 9, 3, 5], [5, 9, 4, 5], [5, 9, 6, 5], [5, 9, 7, 5], [5, 9, 8, 5], [6, 0, 1, 6], [6, 0, 2, 6], [6, 0, 3, 6], [6, 0, 4, 6], [6, 0, 5, 6], [6, 0, 7, 6], [6, 0, 8, 6], [6, 0, 9, 6], [6, 1, 0, 6], [6, 1, 2, 6], [6, 1, 3, 6], [6, 1, 4, 6], [6, 1, 5, 6], [6, 1, 7, 6], [6, 1, 8, 6], [6, 1, 9, 6], [6, 2, 0, 6], [6, 2, 1, 6], [6, 2, 3, 6], [6, 2, 4, 6], [6, 2, 5, 6], [6, 2, 7, 6], [6, 2, 8, 6], [6, 2, 9, 6], [6, 3, 0, 6], [6, 3, 1, 6], [6, 3, 2, 6], [6, 3, 4, 6], [6, 3, 5, 6], [6, 3, 7, 6], [6, 3, 8, 6], [6, 3, 9, 6], [6, 4, 0, 6], [6, 4, 1, 6], [6, 4, 2, 6], [6, 4, 3, 6], [6, 4, 5, 6], [6, 4, 7, 6], [6, 4, 8, 6], [6, 4, 9, 6], [6, 5, 0, 6], [6, 5, 1, 6], [6, 5, 2, 6], [6, 5, 3, 6], [6, 5, 4, 6], [6, 5, 7, 6], [6, 5, 8, 6], [6, 5, 9, 6], [6, 7, 0, 6], [6, 7, 1, 6], [6, 7, 2, 6], [6, 7, 3, 6], [6, 7, 4, 6], [6, 7, 5, 6], [6, 7, 8, 6], [6, 7, 9, 6], [6, 8, 0, 6], [6, 8, 1, 6], [6, 8, 2, 6], [6, 8, 3, 6], [6, 8, 4, 6], [6, 8, 5, 6], [6, 8, 7, 6], [6, 8, 9, 6], [6, 9, 0, 6], [6, 9, 1, 6], [6, 9, 2, 6], [6, 9, 3, 6], [6, 9, 4, 6], [6, 9, 5, 6], [6, 9, 7, 6], [6, 9, 8, 6], [7, 0, 1, 7], [7, 0, 2, 7], [7, 0, 3, 7], [7, 0, 4, 7], [7, 0, 5, 7], [7, 0, 6, 7], [7, 0, 8, 7], [7, 0, 9, 7], [7, 1, 0, 7], [7, 1, 2, 7], [7, 1, 3, 7], [7, 1, 4, 7], [7, 1, 5, 7], [7, 1, 6, 7], [7, 1, 8, 7], [7, 1, 9, 7], [7, 2, 0, 7], [7, 2, 1, 7], [7, 2, 3, 7], [7, 2, 4, 7], [7, 2, 5, 7], [7, 2, 6, 7], [7, 2, 8, 7], [7, 2, 9, 7], [7, 3, 0, 7], [7, 3, 1, 7], [7, 3, 2, 7], [7, 3, 4, 7], [7, 3, 5, 7], [7, 3, 6, 7], [7, 3, 8, 7], [7, 3, 9, 7], [7, 4, 0, 7], [7, 4, 1, 7], [7, 4, 2, 7], [7, 4, 3, 7], [7, 4, 5, 7], [7, 4, 6, 7], [7, 4, 8, 7], [7, 4, 9, 7], [7, 5, 0, 7], [7, 5, 1, 7], [7, 5, 2, 7], [7, 5, 3, 7], [7, 5, 4, 7], [7, 5, 6, 7], [7, 5, 8, 7], [7, 5, 9, 7], [7, 6, 0, 7], [7, 6, 1, 7], [7, 6, 2, 7], [7, 6, 3, 7], [7, 6, 4, 7], [7, 6, 5, 7], [7, 6, 8, 7], [7, 6, 9, 7], [7, 8, 0, 7], [7, 8, 1, 7], [7, 8, 2, 7], [7, 8, 3, 7], [7, 8, 4, 7], [7, 8, 5, 7], [7, 8, 6, 7], [7, 8, 9, 7], [7, 9, 0, 7], [7, 9, 1, 7], [7, 9, 2, 7], [7, 9, 3, 7], [7, 9, 4, 7], [7, 9, 5, 7], [7, 9, 6, 7], [7, 9, 8, 7], [8, 0, 1, 8], [8, 0, 2, 8], [8, 0, 3, 8], [8, 0, 4, 8], [8, 0, 5, 8], [8, 0, 6, 8], [8, 0, 7, 8], [8, 0, 9, 8], [8, 1, 0, 8], [8, 1, 2, 8], [8, 1, 3, 8], [8, 1, 4, 8], [8, 1, 5, 8], [8, 1, 6, 8], [8, 1, 7, 8], [8, 1, 9, 8], [8, 2, 0, 8], [8, 2, 1, 8], [8, 2, 3, 8], [8, 2, 4, 8], [8, 2, 5, 8], [8, 2, 6, 8], [8, 2, 7, 8], [8, 2, 9, 8], [8, 3, 0, 8], [8, 3, 1, 8], [8, 3, 2, 8], [8, 3, 4, 8], [8, 3, 5, 8], [8, 3, 6, 8], [8, 3, 7, 8], [8, 3, 9, 8], [8, 4, 0, 8], [8, 4, 1, 8], [8, 4, 2, 8], [8, 4, 3, 8], [8, 4, 5, 8], [8, 4, 6, 8], [8, 4, 7, 8], [8, 4, 9, 8], [8, 5, 0, 8], [8, 5, 1, 8], [8, 5, 2, 8], [8, 5, 3, 8], [8, 5, 4, 8], [8, 5, 6, 8], [8, 5, 7, 8], [8, 5, 9, 8], [8, 6, 0, 8], [8, 6, 1, 8], [8, 6, 2, 8], [8, 6, 3, 8], [8, 6, 4, 8], [8, 6, 5, 8], [8, 6, 7, 8], [8, 6, 9, 8], [8, 7, 0, 8], [8, 7, 1, 8], [8, 7, 2, 8], [8, 7, 3, 8], [8, 7, 4, 8], [8, 7, 5, 8], [8, 7, 6, 8], [8, 7, 9, 8], [8, 9, 0, 8], [8, 9, 1, 8], [8, 9, 2, 8], [8, 9, 3, 8], [8, 9, 4, 8], [8, 9, 5, 8], [8, 9, 6, 8], [8, 9, 7, 8], [9, 0, 1, 9], [9, 0, 2, 9], [9, 0, 3, 9], [9, 0, 4, 9], [9, 0, 5, 9], [9, 0, 6, 9], [9, 0, 7, 9], [9, 0, 8, 9], [9, 1, 0, 9], [9, 1, 2, 9], [9, 1, 3, 9], [9, 1, 4, 9], [9, 1, 5, 9], [9, 1, 6, 9], [9, 1, 7, 9], [9, 1, 8, 9], [9, 2, 0, 9], [9, 2, 1, 9], [9, 2, 3, 9], [9, 2, 4, 9], [9, 2, 5, 9], [9, 2, 6, 9], [9, 2, 7, 9], [9, 2, 8, 9], [9, 3, 0, 9], [9, 3, 1, 9], [9, 3, 2, 9], [9, 3, 4, 9], [9, 3, 5, 9], [9, 3, 6, 9], [9, 3, 7, 9], [9, 3, 8, 9], [9, 4, 0, 9], [9, 4, 1, 9], [9, 4, 2, 9], [9, 4, 3, 9], [9, 4, 5, 9], [9, 4, 6, 9], [9, 4, 7, 9], [9, 4, 8, 9], [9, 5, 0, 9], [9, 5, 1, 9], [9, 5, 2, 9], [9, 5, 3, 9], [9, 5, 4, 9], [9, 5, 6, 9], [9, 5, 7, 9], [9, 5, 8, 9], [9, 6, 0, 9], [9, 6, 1, 9], [9, 6, 2, 9], [9, 6, 3, 9], [9, 6, 4, 9], [9, 6, 5, 9], [9, 6, 7, 9], [9, 6, 8, 9], [9, 7, 0, 9], [9, 7, 1, 9], [9, 7, 2, 9], [9, 7, 3, 9], [9, 7, 4, 9], [9, 7, 5, 9], [9, 7, 6, 9], [9, 7, 8, 9], [9, 8, 0, 9], [9, 8, 1, 9], [9, 8, 2, 9], [9, 8, 3, 9], [9, 8, 4, 9], [9, 8, 5, 9], [9, 8, 6, 9], [9, 8, 7, 9]]
108.00s user 0.90s system 99% cpu 1:49.73 total

```

Accepts a pattern in the format `[1,2,2,3]`.

```
⁵Œ!’        All permutations of [0..9].
     ³ịⱮ    For each such permutation, use the input as index vector:
              e.g. for input [1,2,2,3], turn 3862149075 into 3886.
        Q   Eliminate duplicates.

```

# Answer
> 5 votes
# Factor \+ `math.combinatorics`, 50 bytes

```
[ 10 iota [ nths ] with map-permutations members ]

```

Try it online!

Port of @Lynn's Jelly answer.

* `10 iota` The digits from 0 to 9.
* `[ ... ] with` Include the input in a quotation.
* `[ nths ] map-permutations` Map the permutations of 0-9 to the indices given by the input.
* `members` Remove duplicates.

# Answer
> 4 votes
# Python 3, 86 bytes

```
lambda*r:{eval('x[%d],'*4%r)for x in permutations(range(10),5)}
from itertools import*

```

Try it online!

Fix and -3 thanks to @dingledooper

-2 thanks to @tsh

(`f()` outputs unsorted list, so footer code is added to display sorted and joined by newlines)

Very fast. Fixed time complexity of \\$O(120960) = O(10P5×4)\\$, it could be \\$6×\\$ faster if we could take input numbers decremented by 1.

# Answer
> 3 votes
# , 27 24 23 bytes

```
(-:&="1#])&(>,{4$<i.10)

```

Try it online!

* `(>,{4$<i.10)` Generates all 10K pins.
* `-:&="1#]` Filter those by equality to the input after transforming both by "Self Classify" `=`. Self classify gives a boolean signature for each unique member of a list, thereby encoding the "mask" that we're trying to match. Eg, `= 'AABC'` returns:

```
1 1 0 0
0 0 1 0
0 0 0 1

```

### bonus

`[:~.]{"1(i.@!A.i.)@10` for 21 bytes using Lynn's clever approach. Executes decently fast.

# Answer
> 3 votes
# Vyxal, 8 bytes

```
9ʀṖƛ?İ;U

```

Try it Online!

Will time out. (But work in theory, because taking 0..n (n\<9) permutations finish properly in time)

```
9ʀṖ                     # 0..9 permutations
       ƛ                  # For each
             ?İ          #  Index with input
                ;U      # Close and remove duplicates

```

# Answer
> 3 votes
# \>= 4.1 plus gtools, 41 bytes

```
\(x)gtools::permutations(10,max(x))[,x]-1

```

Try it online!

A function that takes a vector of integers and returns a matrix with the PINs in rows and the digits in columns. It would be nice to have a base R equivalent of `combn` for permutations.

Thanks to @Mark for pointing out the flaw in my previous answer which did permutations with replacement rather than without.

# Answer
> 2 votes
# Jelly, 11 bytes

```
Ġ⁵ṗ4¤ĠṢ⁼ɗƇ’

```

Try it online!

Works equally well when given a list of digits (`[1, 2, 3, 4]`) or a string (`"ABCD"`).

### How it works

```
Ġ⁵ṗ4¤ĠṢ⁼ɗƇ’    Monadic link. Left arg: PIN pattern
Ġ              Group indices by identical values
               (which gives the pattern to filter the combinations for)
 ⁵ṗ4¤ĠṢ⁼ɗƇ     Monad-dyad pair:
 ⁵ṗ4¤          Create a list of 4-digit combinations using 1-10
         Ƈ     Filter from the above list by:
     ĠṢ⁼ɗ        Is the list of sorted groups identical to the input's?
          ’    Decrement to get a list of 0-9 combinations

```

# Answer
> 2 votes
# Jelly (fork), 8 bytes

```
9Żṗ4Qi$Ƙ

```

Try it online! (my original Jelly answer)

Didn't take long for Lynn to outgolf my original Jelly answer, so I thought I'd show my approach, using my fork because `⁼¥Ƈ` annoys me.

## How it works

```
9Żṗ4Qi$Ƙ - Main link. Takes [a,b,c,d] on the left
9Ż       - Zero-range of 9; Yield [0,1,2,3,4,5,6,7,8,9]
  ṗ4     - Fourth cartesian power; All length-4 lists with elements from that range
      $Ƙ - Keep those elements [x,y,z,w] for which the following equals [a,b,c,d]:
    Q    -   Unique elements
     i   -   Their indices in [x,y,z,w]

```

In this case, `i` in my fork has been modified so that using it on flat lists is equivalent to `iⱮ`, as otherwise it outputs `0` (not found): Try it online! Additionally, `Ƙ` has been added to supplant `⁼¥Ƈ` as it gets used a lot.

# Answer
> 2 votes
# 05AB1E, 8 bytes

```
9Ýœε¹è}Ù

```

Try it online!

-2 Thanks to @ovs

# Answer
> 2 votes
# Jelly, 8 bytes

```
Ṁ⁵œ!’ị@€

```

Try it online!

Another Jelly 8-byter. This works similarly to my R answer, and completes quickly on TIO.

```
Ṁ        | Max
 ⁵œ!     | Permutations of (10, max(x))
    ’    | Decrease by 1
     ị@€ | Index original argument into each permutation

```

# Answer
> 2 votes
# Japt, 10 bytes

Input is an array of integers `1-4`. Output is an array of integer arrays. Careful running this one; even with all 4 input integers the same, it takes about 10.5 seconds to complete.

```
Ao á mgU â

```

Try it (Limits the lengths of the permutations to 4)

```
Ao á mgU â     :Implicit input of array U
A              :10
 o             :Range [0,A)
   á           :Permutations
     m         :Map
      gU       :  Get elements at 0-based indices in U
         â     :Deduplicate

```

# Answer
> 2 votes
# Google Sheets, ~~366 354 352 301 203~~ 189

Ending parens discounted.

## Setup

* Input: A1, (any format)
* A2: Cache every relevant character comparison result

```
=ArrayFormula(MID(A1,{1;2;3},1)=MID(A1,{2,3,4},1))

```
* E1:

```
=SEQUENCE(1e4,1,)

```
* Set Column E to format all 4 digits. (Custom format `0000`. We'll add +4 for this)
* F1: Split digits into columns

```
=ArrayFormula(MID(E:E,{1,2,3,4},1))

```
* J1 (result):

```
=FILTER(E:E,(F:F=G:G=A2)*(F:F=H:H=B2)*(F:F=I:I=C2)*(G:G=H:H=B3)*(G:G=I:I=C3)*(H:H=I:I=C4))

```

## Notes

* At a high level, it enumerates all possible PINs with `SEQUENCE`, then applies several filter conditions to remove unwanted result.
* Each filter condition checks PINs that either both match or both don't match in the corresponding places (`=` is like `XNOR` in that regard)
* `*` acts like and `AND`

# Answer
> 1 votes
# JavaScript (V8), 87 bytes

Expects a pattern made of non-digit characters. Prints the results.

```
f=(s,m=/\D/.exec(s),g=n=>n--&&g(n,s.match(n)||f(s.split(m).join(n))))=>m?g(10):print(s)

```

Try it online!

---

# JavaScript (ES10), 100 bytes

Expects a pattern made of `1`, `2`, `3`, `4`. Returns an array of strings.

```
s=>[...Array(x=1e4)].flatMap(_=>(S=`${x++}`.slice(-4)).replace(o=/./g,c=>o[c]=o[c]||++n,n=0)^s?[]:S)

```

Try it online!

# Answer
> 1 votes
# JavaScript (browser), 83 bytes

```
p=>{for(i=1e5;i++<2e5;)/.(.).*\1/.test(i+=n='')?0:p[p.map(v=>n+=i[v])]??=+alert(n)}

```

```
f =

p=>{for(i=1e5;i++<2e5;)/.(.).*\1/.test(i+=n='')?0:p[p.map(v=>n+=i[v])]??=+alert(n)}

alert = s => output.textContent += s + '\n'

f([1,1,1,1])
alert('----')
f([1,1,1,2])
```

```
<output id=output style=white-space:pre></output>
```

Input an array of 4 numbers, each number in range 1 to 4, `f([1, 2, 3, 4])` for example.

# Answer
> 1 votes
# Charcoal, 29 bytes

```
ＥΦＥＸχ⊕⌈θ⭆◧Ｉι⊕⌈θΣλ⬤ι⁼¹№ιλ⭆θ§ιλ

```

Try it online! Link is to verbose version of code. Takes input as a list of 0-indexed digits. Explanation:

```
    χ                           Predefined variable 10
   Ｘ                            Raised to power
       θ                        Input array
      ⌈                         Maximum
     ⊕                          Incremented
  Ｅ                             Map over implicit range
            ι                    Current value
           Ｉ                     Cast to string
          ◧                      Left padded to length
               θ                 Input array
              ⌈                  Maximum
             ⊕                   Incremented
         ⭆                       Map over characters and join
                 λ               Current character
                Σ                Numeric value or 0 for space
 Φ                               Filtered where
                   ι             Current string
                  ⬤              All digits satisfy
                      №          Count of
                        λ        Current digit
                       ι         In current string
                    ⁼            Is equal to
                     ¹           Literal `1`
Ｅ                                Map over strings
                          θ      Input array
                         ⭆       Map over values and join
                            ι    Current string
                           §     Indexed by
                             λ   Current value
                                 Implicitly print

```

# Answer
> 1 votes
# PHP, 128 bytes

```
for(;$n<1e4;){$s=sprintf('%04d',$n++);$m='';$l=A;$v=[];for($d=0;$d<4;)$m.=$v[$g=$s[$d++]]??$v[$g]=$l++;$m==$argn&&print($s.~_);}

```

Try it online!

# Answer
> 1 votes
# Pyth, 8 bytes

Two solutions:

```
{@LRQ.pT
{C@RR.pT

```

Try it online!

Standard method - index into permutations of `[0, 1, ..., 9]`.

Try it online!

Reverse the order of indexing - generate separate lists of all 0th, 1st, etc. elements of the permutations, then transpose.

# Answer
> 1 votes
# Python 3.8 (pre-release), ~~87~~ 85 bytes

-2 thanks to @ovs

```
lambda s:[c for i in range(10000)if len({*s})==len({*zip(s,c:='%04i'%i)})==len({*c})]

```

Try it online!

# Answer
> 0 votes
# Perl 5, 107 bytes

```
sub{my%s;my$r;$r.=$s{$_}++?"\\$_":'((?!'.join('|',map"\\$_",1..keys%s).')\d)'for@_;grep/$r/,'0000'..'9999'}

```

Try it online!

---
Tags: code-golf, array, combinatorics
---


title: Assembly Language Quine

text:
# Question
Title: Assembly Language Quine
Write the shortest possible assembly-language quine.

Use any ISA you want, unless it has a `print-quine` instruction or equivalent. Examples include x86, MIPS, SPARC, MMIX, IBM BAL, MIX, VAX, JVM, ARM, etc.

You may link against the C standard library's `_printf` function (or the Java equivalent for JVM bytecode) for I/O.

Length will be judged both on instruction count and size of the data segment. Solutions must contain at least two instructions.

The quine should print the *assembly* code, not the assembled machine code.

# Answer
> 24 votes
## x86 Linux, AT&T syntax: 244

```
push $10
push $34
push $s
push $34
push $37
push $37
push $s
call printf
mov $0,%ebx
mov $1,%eax
int $128
s:.ascii "push $10
push $34
push $s
push $34
push $37
push $37
push $s
call printf
mov $0,%cebx
mov $1,%ceax
int $128
s:.ascii %c%s%c%c"

```

(I compiled it with this: `gcc -nostartfiles -lc quine.S -o quine`)

# Answer
> 8 votes
# gas for x86 Linux (~~89~~ 88 bytes, seven instructions)

Technically, this is cheating.

```
mov $4,%al
mov $1,%bl
mov $b,%ecx
mov $89,%dl
int $128
mov $1,%al
int $128
b:.incbin"a"

```

Save in a file named `a` and assemble with the following commands to create the executable named `a.out`.

```
as -o a.o <a ; ld a.o

```

The directive `.incbin` includes a file verbatim at the current location. If you use this to include the source code itself, you get a nice quine.

# Answer
> 7 votes
### JVM Bytecode Assembly (via Jasmin) – 952 ~~960~~ ~~990~~

```
.class public Q
.super java/io/File
.method public static main([Ljava/lang/String;)V
.limit stack 9
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc ".class public Q%n.super java/io/File%n.method public static main([Ljava/lang/String;)V%n.limit stack 9%ngetstatic java/lang/System/out Ljava/io/PrintStream;%nldc %c%s%c%nldc 3%nanewarray java/lang/Object%ndup%ndup%nldc 0%nldc 34%ninvokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;%ndup_x2%naastore%nldc 2%nswap%naastore%ndup2%nswap%nldc 1%nswap%naastore%ninvokevirtual java/io/PrintStream/printf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream;%npop%nreturn%n.end method"
ldc 3
anewarray java/lang/Object
dup
dup
ldc 0
ldc 34
invokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;
dup_x2
aastore
ldc 2
swap
aastore
dup2
swap
ldc 1
swap
aastore
invokevirtual java/io/PrintStream/printf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream;
pop
return
.end method

```

Sadly, Jasmin doesn't allow as many nice tricks as Microsoft's `ilasm` allows. But the JVM has a total of *six* different `dup` instructions that do all kinds of fun things. Reordering items on the stack is something .NET doesn't seem to support.

In any case, I guess none of my two entries are serious contenders for shortest code but I guess it's hard to make them much shorter. Therefore just for completeness :-)

Commented version with info about what's on the stack:

```
.class public Q
.super java/io/File
.method public static main([Ljava/lang/String;)V
.limit stack 9
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc ".class public Q%n.super java/io/File%n.method public static main([Ljava/lang/String;)V%n.limit stack 9%ngetstatic java/lang/System/out Ljava/io/PrintStream;%nldc %c%s%c%nldc 3%nanewarray java/lang/Object%ndup%ndup%nldc 0%nldc 34%ninvokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;%ndup_x2%naastore%nldc 2%nswap%naastore%ndup2%nswap%nldc 1%nswap%naastore%ninvokevirtual java/io/PrintStream/printf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream;%npop%nreturn%n.end method"
ldc 3       ; stack; System.out, string, 3
anewarray java/lang/Object    ; stack: System.out, string, Object[3]
dup
dup    ; stack: System.out, string, array, array, array
ldc 0  ; stack: System.out, string, array, array, array, 0
ldc 34   ; stack: System.out, string, array, array, array, 0, 34
invokestatic java/lang/Integer/valueOf(I)Ljava/lang/Integer;
dup_x2   ; stack: System.out, string, array, array, 34, array, 0, 34
aastore  ; stack: System.out, string, array, array, 34
ldc 2    ; stack: System.out, string, array, array, 34, 2
swap     ; stack: System.out, string, array, array, 2, 34
aastore  ; stack: System.out, string, array
dup2     ; stack: System.out, string, array, string, array
swap     ; stack: System.out, string, array, array, string
ldc 1    ; stack: System.out, string, array, array, string, 1
swap     ; stack: System.out, string, array, array, 1, string
aastore  ; stack: System.out, string, array
invokevirtual java/io/PrintStream/printf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/io/PrintStream;
pop
return
.end method

```

**History:**

* 2011-02-07 02:09 (990) – First working version.
* 2011-02-07 02:11 (960) – `ldc` is shorter than `bipush` or `iconst_*`.
* 2011-02-07 02:30 (952) – Who says I need to inherit from java.lang.Object? Other class names are so much shorter :-)

# Answer
> 6 votes
# GAS x86-64 for Linux (verified on GCC 10.1):

## ~~13 12~~ 5 instructions

## ~~148 136 129~~ 0 byte data section

### ~~298 274 260 51~~ 49 byte source code

Self-imposed rules/assumptions:

1. No standard library (including `printf` and `main`) allowed.
2. No `.incbin` allowed. This is commonly considered input in quine challenges.
3. In a similar vein, I disallowed using the `-D` flag as this would likely trivialize the problem as well as any file-content accessing flags. All other flags are fair game.
4. If it's loaded in program memory, it's fair game. As long as no files are accessed.

```
lea .+174,%rsi;inc %di;lea 49,%dx;inc %ax;syscall

```

### Annotated version:

```
// We rely on Linux initializing all GP registers to 0.

// The filename is loaded into memory at this location:
lea .+174,%rsi
inc %di
// Length
lea 49,%dx
inc %ax
// Write string
syscall
// Since there are no valid instructions after this, it crashes.
// Since Segfault info is not program output, we're good.

```

The ELF has no ".data" section. The program reads from the ".debug\_line" section as if it were one, so that's why it's 0 bytes. This requires some setup.

### The ~~Hacks~~ ~~Voodoo Magic~~ Setup

Save the file as `lea .+174,%rsi;inc %di;lea 49,%dx;inc %ax;syscall.sx` (ie, source + `.sx`) and compile with:

```
% qFile='lea .+174,%rsi;inc %di;lea 49,%dx;inc %ax;syscall.sx'
% gcc -g1 -nostdlib -no-pie $qFile -o quine

```

Explanation:

* `-g1` adds debugging info to ELF, which handily injects the filename too! This also means it gets loaded into memory at runtime!
* `-no-pie` is required for two reasons:
    1. We want to load a non-RIP-relative address
    2. The debugging info doesn't get ASLR'ed away.
* `-nostdlib` means we don't have to use `main`.

Verify with diff:

```
% ./quine > quineresult.sx; diff $qFile quineresult.sx
[1]    52466 segmentation fault (core dumped)  ./quine > quineresult.sx

```

The filename is not part of the true source code, as it is not part of the file's contents, which is why I only output this source one time. I originally penalized my source code because the filename is vital to the quine, but I realized that this was moot because the rules aren't scoring on source code size anyway. I guess this means I beat the accepted answer without `printf`!

# Answer
> 4 votes
## Windows .COM Format: 307 characters

Assembles, using A86, to 51 bytes. Requires no external libraries other than the DOS Int21 AH=9 function (write string to stdout).

```
db 185
db  51
db   0
db 190
db   0
db   1
db 191
db  47
db   1
db 172
db 178
db  10
db 199
db   6
db  45
db   1
db  32
db  32
db 180
db   0
db 246
db 242
db 128
db 196
db  48
db 136
db  37
db  79
db  10
db 192
db 117
db 242
db 180
db   9
db 186
db  42
db   1
db 205
db  33
db 226
db 221
db 195
db 100
db  98
db  32
db  32
db  51
db  49
db  10
db  13
db  36

```

# Answer
> 4 votes
# NASM, 223 bytes

```
%define a "%define "
%define b "db "
%define c "%deftok "
%define d "a, 97, 32, 34, a, 34, 10, a, 98, 32, 34, b, 34, 10, a, 99, 32, 34, c, 34, 10, a, 100, 32, 34, d, 34, 10, c, 101, 32, 100, 10, b, 101, 10"
%deftok e d
db e

```

Beating the accepted answer!

# Answer
> 3 votes
### .NET CIL – 623 ~~669~~ ~~691~~ ~~723~~ ~~727~~

```
.assembly H{}.method void M(){.entrypoint.locals init(string)ldstr".assembly H{0}{1}.method void M(){0}.entrypoint.locals init(string)ldstr{2}{3}{2}stloc 0ldloc 0ldc.i4 4newarr object dup dup dup dup ldc.i4 0ldstr{2}{0}{2}stelem.ref ldc.i4 1ldstr{2}{1}{2}stelem.ref ldc.i4 2ldc.i4 34box char stelem.ref ldc.i4 3ldloc 0stelem.ref call void[mscorlib]System.Console::Write(string,object[])ret{1}"stloc 0ldloc 0ldc.i4 4newarr object dup dup dup dup ldc.i4 0ldstr"{"stelem.ref ldc.i4 1ldstr"}"stelem.ref ldc.i4 2ldc.i4 34box char stelem.ref ldc.i4 3ldloc 0stelem.ref call void[mscorlib]System.Console::Write(string,object[])ret}

```

A single line, no line break at the end.

Formatted and commented first version (even though it isn't a quine anymore) – it's unlikely that I deviate much from the general concept:

```
.assembly H{}
.method void M() {
  .entrypoint
  .locals init (
    string,
    object[]
  )
  // the string
  ldstr".assembly H{0}{1}.method void M(){0}.entrypoint.locals init(string,object[])ldstr{2}{3}{2}stloc.0 ldloc.0 ldc.i4.4 newarr object stloc.1 ldloc.1 ldc.i4.0 ldstr{2}{0}{2} stelem.ref ldloc.1 ldc.i4.1 ldstr{2}{1}{2} stelem.ref ldloc.1 ldc.i4.2 ldc.i4 34 box char stelem.ref ldloc.1 ldc.i4.3 ldloc.0 stelem.ref ldloc.1 call void[mscorlib]System.Console::Write(string,object[])ret{1}"
  stloc.0   // store in first local var
  ldloc.0   // load again. Going to be the first argument to Console::Write
  ldc.i4.4 newarr object stloc.1   // create new array and store in local var
  ldloc.1 ldc.i4.0 ldstr"{" stelem.ref   // we need a literal brace
  ldloc.1 ldc.i4.1 ldstr"}" stelem.ref   // closing, too
  ldloc.1 ldc.i4.2 ldc.i4 34 box char stelem.ref   // double quote
  ldloc.1 ldc.i4.3 ldloc.0 stelem.ref   // our format string from before
  ldloc.1 // load array
  call void[mscorlib]System.Console::Write(string,object[]) // output
  ret
}

```

**History**:

* 2011-02-06 16:48 (727) – First working version.
* 2011-02-06 17:14 (723) – I don't need a space after a string literal.
* 2011-02-06 17:21 (691) – `dup` is shorter than writing `ldloc.1` every time.
* 2011-02-06 17:24 (669) – I don't need spaces after *any* literal and things like `ldloc.1` can be written as `ldloc 1` to make the last token a literal. The resulting bytecode is likely larger, but it's about the assembler code so I couldn't care less :-)
* 2011-02-06 17:34 (623) – I don't need the `object[]` as a local variable; I can do all that on the stack directly. Nice.

# Answer
> 3 votes
# gas for x86 Linux, ~~184~~ 176 bytes

```
.globl main
main:movw $34,B+87
push $B
call printf
call printf
pop B
ret
.data
B:.ascii".globl main
main:movw $34,B+87
push $B
call printf
call printf
pop B
ret
.data
B:.ascii"

```

Build with `gcc -m32 -o a.out quine.S`. (The `-m32` is optional if your OS is already 32-bit.)

**Edited to add:** If we modify the rules to allow `puts` to be called instead of `printf` then it can be done in ~~182~~ 174 bytes:

```
.globl main
main:movw $34,B+86
push $B+1
call puts
call puts
pop B
ret
.data
B:.ascii"
.globl main
main:movw $34,B+86
push $B+1
call puts
call puts
pop B
ret
.data
B:.ascii"

```

(Note that this one, unlike the previous one, has a terminating newline.)

# Answer
> 3 votes
# Bootable ASM, 660 bytes

```
[bits 16]
mov ax,07C0h
mov ds,ax
mov ah,0
mov al,03h
int 10h
mov si,code
call p
jmp $
p:mov ah,0Eh
r:lodsb
cmp al,0
je d
cmp bx,0x42
jne s
c:int 10h
jmp r
s: cmp al,94
je re
cmp al,63
je q
jmp c
q:mov al,34
jmp c
re:push si
mov bx,0x42
mov si,code
call p
mov bx,0
pop si
jmp p
d:ret
code:db "[bits 16]\mov ax,07C0h\mov ds,ax\mov ah,0\mov al,03h\int 10h\mov si,code\call p\jmp $\p:mov ah,0Eh\r:lodsb\cmp al,0\je d\cmp bx,0x42\jne s\c:int 10h\jmp r\s:cmp al,94\je re\cmp al,63\je q\jmp c\q:mov al,34\jmp c\re:push si\mov bx,0x42\mov si,code\call p\mov bx,0\pop si\jmp p\\d:ret\\code:db ?^?\times 510-($-$$) db 0\dw 0xAA55"
times 510-($-$$) db 0
dw 0xAA55

```

Originally by jdiez17, golfed by yours truly.

# Answer
> 1 votes
## x86-64, System V AMD64 ABI, GASM: 432

```
.att_syntax noprefix
.globl main
main:
pushq rbp
movq rsp, rbp
mov $.Cs, rdi
mov $0xa, rsi
mov $0x22, edx
mov $.Cs, ecx
mov $0x22, r8d
mov $0xa, r9d
xor eax, eax
call printf
xor eax, eax
leave
ret
.Cs: .string ".att_syntax noprefix
.globl main
main:
pushq rbp
movq rsp, rbp
mov $.Cs, rdi
mov $0xa, rsi
mov $0x22, edx
mov $.Cs, ecx
mov $0x22, r8d
mov $0xa, r9d
xor eax, eax
call printf
xor eax, eax
leave
ret%c.Cs: .string %c%s%c%c"

```

# Answer
> 1 votes
# 80x86 TASM, 561 bytes

```
MODEL TINY
.CODE
.STARTUP
DB 177
DB 076
DB 186
DB 044
DB 001
DB 172
DB 180
DB 036
DB 179
DB 004
DB 191
DB 080
DB 001
DB 079
DB 136
DB 037
DB 212
DB 010
DB 004
DB 048
DB 134
DB 196
DB 075
DB 117
DB 244
DB 180
DB 009
DB 205
DB 033
DB 178
DB 071
DB 226
DB 228
DB 178
DB 038
DB 205
DB 033
DB 195
DB 013
DB 010
DB 069
DB 078
DB 068
DB 036
DB 077
DB 079
DB 068
DB 069
DB 076
DB 032
DB 084
DB 073
DB 078
DB 089
DB 013
DB 010
DB 046
DB 067
DB 079
DB 068
DB 069
DB 013
DB 010
DB 046
DB 083
DB 084
DB 065
DB 082
DB 084
DB 085
DB 080
DB 013
DB 010
DB 068
DB 066
DB 032
END

```

# Answer
> 1 votes
I wrote this in assembly on paper and assembled it into machine code by hand with an opcode chart. I then entered the machine code into the program editor on the TI-84 Plus CE and executed it with asm(. It starts at it's own load address, copies that byte into the accumulator, then makes a system call that prints the contents of the accumulator in ascii on the display and repeats for every byte of the program, essentially printing it's own machine code.... Is it technically a quine because I didn't use a computer to assemble it and because the exact code I entered into the calculator is printed by the program itself?

This is ez80 machine language on a TI-84 Plus CE:

34 bytes. First byte loads @ D1A881, whitespace ignored:

```
181F
50
7E
23
0602
4F
07070707
E60F
C630
FE3A
3802
C607
CDB80702
79
10EF
42
10E2
C9
C9

```

# Answer
> 0 votes
## TAL

```
push puts
push \100
push {push puts
push \100
push {@}
dup
strmap
invokeStk 2}
dup
strmap
invokeStk 2

```

To execute it, call `::tcl::unsuppoted::assemble` with the code as argument.
Tcl 8.6 only.

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


title: Counting maximal domino placements

text:
# Question
Title: Counting maximal domino placements
## Background

A **maximal domino placement** (MDP) on a rectangular grid is a non-overlapping placement of zero or more dominoes, so that no more dominoes can be added without overlapping some existing domino.

Alternatively, it can be thought of as a tiling using dominoes and monominoes (single square pieces) so that no two monominoes are adjacent to each other.

For example, the following are a few MDPs on a 3x3 grid: (`-`s and `|`s represent horizontal and vertical dominoes, and `o`s represent holes respectively.)

```
--|   --|   --o
|o|   --|   o--
|--   --o   --o

```

There are exactly five MDPs on 2x3, and eleven on 2x4. Rotation and/or reflection of a placement is different from original unless they exactly coincide.

```
|||   |--   --|   o--   --o
|||   |--   --|   --o   o--

||||   ||--   |--|   |o--   |--o   --||
||||   ||--   |--|   |--o   |o--   --||

--o|   ----   o--|   o--o   ----
o--|   o--o   --o|   ----   ----

```

In the graph-theoretical sense, an MDP is equivalent to a maximal matching (maximal independent edge set) in the grid graph of given size.

## Challenge

Given the width and height of a grid, count the number of distinct maximal domino placements on it.

Standard rules apply. The shortest code in bytes wins.

## Test cases

A288026 is the table of values read by antidiagonals.

```
w|h| 1  2   3     4      5       6
---+------------------------------
1  | 1  1   2     2      3       4
2  | 1  2   5    11     24      51
3  | 2  5  22    75    264     941
4  | 2 11  75   400   2357   13407
5  | 3 24 264  2357  22228  207423
6  | 4 51 941 13407 207423 3136370

```

# Answer
# JavaScript (ES2021), 177 bytes

```
m=>n=>(g=i=>m*n>i?![-1,1,3,4,6].map(k=>g(i+1,(a[i/n|0]??=[])[i%n]=k)):S+=!a.some((r,y)=>r.some((c,x)=>~c?(c%2?a[y+c-2]?.[x]^c:r[x+c-5]^c)-2:r[x+1]<0|a[y+1]?.[x]<0)))(S=0,a=[])|S

```

Certainly can be golfed, but I don't know how. Terrible performance \\$O(5^{mn})\\$.

```
f=m=>n=>(g=i=>m*n>i?![-1,1,3,4,6].map(k=>g(i+1,(a[i/n|0]??=[])[i%n]=k)):S+=!a.some((r,y)=>r.some((c,x)=>~c?(c%2?a[y+c-2]?.[x]^c:r[x+c-5]^c)-2:r[x+1]<0|a[y+1]?.[x]<0)))(S=0,a=[])|S
console.log(`f(2,4) =`,f(2)(4))
```
> 3 votes

# Answer
# Jelly, 34 bytes

```
Ẏ⁹ḟƑƇṭ€⁸Ṣ€ȯW)ẎQ
;þ;Z$,Ɲ€ẎW€çƬ$ṪLo1

```

Try it online!

A dyadic link taking the dimensions as the left and right arguments and returning an integer. The TIO footer generates a 4x4 table similar to the one in the question; the argument for the footer is the size of the table to generate.

Full explanation to follow, but in brief this generates all possible dominoes and then builds all possible lists of those dominoes that don’t have any overlaps. It would be fairly straightforward to extend this to larger polyominoes (though the first part of the code would be a bit more complex); here’s an initial attempt.
> 3 votes

# Answer
# Python 3, ~~250~~ ~~225~~ 219 bytes

```
from itertools import*
def f(w,h):
 p=[[0]*w]
 while h:h-=1;p=[n for r in p for n in product(*[[k%3//2*3,1,2][::k%3+1]for k in r])if('0'in str(n).replace('0, 0',''))<1>("1, 1"in str(n))]
 return sum(1-(2in u)for u in p)

```

*-25 bytes thanks to @ovs*

*-6 bytes thanks to @Jakque*

Try it online!

## How it works

We store each row as a list of `w` values from `[0,1,2,3]`, then transition from each row to the next while following constraints. Vertical constraints are determined by the table at the start of "Rules" in the code below. Horizontal constraints are determined by checking run lengths to ensure that two `0`s are not adjacent, and runs of `1`s are an even length.

Probably can be golfed through a wise relabelling, but that would not be fun.

```
def possible(w, h):
    """
    0: empty; now you must place a domino
    1: is a horizontal domino; now you have freedom
    2: starts a vertical domino; must end it
    3: ends a vertical domino; now you have freedom

    Rules:
    0 →   1,2
    1 → 0,1,2
    2 →       3
    3 → 0,1,2

    0 cannot be next to a 0
    1 is horizontal domino (must have runs of even length)
    """
    if h == 0:
        yield [1 for _ in range(w)]
    else:
        for row in possible(w, h - 1):
            for new_row in itertools.product(
                *[{0: [1, 2], 1: [0, 1, 2], 2: [3], 3: [0, 1, 2]}[k] for k in row]
            ):
                valid = True
                for i, j in itertools.groupby(new_row):
                    L = len(list(j))
                    if i == 0 and L > 1:
                        valid = False
                    elif i == 1 and L % 2 == 1:
                        valid = False
                if valid:
                    yield new_row

def num_possible(w, h):
    return len([p for p in possible(w, h) if 2 not in p])

```
> 3 votes

# Answer
# Jelly,  ~~45~~  24 bytes

```
pŒcạ/S$ÐṂŒPẎ€f€ẠȧQƑʋ@ƇƊL

```

A dyadic Link that accepts the two dimensions and yields the count.

**Try it online!** Note: It brute forces across the powerset of all possible dominoes so is incredibly inefficient.

### How?

```
pŒcạ/S$ÐṂŒPẎ€f€ẠȧQƑʋ@ƇƊL - Link: integer, n; integer m
p                        - (n) cartesian product (m) -> list of all coordinates
 Œc                      - pairs -> all pairs of coordinates, once each
       ÐṂ                - keep those which are minimal under:
      $                  -   last two links as a monad, f(pair of coordinates):
    /                    -     reduce (the pair of coordinates) by:
   ạ                     -       absolute difference
     S                   -     sum
                           -> all possible dominoes, once each, as pairs of coordinates
                      Ɗ  - last three links as a monad, f(all dominoes):
         ŒP              -   power set -> all sets of dominoes (including overlaps)
           Ẏ€            -   tighten each -> coordinates used by each set of dominoes
                     Ƈ   -   filter keep those (potential sets) for which:
                    @    -     with swapped arguments...
                   ʋ     -     ...last four links as a dyad, f(all dominos, potential set):
              €          -       for each (domino in all dominoes):
             f           -         keep those (coordinates of the domino) which are in (the coordinates used by the potential set)
               Ạ         -       all? (i.e only single empties / no touching monominoes?)
                  Ƒ      -       is (potential set) invariant under:
                 Q       -         deduplication? -> truthy if no overlaps
                ȧ        -       (only single empties) logical AND (no overlaps)
                       L - length

```
> 2 votes

# Answer
# JavaScript (ES6),  ~~169~~  164 bytes

Expects `(width)(height)`.

```
w=>h=>(g=(o,x,y,d,q)=>{for(d=2;d--;)for(x=w-!d;x--;)for(y=h-d;y--;)(o[y]|o[y+d])&(m=3>>d<<x)||g(b=[...o],[0,d,h].map(i=>q=b[y+i]|=m));q|g[o+=o]?0:g[o]=++n})(n=[])|n

```

Try it online!

Or much faster for **167 bytes**:

```
w=>h=>(g=(o,x,y,d,q=g[o+o])=>{for(d=2*!q;d--;)for(x=w-!d;x--;)for(y=h-d;y--;)(o[y]|o[y+d])&(m=3>>d<<x)||g(b=[...o],[0,d,h].map(i=>q=b[y+i]|=m));g[o+o]=q||++n})(n=[])|n

```

Try it online!

### How?

We use \\$o\[\\:\]\\$ as an array of bitmasks. This array is split into two areas. An exact representation of all dominoes is stored in the first area (\\$0\le y \<h\\$), whereas only the upper parts of the dominoes are stored in the second area (\\$h \le y \< 2h\\$).

It means that a horizontal domino is stored the same way in both areas, but a vertical domino is stored as a single cell in the second area:

This allows us to distinguish between two grids which are filled the same way but with different orientations of the dominoes.

The recursive function \\$g\\$ attempts to insert dominoes at all possible positions \\$(x,y)\\$ and with either orientation (horizontal when \\$d=0\\$, vertical when \\$d=1\\$), using 3 nested `for` loops:

```
for(d = 2; d--;)
  for(x = w - !d; x--;)
    for(y = h - d; y--;)

```

The collision test is:

```
(o[y] | o[y + d]) & (m = 3 >> d << x)

```

which is:

* `o[y] & (m = 3 << x)` when \\$d=0\\$
* `(o[y] | o[y + 1]) & (m = 1 << x)` when \\$d=1\\$

Whenever a new domino is inserted, we make a copy of \\$o\[\\:\]\\$ in \\$b\[\\:\]\\$ and do:

```
[ 0,  // insert the upper part in area 1
  d,  // insert the lower part in area 1 if d = 1
      // (or just overwrite the upper part if d = 0)
  h   // insert the upper part in area 2
]
.map(i => q = b[y + i] |= m)

```
> 2 votes

# Answer
# Charcoal, ~~112~~ ~~94~~ 86 bytes

```
ＮθＮη≔⁰ζ⊞υＥ²ζＦυ«≔ωδＦ×θηＦ²«≔×⊕Ｘ²∨ληＸ²κε¿∧⎇λ﹪⊕κη‹κ×⊖θη¬＆εΣι«≔Ｅι⁺μ×⁼λνεδ¿¬№υδ⊞υδ»»≧⁺¬δζ»Ｉζ

```

Try it online! Link is to verbose version of code. Takes 30s on TIO to do 4×4 but smaller areas are quicker. Explanation:

```
ＮθＮη

```

Input the width and height.

```
≔⁰ζ⊞υ

```

Start with zero placements.

```
⊞υＥ²ζ

```

Start enumerating placements with one that has no vertical or horizontal dominoes.

```
Ｆυ«

```

Loop through the placements.

```
≔ωδ

```

Assume that there are no possible dominoes.

```
Ｆ×θηＦ²«

```

Loop through all potential dominoes.

```
≔×⊕Ｘ²∨ληＸ²κε

```

Create a bitmask for this domino.

```
¿∧⎇λ﹪⊕κη‹κ×⊖θη¬＆εΣι«

```

If this domino doesn't wrap around, and there is room to place a domino without overlapping any existing domino, then...

```
≔Ｅι⁺μ×⁼λνεδ

```

Add a domino in the appropriate orientation.

```
¿¬№υδ⊞υδ

```

Add this if it is a new placement.

```
»»≧⁺¬δζ

```

Increment the number if this is a maximal placement i.e. no dominoes were found.

```
»Ｉζ

```

Output the final number of maximal placements.
> 0 votes

---
Tags: code-golf, combinatorics, grid, tiling, dominoes
---


# Question
Title: Strip all non-printable ASCII characters
Your challenge, should you be coded to accept it, runs as follows:

You may choose one of the following two challenges to implement:

**Challenge #1**

* Read from a file `a.txt`
* Write only printable ASCII characters (values 32-126) to a file `b.txt`

**Challenge #2**

* With a file `a.txt`, delete all characters in the file except printable ASCII characters (values 32-126)

**Specs on `a.txt`**

`a.txt` is a plain text file which can include any ASCII values from 0-255 (even undefined/control) and its size can range up to 1 GB.

**Winning**

The answer with the smallest amount of sourcecode in bytes wins.

# Answer
> 6 votes
## sh

### Challenge 1, ~~24~~ 23 chars

```
tr -dc \ -~<a.txt>b.txt

```
**Bonus**: variations on the set of characters to delete.
```
tr -dc " -~
"<a.txt>b.txt                       # preserves printables + line feed

```

```
tr -dc "[:space:] -~"<a.txt>b.txt   # preserves printables + whitespace

```

# Answer
> 2 votes
# Brainfuck: 92

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

```

Brainfuck cannot open files so you use stdin/stdout redirection (#1)

```
bf strip.bf < a.txt > b.txt

```

The same code in Extended Brainfuck: 68

```
+[(->+>+)3>8+(->12+<<4-)>2-[<<[->]>[<]>-]<+<([-]>-)>([-]2<.)2<[-]<,]

```

# Answer
> 1 votes
## Bash + Perl

### Challenge 1 – *31* bytes

```
perl -petr/\ -~//cd a.txt>b.txt

```

### Challenge 2 – *28* bytes

```
perl -i -petr/\ -~//cd a.txt

```

# Answer
> 1 votes
Both are Challenge 1.

# C - 132 characters

```
#include<stdio.h>
k;main(){FILE*f=fopen("a.txt","rb");FILE*g=fopen("b.txt","w");while(!feof(f))(k=getc(f))>31&&k<127&&putc(k,g);}

```

# Python - 78 characters

```
file("b.txt","w").write(filter(lambda x:'~'>=x>' ',file("a.txt").read()))

```

# Answer
> 1 votes
**PowerShell (43, 43)**

**Challenge 1: (43)**

```
(gc -raw a.txt) -replace"[^ -x7e]","">b.txt

```

**Challenge 2: (43)**

```
(gc -raw a.txt) -replace"[^ -x7e]","">a.txt

```

# Answer
> 1 votes
# Vyxal, 6 bytes

```
kPs5ȯ↔

```

Try it Online!

Fixed thanks to Aaron Miller. Why does the printable ascii builtin contain unprintables?

# Answer
> 0 votes
## iX3, 388

```
Set  in [c]:  '1'
Loop start   ([c]  of 1  to 999999999)
   Read from file  'a.txt' into [T] (read from [c], 1 bytes)
   Modify text  '[T]' into [R] (code in Hex)
   Set  in [N]:  '&H[R]' (calculate)
   If  True: '([N]=10)'
      Write into file  'b.txt' line '' (Append)
   End If
   If  True: '([N]>31)&([N]<127)'
      Write into file  'b.txt' line '[T]' (Append, no linefeed)
   End If
Loop end

```

# Answer
> 0 votes
# Ruby (52)

### Challenge #1

```
 IO.write (f="a.txt"),IO.read(f).gsub(/\p{Cntrl}/,'')

```

# Answer
> 0 votes
# Retina, 7 bytes

Simple regex to remove non-printable ASCII.

```
[^ -~]

```

**Try it online!**

Test input copied from this SO post.

# Answer
> 0 votes
# Tcl, 122 ~~123~~ bytes

```
set g [open b.txt w]
lmap c [split [read [open a.txt]] ""] {scan $c %c v
if $v>31&$v<127 {puts -nonewline $g $c}}
close $g

```

Try it online!

# Answer
> 0 votes
# K4, ~~36~~ 33 bytes

**Solution:**

```
`b.txt 1:{x@&31<x*127>x}@1:`a.txt

```

**Explanation:**

Above is for Challenge A, replace the `b.txt` for `a.txt` for Challenge B.

```
`b.txt 1:{x@&31<x*127>x}@1:`a.txt / the solution
                         1:`a.txt / binary read (1:) "a.txt"
                        @         / apply to
         {             }          / lambda taking 1 implicit arg (x)
                  127>x           / 127 greater than?
                 *                / multiply by
                x                 / x
             31<                  / 31 less than?
            &                     / indices where true
          x@                      / index into x at these indices
`b.txt 1:                         / binary write to "b.txt"

```

# Answer
> 0 votes
## Burlesque - 21 bytes

```
{**{31.>}{127.<}m&}f[

```

This can be shortened be replacing the `128` with `'<DEL>` (where DEL is the delete character) but I'm not sure how I can post a DEL here (also replace the `31` and then you can also get rid of the `**`)).

Also, in the WIP version you can golf this down to `:un:ln`.

# Answer
> 0 votes
# Japt, 3 bytes

Well, seeing as everyone else is ignoring the requirements to read from & write to a file ...

Input also from this SO answer.

```
;oE

```

Try it

# Japt v2.0a0, 3 bytes

```
r\P

```

Try it

---
Tags: code-golf
---


title: What did we forget?

text:
# Question
Title: What did we forget?
Your task is to write a non-empty computer program comprised of some sequence of bytes. If we choose a particular byte in the program and remove all instances of it from the program, the modified program should output the removed byte.

For example if our program were

```
aabacba

```

Then `bcb` would output `a`, `aaaca` would need to output `b` and `aababa` would output `c`.

It does not matter what the unmodified program does.

Answers will be scored in bytes with the goal being to minimize the number of bytes.

# Answer
## zsh, ~~603~~ ~~594~~ ~~566~~ ~~561~~ ~~548~~ ~~440~~ ~~415~~ ~~399~~ ~~378~~ 370 bytes

```
ec
ho \\n;ca t<<<$'\x20';exi t
d$c -e8BC6P
d0c -eKp
$'\172\163\150' $'\055\143' $'\146\157\162 v \151\156 \173\043\056\056\134\175\175\073\173 \146\147\162\145\160 \055\161 $\166 '$0$'\174\174\074\074\074$\166\073\175'
$'\145v\141\154' $':\073\072\046\046\145\170\151\164';#%&()*+,/9=>?@ADEFGHIJLMNOQRSTUVWXYZ[]^_`jklmsuwy
0# $#;for b in {$..z};{ fgrep -q $b $0||<<<$b;}

```

Depends on coreutils + `dc`.

Try it online!

That was... a journey.

This answer has three parts. The first 4 lines handle certain special cases to simplify the code that follows. The next 2 lines and the last line both accomplish essentially the same thing, but exactly one is run with any given character removal. They are written with mostly complementary character sets, so that removing any character breaks only one at most, allowing the other to continue to function.

Looking at the first part, we first handle

* newline removal with `ec\nho \\n`
* space removal with `ca t<<<$'\x20'` (followed by `exi t` to avoid running later code, which would result in extraneous output)
* `$` removal with `d$c -e8BC6P` (`8BC6` = `9226` is `36*256 + 10`, and 36 and 10 are the byte values of the `$` and newline characters respectively; we use hex digits in decimal to avoid having to include them in the large comment in line 6)
* `0` removal with `d0c -eKp` (`K` gets the decimal precision, which is `0` by default)

In the next part, the only characters used (aside from the garbage at the end of the second line) are `$'\01234567v;`, space, and newline. Of these, four have been accounted for, so the remainder (`'\1234567v`) cannot occur in the last line. Expanding the octal escapes (`$'\123'` represents the ASCII character with value 1238), we get:

```
zsh -c 'for v in {#..\}};{ fgrep -q $v '$0'||<<<$v;}'
eval ':;:&&exit'

```

The first line loops through all characters used in the program and searches for each one in its own source code (`$0` is the filename of the script being run), printing any character that is not found.

The second line looks a little strange, and appears to do the same thing as `exit` with a bunch of nops. However, encoding `exit` as octal directly results in `$'\145\170\151\164'`, which does not contain `2` or `3`. We actually need to make this *less* resilient to removals. This is because if any of `'\014567v` are removed, breaking the first line, the second line also breaks, allowing the remainder of the code to execute. However, we need it to also break if `2` or `3` are removed so that lines 3 and 4 can run. This is accomplished by shoehorning in `:` and `;`, which have a 2 and 3 in their octal representation respectively.

The junk at the end of line 2 is simply there to ensure every printable ASCII character appears at least once, as the way the checking is done by looping through each one requires this.

If `exit` was not called in the first section (i.e. it was mangled by the removal of one of `'\01234567v`), we move on to the second, in which we must accomplish the same thing without using any of these characters. The last line is similar to the decoded first line, except that we can contract the range of the loop to save a few bytes, because we already know that all characters except for `'\01234567v` have been covered. It also has `0# $#` before it, which comments it out and prevents it from producing extraneous output if `0` or `$` were removed.
> 73 votes

# Answer
# Retina, 1 byte

```
1

```

Try it online!

When all instances of the single byte (`1`) are removed, the output is `1`. Simple enough.
> 22 votes

# Answer
## Lenguage, 216173027061157310 bytes

`216173027061157310 = (144115617572598740 + 144115241762960340 + 144115194786755540) / 2`. There are `216173027061157310 - 144115617572598740` `$`s, `216173027061157310 - 144115241762960340` `#`s and `216173027061157310 - 144115194786755540` spaces.

The 144115617572598740 `#`s and spaces encode the following BF program:

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

```

Try it online!

The 144115241762960340 `$`s and spaces encode the following BF program:

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

```

Try it online!

The 144115194786755540 `$`s and `#`s encode the following BF program:

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

```

Try it online!

Edit: Saved 72057832274401770 bytes thanks to @Nitrodon.
> 12 votes

# Answer
# Jelly, 1 byte

```
0

```

Completely different from the Retina answer. *whistles*

Try it online!
> 10 votes

# Answer
# Polyglot*, 1 byte (awaiting confirmation)

```
0

```

Try it online! (using Triangularity)

\*: This works in a (rather wide) variety of languages (except for esolangs like 4, \>\<\> and the like and some other exceptions). Identical to the Jelly answer in source code, but the method of I/O is different – Output is via exit code. When one removes `0` from the source code, they're left with an empty program, which often doesn't error and yields exit code **0** in the majority of languages.
> 9 votes

# Answer
# sed, 1 byte

```

```

Try it online!

Completely different from the Retina answer, or the Jelly answer.
> 4 votes

# Answer
# Unary (non-competitive), 96 bytes

```
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0101 0101 0101 0101 0101 0101  ................

```

Here is `xxd` dump.

A wider definition of Unary language allows any characters in its source code. But I havn't find a compiler or interpreter which would work for this. So I marked this answer as non-competitive. If you can find one which posted before this question asked, I will link to it.
> 3 votes

# Answer
# Gol\>\<\>, 143 bytes

```
<\Hs+:+:PPPs\
\sM:+:+H
HP+:+:PPPs++\
HsssssssM+++\
;HssssMMMMM++\
;o+:+:PPs++\
+:+:P+:PPP\H+P:P+:
ssssMMMMMM\H
sHsssMMMMM+\
Hsssss+++\
HMMMMMMs

```

Try it online!

This contains the characters `<\Hs+:PM;o` and newline

I wanted to solve this in a 2D language, but most 2D languages are ruled out from this challenge. Gol\>\<\> works because of the large number of operations including operations with overlapping functionality, this ensures that we can write a meaningful program with any 1 character banned.

We use the standard technique for 2D languages here. The removal of characters causes the length of a line to change which creates a new alignment and sends the pointer down a new path untouched by the radiation.

Each character gets its own line of the program and which line is run is triggered by the removal. We could possibly choose a smaller character set to work with `<\Ho;P1+` and newline should work, however the lines would be very long making this overall more costly.
> 1 votes

---
Tags: code-golf, source-layout, radiation-hardening
---


title: Error 404: Character Not Found

text:
# Question
Title: Error 404: Character Not Found
# Scenario

One of your friends is struggling on a homework assignment. He needs a simple program which prints the first 404 natural numbers:

```
1 2 3 4 5 6 7 8 9 10 11 ... 401 402 403 404

```

Your challenge is simple: write this program for him.

However, your connection is terrible, so 1 random character is lost every time you send the program. To prevent this from breaking your program, you must make it so that removing **any single character** will have **no effect:** the program works, regardless. (The original program must also work.)

Because the connection is too poor to send large files, **your code must be as short as possible.**

TL:DR - make a radiation hardened program to output the numbers 1 to 404

---

## Rules/Details

* The output may be a list of integers in any reasonable format (separated by spaces, newlines, commas, etc). However, your **output must be consistent** and not change when the program is modified.
* Command line flags that contain logic, execute actual code, generate the number list, and so on, are banned.
* This is , so the shortest submission (in bytes) wins!

# Answer
> 18 votes
# 05AB1E, 12 bytes

Code:

```
XX440044ÔÔŸŸ

```

Normal code explanation:

```
X             # Pushes the number 1.
 X            # Pushes the number 1 again.
  440044      # Pushes the number 440044.
        Ô     # Connected uniquify.
         Ô    # Connected uniquify.
          Ÿ   # Inclusive range of the top two elements.
           Ÿ  # Inclusive range on the array, which leaves it intact.

```

This leads to the following golfed code: `X404Ÿ`, which is what we want to achieve.

The number **404** is generated by any of these variants:

```
440044ÔÔ
40044ÔÔ
44044ÔÔ
44004ÔÔ
440044Ô

```

The inclusive range works as following on two numbers:

```
`1 5Ÿ`             ->    [1, 2, 3, 4, 5]
[1, 5]Ÿ            ->    [1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]Ÿ   ->    [1, 2, 3, 4, 5]

```

Which always makes the second `Ÿ` a **no-op**.

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

# Answer
> 36 votes
# JavaScript, 228 bytes

```
etInterval=stInterval=seInterval=setnterval=setIterval=setInerval=setIntrval=setInteval=setInteral=setIntervl=setInterva=top=>4

setInterval
`405>(i=this.i?i:1)?alert(i++):0`///`
setInterval
`405>(i=this.i?i:1)?alert(i++):0`///`

```

### Explanation

Evaluating code in a `setInterval` allows the program to continue even if there is an error. We make sure that the code passed will error out if any single character is removed. Template string syntax can be abused to call `setInterval` with a constant string without parentheses. Luckily, even if the template string is on the next line it still parses as a function call with such syntax.

The first issue we run into is that `setInterval` is a function, and thus if a character is removed and the program tries to call `setInteval` instead, it errors out. Of course, since there are two indentical invocations of the `setInterval`, we don't have to worry about it actually functioning correctly as long as we avoid the error. So, the first line defines every possible "misspelling" of `setInterval` to a valid function.

The first line works by assigning all of these "misspellings" to the function `top=>4`. Note the ES6 syntax, this simply takes a paramater named "top" and returns 4. Why "top"? Well, the first line must never throw an error even if a character is removed. If an `=` is removed to make `top>4`, this boolean expression will be valid since `top` is predefined in browsers, simply yielding `false`. If the 4 is removed, the function body simply becomes the first `setInterval` segment, and the second runs unharmed.

Now, all that is left to worry about is if a \` is removed.

If removed from the beginning, `setInterval` simply does nothing, evaluating to itself as its own expression. Then, the rest of the second line simply runs a single iteration of the loop, letting the other `setInterval` fragment finish the job. If removed from the end, the remaining backtick is picked up from the end of the comment.

The newlines are placed so that removal one will not affect program behavior, but they prevent errors in the case of some character removals such as the leading backtick.

# Answer
> 26 votes
# Pyth - 16 bytes

The basic idea behind this is that when you take a digit off of `404`, it only makes the number smaller, so we just have to get the maximum of two `404`'s to ensure we have the right number. Obviously, there are a bunch more redundancies.

```
SSsetSS[404  404

```

Explanation:

```
SS                       First one does 1-index range, second one sorts, which is no-op
 s                       If the e is there, this is no-op, if only t is there, it sums a one element list, which is the item
  et                     e picks last element in list, and if e is gone, then t gets you the list without the first element which is good enough when combined with s
   SS                    Sorting twice is no-op
    [                    Start list, this can't be two element because if we get rid of initial 4, the 0 becomes third element which neeeds to be captured
     404                 One of the 404's
     <space><space>404   Need two spaces for redundancy, because 404404 *is* bigger than 404

```

Try it online here.

# Answer
> 25 votes
## Befunge-98, 37 bytes

```
20020xx##;;11++::''ee44**``kk@@::..;;

```

Try it online!

### Explanation

Making radiation-hardened code in Befunge-98 isn't *too* bad, because you can set the "delta" (i.e. the step size of the instruction pointer) manually with `x`. So if set the delta to `(2,0)`, from then on every other character is skipped and we can simply double up all commands. The tricky thing is getting `2 0` on top of the stack in a reliable way. We'll actually need `0 2 0` for the rest the program to work correctly, but we'll that for free. Here is how we do this:

```
20020xx

```

Note that each digit pushes itself, so in the full program, there will be a start `2 0` which we'll simply ignore.

Consequently, dropping either the first or second character from the program is irrelevant because we won't use those digits anyway. Likewise, removing the third character is identical to removing the second, so we don't need to worry about that either.

Let's consider what happens in the other two cases. Dropping the fourth character:

```
2000xx

```

Note the delta is set to `(0,0)`. But this doesn't move the instruction pointer at all, so the same `x` is executed again immediately and this time pops the `(2,0)` and all is well (there are implicit zeros at the bottom of the stack for our later purposes).

Let's drop the fifth character instead:

```
2002xx

```

Now the delta gets set to `(0,2)`. However, there is still no horizontal movement, so the IP wraps immediately back to `x` and again, the correct delta gets set.

From this point onward we can basically ignore the character duplication as well as this initial part because it will always be skipped:

```
...#;1+:'e4*`k@:.;

```

The `;` is a sort of comment command which skips everything until the next `;` is encountered. However, we jump over the first `;` with `#` so only the part between the `;` will be executed from that point onward.

```
1+    Increment the top of the stack.
:     Duplicate it.
'e    Push 101.
4*    Multiply by 4 to get 404.
`     Greater-than check. Pushes 1 once the top
      reaches 405, otherwise 0.
k@    Terminate the program that many times.
:.    Print a copy of the top of the stack (and a space).

```

# Answer
> 16 votes
# \>\<\>, ~~103~~ ~~60~~ 51 bytes

```
               vv
;?=*4o" e"n:ll<<
;?=*4o" e"n:ll<<

```

Tested here.

Uses the same tactic as this program. If a character is deleted in the first line, the 2nd line will still be run. If a character in the 2nd line is deleted, the `v` will move execution to the 3rd line, since the 2nd line is a character shorter. A deletion in the 3rd line has no effect on program control, as it is only execution after a deletion in line 2.

The program will also work in the event that a line break is deleted:

**Case 1:**

The 2nd line will be run.

```
               vv;?=*4o" e"n:ll<<
;?=*4o" e"n:ll<<

```

**Case 2:**

Both lines become one line with twice the instructions.

```
               vv
;?=*4o" e"n:ll<<;?=*4o" e"n:ll<<

```

**Explanation:**

The core of the program is the following. Note that a `1` is pushed on the stack already by the first line.

```
ll:n        Push length of the stack twice, duplicate, print as number
"e "o       Push 101, 32, output 32 as space
4*          101 * 4 is 404
=?;         Pop twice, if equal, halt
            (Execution wraps around)

```

# Answer
> 13 votes
# \>\<\>, ~~42 38~~ 34 bytes

Try it Online!

Thanks to @Martin Ender and @Teal Pelican for shaving off 8 bytes!

```
<<;?=*4o" e"lnll/
 ;?=*4o" e"lnll<

```

Similar to mbomb007's answer, but only uses 2 lines.

Instead of counting up from 1 to 404 using a single memory value, I continuously pushed the length of the stack. This made it so that I didn't need to put anything on the stack before the loop started, making things a lot easier.

### The original code

The `<`s turn the IP around, and the `/` is a no-op, as the IP wraps around and continues along it's normal path. Thus, the relevant code is:

```
          lnll   Prints the size of the stack + 1 and pushes the stack size twice
     o" e"       Prints a space and pushes 101
   *4            Multiplies to get 404
;?=              If the number we just printed was 404, end the program

```

And this repeats.

### The deletion

The big key here is the mirror `/`. It doesn't do anything if the second line is modified - only wraps back around to itself and is essentially a no-op. But if a character from the first line is removed, the line will shift down, so that the mirror hits the arrow `<`, leading into an identical, unmodified loop.

The only other significant deletion would be the `\n` character. This is also accounted for, as it produces this code:

```
<<;?=*4o" e"lnll/ ;?)*4o" e"lnll<

```

Now, we have just appended a copy of the original loop `;?=*4o" e"lnll` to itself. As this is a loop, it makes no difference to the execution, and runs as if nothing had changed.

# Answer
> 11 votes
# A Pear Tree, 34 bytes

The program contains control characters, so here's an `xxd` dump:

```
00000000: 7072 696e 7420 312e 2e34 3034 2327 108a  print 1..404#'..
00000010: af70 7269 6e74 2031 2e2e 3430 3423 2710  .print 1..404#'.
00000020: 8aaf                                     ..

```

A Pear Tree is basically a Perl derivative, with some "interesting" features. I threw it together as a joke (so that I could say that my polyglot printed `a partridge` in A Pear Tree; in fact, almost all programs do). However, it's Turing-complete, and actually kind-of good at this sort of challenge.

The feature that we mostly care about here is that A Pear Tree will only run a program if some substring of the code has a CRC-32 of `00000000`. The code gets rotated to put the substring in question at the start. As it happens, the two (identical) halves of the code each have the CRC-32 in question (due to that suspicious-looking binary comment at the end), so if you delete a character from the source (breaking the CRC), the other half gets rotated to the start and the `#` sign near the end will comment the damaged half out, in addition to the binary junk.

Another feature makes the program slightly smaller: although A Pear Tree is mostly interpreted as Perl, it has some minor changes to make it work more like Python. One that's relevant here is that unlike Perl's `print` statement (which just runs the numbers together), A Pear Tree's `print` statement separates arguments with spaces and prints a final newline. That gives us nicely space-separated output, meaning that we don't have to waste bytes on formatting. (Note that you'll have to give the program no input; if the language receives input, it assumes by default that it's supposed to do something with it.)

Of course, this can't compete with actual golfing languages (nor would I expect it to), but I thought people might find it interesting.

# Answer
> 10 votes
# Befunge 98, 34 bytes

Try it Online!

```
<<.:@k`*4e':+1[

2.:@k`*4e':+1<^^j

```

This works very similarly to my \>\<\> answer, but instead of the mirror `/`, I use the turn left operation `[` and then reverse the IP direction, which is functionally equivalent to a mirror in this case.

### The original code

```
<<                 Reverses code direction, sending IP to right
               [   Turns the IP left, into the ^, which reverses it.
                   It then hits this again, turning left to go West. (No-op)
            :+1    Adds 1 to the sum
        *4e'       Pushes 404
     @k`           Ends the program if (sum > 404)
   .:              Prints the sum

```

### The deletion

If something in the second line is deleted, it will shift over, and not affect the top at all.

If anything in the first line is deleted, the `[` will send the IP into the `<`, which starts an identical loop (with the exception of `2j^^` which avoids the `^`s used in tandem with the `[`)

Because there are 2 new lines, it makes no difference to the code if one is deleted (thanks to @masterX244 for this!)

# Answer
> 5 votes
# Befunge-93, ~~54~~ 51 bytes

Thanks to Mistah Figgins for saving me 3 bytes.

```
111111111111111vv
+1_@#-*4"e":.:<<
+1_@#-*4"e":.:<<

```

Try it online!

This is essentially the same trick as was used in the Fault-Tolerant Hello World challenge. The first line starts by making sure there is a 1 on the top of the stack for the start of the sequence, and then one of the `v` arrows at the end of the line redirects the code path to the start of the main routine on line 2, executing from right to left.

Removing a character from the first line will just shift the `v` arrows across by one, but that still allows the code to redirect to the second line successfully. Removing a character from the second line causes the `<` arrow at the end of the line to shift out of the path of the `v` above it, so the code path will be redirected to the backup routine on line 3.

Removing the first line break does no harm, because that just moves the third line into place to replace the second line. And removing anything after the end of the second line will have no effect, because that's just the backup code.

# Answer
> 5 votes
# JavaScript + HTML + Stack Snippets, ~~167~~ ~~158~~ 154 bytes

Abusing the fact that JavaScript in Stack Snippets gets placed in a web page inside a `<script>` element.

```
or(x="",i=405,d=document;--i;)d[i]||(x=d[i]=i+' '+x);d.write(x)</script></script><script>for(x="",i=405,d=document;--i;)d[i]||(x=d[i]=i+' '+x);d.write(x)
```

# Answer
> 4 votes
# Actually, 18 bytes

```
:404::404kMkMMRRSS

```

Actually is a stack based golfing language.

Explanation of the commands involved (as they work in the above context):

```
Numbers are indicated by round brackets () and lists by square brackets []

:         - pushes the longest string of characters in '0123456789+-.ij' as a numeric
k         - pop all the elements on the stack into a list [l] and push [l]
M         - pop [l], push max([l])
            pop (a), push (a)
R         - pop [l], push reverse([l])
            pop (a), push range([1,a])
S         - pop [a], push sorted([a])

```

# Answer
> 2 votes
# Zsh, 26 bytes

```
>404
>404

seq  ???||seq *

```

Try it online!

Verify all mutations!

Explanation:

* `>404`: create the file `404`. This command is repeated twice because if one has had a byte removed, we need the other to still work. Ordinarily with `>` you wouldn't need the newline between them, but in the case the second `>` is removed, `>404404` wouldn't create `404`
* `???`: find a 3-character file name in the current directory (this will always find `404` because of the redundancy above)
* `seq`: count up to that
* `||`: if that fails (happens if `seq` or `???` is mangled):

+ `*`: find a filename
    + `seq`: count up to it
* The second newline before the first `seq` is necessary because otherwise `>404seq` would create two files, and then `seq *` would try to range between `404` and `404seq`, which isn't a number
* The second space in `seq ???` is necessary because `seq???` would fail to match, and for some reason the bit after the `||` doesn't get executed either (it's possibly a bug in zsh)
* If any of the two `|`s are missing, the first `seq` is piped to the second; the second ignores its input, but still outputs as normal.

# Answer
> 1 votes
# Vyxal, ~~11~~ 9 bytes

*-2 thanks to A username*

```
⁺ed404∴ɾƛ

```

Try it Online!

```
⁺ed404∴ɾƛ
⁺e          # Push 202
  d         # Double ^ to get 404
   404      # Push 404 again
      ∴     # Take the maximum
               # If bytes are removed from either of the 404s, this ensures the intact one is pushed
               # If ∴ is removed, 404 is still at the top of the stack so it doesn't matter
       ɾ    # range(1, n+1)
        ƛ   # Map
               # If it's a number (ɾ removed), range(1, n+1) is used
               # Otherwise (it's a range), nothing happens here

```

# Answer
> 1 votes
# Gol\>\<\>, 26 bytes

```
<<;|N:PF*4e`/
<;|N:PF*4e`/

```

Try it online!

This is pretty simple, but there wasn't a Gol\>\<\> answer yet, and it scores pretty well.

# Answer
> 1 votes
# Klein 000, 32 bytes

```
<<@?+-*4"e":+1:/
<@?+-*4"e":+1:/

```

Try it online!

# Klein XXX, 54 bytes

```
>>>             \\
..\:+1:@?+-*4"e"<
\..:+1:@?+-*4"e"<

```

Try it online!

Shamelessly reusing strategies from my fault tolerant "Hello world" solution.

---
Tags: code-golf, kolmogorov-complexity, source-layout, radiation-hardening
---