title: Output the missing integer

text:
# Question
Title: Output the missing integer
You will be given a string. It will contain 9 unique integers from 0-9. You must return the missing integer. The string will look like this:

```
123456789
 > 0

134567890
 > 2

867953120
 > 4

```

# Answer
> 43 votes
# Python 2, ~~18~~ 16 bytes

<sup>+beauty thanks to @Sarge Borsch</sup>

```
`99066**2`.strip

```

Try it online!

`99066**2` is just a shorter way to generate a string that contains 0~9

# Answer
> 27 votes
# Python, 22 bytes

```
lambda s:-int(s,16)%15

```

Try it online!

An arithmetic solution. Interprets the input string as hex, negates it, and takes the result modulo 15.

# Answer
> 19 votes
# APL (Dyalog), 4 bytes

### Derived function

```
⎕D∘~

```

`⎕D`**D**igits

(ties a left argument to the following dyadic function to create a monadic function)

`~` except \[the argument\]

Try it online!

---

### Function train

```
⎕D~⊢

```

`⎕D`**D**igits

`~` except

the right argument

Try it online!

---

### Explicit program

```
⎕D~⍞

```

`⎕D`**D**igits

`~` except

character input

Try it online!

# Answer
> 13 votes
# Haskell, ~~24~~ 23 bytes

```
(477-).sum.map fromEnum

```

Try it online! Usage: `(477-).sum.map fromEnum $ "123456890"`. 477 is the sum of the character codes of the digits 1 to 9, excluding 0. This anonymous function computes 477 minus the sum of all digit character codes to find the missing one.

Turning the char digits to ints is one byte longer:

```
(45-).sum.map(read.pure)
foldl(\a b->a-read[b])45

```

Try it online!

# Answer
> 12 votes
# Brain-Flak, ~~48~~ ~~38~~ 36 + 3 = 39 bytes

*10 bytes saved thanks to DJMcMayhem!*

```
((([]())[]{}){()()({}[()])}{}[{{}}])

```

Try it online!

## Explanation

The sum of all the digits in Ascii is 525. This program sums up the input and subtracts it from 525 to get the missing digit.

```
((([]())[]{}){()()({}[()])}{}      )

```

Will push 525. This takes advantage of the fact that we know there will be 9 elements of input to begin with. This means that `[]` evaluates to 9 which allows us to get to large numbers like 525 quickly.

Next we have the bit:

```
                             [{{}}]

```

which will sum up the inputs and subtract it from the total.

# Answer
> 10 votes
# Jelly, 3 bytes

```
ØDḟ

```

Simply filters () the input string from **“0123456789”** (`ØD`).

Try it online!

# Answer
> 9 votes
# JavaScript (ES6), 26

*Edit* 1 byte save thx @Neil, with a much more smarter trick

Xoring all the values from 1 to 9 gives 1. Xor 1 one more time and the result is 0. So, if any single value is missing, the result will be the missing value.

```
s=>eval([1,...s].join`^`)

```

**Test**

```
f=s=>eval([1,...s].join`^`)

function go() {

  var i=I.value;
  O.textContent = f(i)
}

go()
```

```
<input oninput='go()' value='012987653' id=I>
<pre id=O></pre>
```

# Answer
> 9 votes
# Ruby, 14

Sums the ascii codes and subtracts from 48\*9+45

```
->s{477-s.sum}

```

Use like this

```
f=->s{477-s.sum}

puts f["123456789"]

```

# Answer
> 8 votes
# Retina, ~~27 21~~ 19 bytes

-6 Thanks to Basic Sunset
-2 Thanks to Martin Ender

```
.
$*_5$*
+`_1|1_

1

```

Try it online!

Replace every digit with that many `_`s and 5 `1`s:

```
.
$*_5$*

```

Remove all of the `_`s and a `1` for each:

```
+`_1|1_

```

Count the number of `1`s left:

```
1

```

# Answer
> 7 votes
# Brainfuck, 17 15 bytes

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

```

Try it out here. *This solution works on standard Brainfuck (8-bit cells) only, as it relies on wrapping.*

It's a rare day when Brainfuck can actually compete, but this challenge just happened to line up with the BF spec pretty well!

Instead of straight-up breaking down this answer, I'd like to step through the iterations I took, because I think it would be more understandable (and more interesting).
Note: this solution is inspired largely by Wheat Wizard's Brain-Flak answer.

## Explanation

## Step 1, 26 bytes

In his answer, Wheat Wizard pointed out that the sum of the ASCII values from 0-9 sum to 525. And since standard Brainfuck only has a notion of \[0,255\], this makes the value 525 % 256 = **13**. That is to say, subtracting the ASCII values of the input from 13 nets you the missing digit.

The first version of this program was:
1. Put 13 in the first cell
2. Take inputs into the second cell
3. Subtract the second cell from the first cell
4. Jump to 2 if there are inputs remaining
5. Print the first cell

And here's the code for the simple solution:

```
+++++++++++++ #Set the first cell to 13
>,            #Take inputs into the second cell
[[<->-],]     #Subtract the second cell from the first cell and repeat until inputs are over
<.            #Print the first cell

```

## Step 2, 19 bytes

As pointed out in his answer, since we know the input will be exactly length 9, we can use that value as a constant, and eliminate that long string of +'s right at the beginning.
It also doesn't matter at what point we add 13 (thanks, commutative property!), so we'll mix it in with the subtraction and printing steps.

```
,        #Take input to enter the loop
[[->-<], #Subtract the first cell from the second cell
>+<]     #Add 1 for each input; totaling 9
>++++    #Add the missing 4 to make 13
.        #And print

```

This was my original answer to this problem, but we can do better.

## Step 3, 17 bytes

Interestingly enough, the previous answer works even if we begin with a + instead of a ,

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

```

Brainfuck required *something* in a cell in order to begin a loop. We naively added that extra 4 in the end, when it could have gone in other places.

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

```

With some *totally intentional* (read: trial and error) loop trickery, starting off the program with a - leads to two interesting results:

1. One gets added to the second cell (saving 1 byte at the end).
2. The loops runs one extra time, totaling 10 instead of 9 (saving another 1 byte).

1 + 10 + 2 = 13, and we end up with the original answer.

Looking back on it, this is probably an excessive write-up for such a simple Brainfuck program.

## Step 4, 15 bytes

After thinking about this solution a bit more, I was able to cut off 2 bytes.

I wanted to clarify something about the previous step:
The minus to enter the loop *effectively* adds 1, but what it's actually doing is subtracting 255 from the second cell (resulting in 1).

It's obvious in retrospect, but subtracting 1 from the first cell is the same as adding 1 to the second cell (because everything in the first cell gets subtracted from the second cell.)

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

```

I was able to remove the "\>+\<" by adding a "-" at the beginning of the first loop. It has to go there, and not where the "\>+\<" was, because the program will loop infinitely otherwise.

# Answer
> 6 votes
# 05AB1E, 6 bytes

```
45¹SO-

```

Try it online!

```
45     # Push 45
  ¹    # push input
   S   # Split
    O  # Sum
     - # Subtract (45 - sum)

```

# Answer
> 6 votes
## JavaScript (ES6), ~~31~~ ~~29~~ ~~28~~ 22 bytes

```
s=>(15-`0x${s}`%15)%15

```

Port of @xnor's Python answer, except that JavaScript only has a remainder operator rather than a modulo operator, so I can't do it in a single step. Edit: Saved 6 bytes thanks to @Arnauld.

# Answer
> 6 votes
# Mathematica, 25 bytes

```
477-Tr@ToCharacterCode@#&

```

Pure function taking a string as input and returning an integer. Mathematica has long command names and is reluctant to convert between strings and integers, which makes it particularly bad at this challenge. The best I could find was the algorithm from Level River St's Ruby answer, which does a computation based on the total of the ASCII codes of the input string; in Mathematica, this uses only one long command name.

# Answer
> 5 votes
# Octave, 22 bytes

```
@(x)setdiff('0':'9',x)

```

Try it online!

# Answer
> 5 votes
# PHP, 27

```
<?=trim(32043**2,$argv[1]);

```

uses the trick from Rod's answer to generate a string containing all digits then removes all digits except for the missing one.

---

PHP, 41

```
for($b=1;$i<9;$b^=$argv[1][$i++]);echo$b;

```

This one uses *xor* because I haven't seen it yet.

# Answer
> 5 votes
## Bash + coreutils, 19 bytes

I found a ~~shorter~~ bash solution, that uses an interesting checksum approach:

```
sum -s|dc -e524?--P

```

**Try it online!**

**Explanation:**

The `sum` command prints a checksum and a block count. I don't know many details, but using the option `-s` (System V algorithm) will make the checksum equal to the ASCII sum of each input character code. As such, the checksum remains constant when the order of the same input characters changes.

Given `867953120` as test case (last example), here is how the script works:

* `sum -s` outputs `473 1`. If no integer was missing, the checksum would have been 525.
* `dc -e524?` pushes 524 and then the pipe input. The stack is: `1 473 524`. The idea is to subtract the checksum from 525, but since sum outputs 1 as well, I need to work with it.
* `--P`. After applying the two subtractions (524-(473-1)), the stack is: `52`. With 'P' I print the character with that ASCII code: `4`, the missing digit.

# Answer
> 4 votes
# Fortran 95, ~~146~~ 128 bytes

```
function m(s)
character(len=10)::s,t
t='0123456789'
do j=1,10
k=0
do i=1,9
if(s(i:i)==t(j:j))k=1
end do
if(k==0)m=j-1
end do
end

```

Not very short, I'm afraid.

**Ungolfed:**

```
integer function m(s)
    implicit none

    character(len=9)::s
    character(len=10)::t
    integer:: i, j, k

    t='0123456789'
    do j=1,10
        k=0
        do i=1,9
            if (s(i:i) == t(j:j)) k=1
        end do
        if (k==0) m=j-1
    end do

end function m

```

# Answer
> 4 votes
# Google Sheets, ~~39~~ 33 bytes

> Input is entered into cell **`A1`**.

**Code:**

```
=REGEXEXTRACT(4&2^29,"[^"&A1&"]")

```

*Saved 6 bytes thanks to Steve Kass.*

**Previous Code:**

```
=REGEXEXTRACT("0123456789","[^"&A1&"]")

```

**Result:**

# Answer
> 4 votes
# Bash (+utilities), ~~22~~, 19 bytes

* Use `seq` instead of brace expansion, -3 bytes (Thx @Riley !)

```
seq 0 9|tr -d \\n$1

```

**Test**

```
$seq 0 9|tr -d \\n123456789
0

```

Try It Online!

# Answer
> 4 votes
# Bash, ~~36~~ 30 bytes

```
(fold -1;seq 0 9)|sort|uniq -u

```

Try it online!

~~Posting to get golfing tips over this.~~

Thanks @DigitalTrauma, big fan ;)

`fold -1` writes one char of input per line

`seq 0 9` writes 0..9 one per line after this.

Those lines are fed to `sort` and filtered by `uniq -u` displaying only not duplicated lines.

# Answer
> 3 votes
# PowerShell, 30 bytes

```
param($n)0..9|?{$n-notmatch$_}

```

Try it online!

Takes input `$n`, constructs a range `0..9` (i.e., `0, 1, 2 ... 9`), then uses a `Where-Object` clause (the `|?{...}`) to pull out the number that does regex `-notmatch`. That's left on the pipeline, output is implicit.

# Answer
> 3 votes
# CJam, 5 bytes

```
A,sq-

```

Try it online!

```
A,     e# The range from 0 to 9: [0 1 2 3 4 5 6 7 8 9]
  s    e# Cast to a string: "0123456789"
   q   e# The input
    -  e# Remove all characters from the range that are in the input
       e# Implicit output

```

# Answer
> 3 votes
# GNU sed, 36 bytes

Includes +1 for `-r`

```
s/$/0123456789/
:
s/(.)(.*)\1/\2/
t

```

Try it online!

```
s/$/0123456789/ # Append 0123456789
:               # Start loop
s/(.)(.*)\1/\2/ # remove a duplicate character
t               # loop if something changed

```

# Answer
> 3 votes
# 05AB1E, 5 bytes

```
žhISK

```

Try it online!

**Explanation**

```
žh     # from the string "0123456789"
    K  # remove
  IS   # each digit of the input

```

# Answer
> 3 votes
# Brachylog (2), 5 bytes

```
ẹ:Ị↔x

```

Try it online!

Arguably should be shorter (I'm still confused as to why the  is necessary), but this is the best I could do.

## Explanation

```
ẹ:Ị↔x
ẹ      Split the input into a list of characters
 :Ị    Pair that list with the string "0123456789"
   ↔x  Remove all elements of the list from the string

```

# Answer
> 3 votes
# Japt, 6 bytes

```
¬x n45

```

Try it online!

### Explanation:

```
¬x n45
   n45     // 45-
¬          //    Split the input into an array "123" → ["1","2","3"]
 x         //    Return the sum of all the items ["1","2","3"] → 6
           // 45 - 6 = output

```

# Answer
> 3 votes
# Befunge 98, ~~14~~ 12 bytes

I saved 1 byte by moving the program onto 1 line and 1 byte by doing some better math

```
~+;@.%a--7;#

```

Try it online!

### Explanation

The sum of the ASCII values range from 477 to 468 depending on which number is missing. By subtracting this from 7, we get the range -470 to -461. By modding this number by 10, we get the range 0 - 9, which we can then print.

```
~+;       ;#    Sums the ASCII values of all characters to stdIn
~          #    The # doesn't skip over the ~ because it's on the end of a line
~               Once EOF is hit, the ~ reverses the IP's direction
          ;#    Jump the ; that was used before
       --7      Subtract the sum from 7 (really just 0 - (sum - 7))
     %a         Mod it by 10
   @.           Print and exit

```

The reason I use the ASCII values instead of taking integer input is because the `&` command in Try it Online halts on EOF (Even though it should reverse the IP). The `~` works correctly, though.

### Old Program, 14 bytes

```
#v~+
@>'i5*--,

```

The sum of the ASCII values of all 10 digits is 525. By subtracting the sum of the given digits from 525, we get the ASCII value of the missing character.

```
#v~+         Sums the ASCII values of all characters on stdIn
             Moves to the next line when this is done
 >'i5*       Pushes 525 (105 * 5)
      --     Subtracts the sum from 525
@       ,    Prints and exits

```

# Answer
> 3 votes
# Common Lisp, 47 bytes

```
(lambda(s)(- 45(reduce'+ s :key'digit-char-p)))

```

Ungolfed:

```
(lambda (s) (- 45 (reduce '+ s :key 'digit-char-p)))

```

Explaination:

```
(reduce '+ s :key 'digit-char-p)

```

This loops through the chars in `s`, converts them to digits, and adds them. Digit-char-p, conveniently, return the number of the char as its "true" value, so it can be used as a test or a conversion.

```
(- 45 ...)

```

Subtract from 45 gives back the digit that was missing from the input.

# Answer
> 3 votes
# Cubix, 18 Bytes

```
5v&;52/ni?@.>!&oW+

```

Expanded

```
    5 v
    & ;
5 2 / n i ? @ .
> ! & o W + . .
    . .
    . .

```

Try it here

Uses the same sort of method as this brain-flak answer.

Create the value -525 on the stack by pushing 5, 2, concatenate, push 5, concatenate and negate.
Then repeatably get input and add until end of input is hit.
Remove the last input, negate(make positive) the last add result, output the character and halt.

The reason for working from -525 up is that the character output is hit for each input iteration. Since the value is negative, nothing is output until the loop is exited and the negative value is made positive.

# Answer
> 3 votes
# PHP, 37 bytes

```
<?=45-array_sum(str_split($argv[1]));

```

# Answer
> 3 votes
# dc, ~~12~~ 10 bytes

```
Cdi?B%-B%p

```

Try the dc version online!

This uses the fact that the sum of the digits from 0 to 9 is 45, which is 1 more than a multiple of 11.

The program works by viewing the input as a base 12 number, finding its remainder when divided by 11, and subtracting that from 12 (to find the missing digit). The only catch is that if 0 or 1 is the missing digit, this would give an answer of 11 or 12, respectively, so I mod out by 11 one additional time at the end to take care of those cases.

---

This yields a short bash solution also:

# Bash \+ Unix utilities, ~~17~~ 15 bytes

```
dc -eCdi?B%-B%p

```

Try the bash version online!

# Answer
> 3 votes
# K (ngn/k), 5 bytes

```
477-/

```

Try it online!

Subtracts the ASCII character codes of the input string from 477.

# Answer
> 3 votes
# Vyxal, 3 bytes

```
kd⊍

```

Try it Online!

Imagine not having set operations.

## Explained

```
kd⊍
kd    # "0123456789"
  ⊍   # set(↑) ^ set(input)

```

# Answer
> 3 votes
# Risky, 5 bytes

```
+0/+/-_?}*

```

Input and output are integers. Try it online!

### Explanation

Here's a rough diagram of the program's parse tree:

```
    +
    -
  0   _
 +     }
/ /   ? *

```

It calculates the set difference between the list of numbers 0 through 9 and the list of digits in the input (example input 134567890):

```
  /         5
  /+/       5+5 = 10
 0/+/       range(10) = [0,1,2,3,4,5,6,7,8,9]
       ?    input number = 134567890
         *  10
       ?}*  to-base(134567890, 10) = [1,3,4,5,6,7,8,9,0]
      _?}*  no-op
 0/+/-_?}*  diff([0,1,2,3,4,5,6,7,8,9], [1,3,4,5,6,7,8,9,0]) = [2]
+0/+/-_?}*  sum([2]) = 2

```

---

If input as a list of digits is acceptable, here's a **3-byte** solution:

```
+0*-_?

```

It's the same idea, just skips the base-conversion step.

# Answer
> 3 votes
# Fig, \\$4\log\_{256}(96)\approx\\$ 3.292 bytes

```
Fxcd

```

Try it online!

```
Fxcd
Fx   # Remove all elements of the input
  cd # From the string "0123456789"

```

# Answer
> 2 votes
# Pyth, 5 Bytes

```
-jkUT

```

try it!

### explanation

```
-jkUT
    T   # 10
   U    # The unary range of ten: [0,1,..,9]
 jk     # join that on the empty string
-       # set minus

```

"-jUT" also kinda works but produces newlines for every int.

# Answer
> 2 votes
# Röda, 28 bytes

```
{(_/"")|ord _|sum|chr 525-_}

```

Try it online!

# Answer
> 2 votes
# C (tcc), ~~36~~ 31 bytes

```
f(long*s){s=9-(*s+s[1]%16)%15;}

```

Takes a string as input and returns an int. As written, this work only on little-endian architectures.

The lack of a `return` statement is undefined behavior, but this works with tcc and gcc.

Try it online!

### Alternate version, 33 bytes, no UB

```
f(long*s){*s=57-(*s+s[1]%16)%15;}

```

Takes a string pointer as input and overwrites the string with the result (allowed by default).

While this is perfectly valid C, it will *not* work with compilers such as gcc, which store strings in read-only memory sections.

Try it online!

# Answer
> 2 votes
# Perl 5 `-p`, 12 bytes

```
$_=-hex()%15

```

Try it online!

Explanation:

Interprets input as hex string, negates it, and calculates modulo 15 (based on xnor's Python answer).

# Answer
> 2 votes
# , 9 bytes

```
Num_j_&-.

```

Try it online!

# Answer
> 2 votes
# Wren, 31 bytes

```
Fn.new{|x|"0123456789".trim(x)}

```

Try it online!

## Explanation

```
Fn.new{|x|                      // New anonymous function with parameter x
          "0123456789"          // Declare all the numbers
                      .trim(x)  // Trim out everything included in x
                              } // The remaining number is the result

```

# Answer
> 2 votes
# Clojure, 28 bytes

```
#(- 477(apply +(map int %)))

```

# Answer
> 2 votes
# Javascript, ~~18~~ 17 bytes

-1B from tsh

```
s=>9-('0x9'+s)%15

```

```
F=
s=>9-('0x9'+s)%15
;
console.log(F('135792048'))
```

# Answer
> 2 votes
# Dash (POSIX shell with POSIX utility ), ~~50~~ ~~47~~ 27 bytes

```
$((1${1%0*}-1$1?9-9$1%9:0))

```

Try it online!

The code above evaluates to a string of digit.

## Alternative

```
$((1${1#*0}-1$1?9-9$1%9:0))

```

## How it works

* `${1%0*}`. If $1 has 0, then remove digits from right up to 0; else unchanged.
* `${1#*0}`. Similar but from left.
* Why `1$1` and `9$9`? Numbers begining from 0 is octal; but it would be syntax error if $1 has 8 and 9. They are for workarounding.

# Answer
> 2 votes
# Excel, 28 bytes

```
=SUM(45,-MID(A2,ROW(1:9),1))

```

# Answer
> 2 votes
# Julia 1.0, 22 bytes

```
~x=(w='0':'9')[w.∉x]

```

Try it online!

# Answer
> 1 votes
# Perl 5, 21 bytes

20 bytes of code + `-p` flag.

```
s/./+$&/g;$_=45-eval

```

Try it online!
Note that the input needs to be supplied *without* final newline (with `echo -n` for instance).

---

Some other (longer) approaches (all with `-p` flag):

```
$\=45;$\-=$_ for/./g}{

$_=9876543210=~s/[$_]//gr

for$@(0..9){$\=$@if!/$@/}}{

```

# Answer
> 1 votes
## Batch, ~~83~~ ~~76~~ 52 bytes

```
@set/pn=
@cmd/cset/a(641670-0x%n:~,4%-0x%n:~4%)%%15

```

Takes input on STDIN. Uses @xnor's hex modulo 15 trick, except that a) Batch only has 32-bit integers, so I have to split the string into two b) Batch only does remainder, not modulo, so I have to subtrat the values from a large multiple of 15 first.

# Answer
> 1 votes
# PHP, 43 Bytes

```
for(;strpos(_.$argv[1],48+$i++););echo$i-1;

```

# PHP, 50 Bytes

```
<?=join(preg_grep("#[{$argv[1]}]#",range(0,9),1));

```

# Answer
> 1 votes
## QBIC, 25 bytes

```
;{~instr(A,!a$)|a=a+1\_Xa

```

Explanation

```
;       Get the input as A$
{       Start an infinite DO loop
~instr  Test if A$ has an occurrence of a% cast to string
(A,!a$) a starts out as 0. !..$ casts to string.
|a=a+1  If we did find an instance, tets for the next a
\_Xa    Else, quit, printing our missing number.

```

# Answer
> 1 votes
# C, 44 bytes

```
j;f(char*s){for(j=477;*s;)j-=*s++;return j;}

```

Try it online!

# Answer
> 1 votes
# PHP, 53 bytes

There allready was a array\_sum and regex solution, wanted to provide another:

```
print_r(array_diff(range(0,9),str_split($argvs[1])));

```

A few bytes more, but as bonus it will provide *all* missing numbers.

# Answer
> 1 votes
# MATL, 6 bytes

```
4Y2jX-

```

Try it at **MATL Online**

**Explanation**

```
4Y2     % Pre-defined literal for '0123456789'
j       % Grab input as a string
X-      % Compute the set difference between the two, yields the characters in
        % '0123456789' that are missing in the input
        % Implicitly display the result

```

# Answer
> 1 votes
# JavaScript, 26 bytes

```
v=>45-eval([...v].join`+`)

```

I'm not a big fan of eval, but it does the job. The sum of all digits 0-9 is 45. 45 minus the sum of the passed-in digits is the value of the missing digit.

**Test**

```
f=v=>45-eval([...v].join`+`)

function test() {

  var i=I.value;
  O.textContent = f(i)
}

test()
```

```
<input oninput='test()' value='012987654' id=I>
<pre id=O></pre>
```

# Answer
> 1 votes
# Scala, 9 bytes

```
477-_.sum

```

To use it, assign it to a variable:

```
val f:(String=>Int)=477-_.sum

```

`_` is syntactix sugar for the arguments of a function, so this expands to `x => 477 - x.sum`, which will subtract the sum of the ascii codes of the input from 477.

# Answer
> 1 votes
# , 14 bytes

```
((i.10)-."."0)

```

Try it online!

J is always surprisingly inadequate for golfing :(

```
(                )  NB. Monadic fork: (f g h) x = (f x) g (h x)
  (i.10)            NB. Array of integers from 0 to 9
            "."0    NB. Digits of string (". = evaluate, "0 = each atom)
         -.         NB. Except

```

# Answer
> 1 votes
# Pure bash, 28

```
a=1234567890
echo ${a//[$1]}

```

Try it online.

# Answer
> 1 votes
# AWK, 18 bytes

```
{$0=/0/?9-$0%9:0}1

```

AWK live editor

Explanation: If 0 exists in the input, return 9 - modulo 9 of the input, otherwise return 0. Implicit print.

# Answer
> 1 votes
## TXR Lisp, 28 bytes:

This is 28 bytes. It reads a line of digits and yields a string of the missing ones as the result value;

```
(diff"0123456789"(get-line))

```

This uses the `awk` macro to do read every line of input and print the missing digits. It only adds one byte to the length:

```
(awk((mf(diff"0123456789"))))

```

At the system prompt:

```
$ txr -P '(diff"0123456789"(get-line))'
135249
0678

$ txr -e '(awk((mf(diff"0123456789"))))'
123456789
0
234567890
1
012357698
4
13579
02468
^D

```

# Answer
> 1 votes
**PHP, ~~50~~ 39 Bytes**

~~`function x($y){echo(45-array_sum(str_split($y)));}`~~

Jörg Hülsermann's answer prompted me to try the CLI method, Thanks.

```
echo 45-array_sum(str_split($argv[1]));

```

Test it at the command line with:

```
php -r 'echo 45-array_sum(str_split($argv[1]))."\n";' /'12346789'

```

Test it (The old version) here if you'd like.

Wheat Wizard's answer put me in the right direction and I got help from This Answer

# Answer
> 1 votes
# Keg, ~~14~~ 8 bytes

```
?⅀ȍ$-

```

Try it online! *-6 bytes thanks to @A̲̲*

## Answer History

### 14 bytes

```
`0123456789`᠀-

```

Try it online!

# Answer
> 1 votes
## , ~~13~~ 7 bytes

```
'0'9.St

```

## Explanation

```
'0'9.   % Define the range of string 0 to 9
     S  % Swap so that instructions are in the right order
        % a[0], "0...9" -> "0...9", a[0]
      t % Trim out everything in 0...9 that appears in a[0]
        % The result is the remaining number

```

## W, 8 bytes

```
CJ525S-C

```

## Explanation

```
C         % Convert every character to its code point form
 J        % Sum the list
  525S-   % Minus 525 from the value
       C  % Convert to character form
          % Implicit output

```

# Answer
> 1 votes
## TI BASIC, 23 bytes

```
45-sum(seq(expr(sub(Ans,I,1)),I,1,9

```

Turns the input string in Ans into a list containg the digits and then sums the list so that the number can be derived from subtracting the sum from 45. The byte count is affected by the 2 byte tokens expr(, sub(, and Str1. A full program could prompt for Str1 for 5 additional bytes.

# Answer
> 1 votes
# 05AB1E, 4 bytes

```
žhsм

```

Try it online!

```
žhsм  # full program
   м  # remove all characters of...
  s   # implicit input...
   м  # from...
žh    # "0123456789"
      # implicit output

```

`s` can also be `I` or `¹` and `h` can be `m` with no change in functionality.

# Answer
> 1 votes
# BRASCA, 16 bytes

```
477SSm8[a+A{]x-n

```

Try it online!

## Explanation

```
<implicit input>     - Push STDIN to stack
477SSm               - Push 477 (the sum of all digits' ASCII codes) to the bottom
      8[    ]        - Loop 9 times:
        a+A          -   Put loop counter in register, add the top two digits, then take it back out.
           {         -   Decrement the loop counter
             x-      - Remove the loop counter, then subtract the sum of all digits from 477
               n     - Output the result as a number

```

# Answer
> 1 votes
# Pxem, Filename: 28 bytes + Content: 0 bytes = 28 bytes.

* Filename (Unprintables are escaped): `\011.t.w0.i.-.+.m\001.-.c.t.a\055.-.n`
* Content: empty.

Try it online! (with pxem.posixism)

## With comments

```
XX.z
# push 9; heap=pop
.a\011.tXX.z
# while empty || pop!=0; do
.a.wXX.z
  # push 48; push getchar
  .a0.iXX.z
  # push abs(pop-pop); if size>=2; then push pop+pop; fi
  .a.-.+XX.z
  # push heap; push 1; push abs(pop-pop)
  .a.m\001.-XX.z
  # dup; heap=pop
  .a.c.tXX.z
# done
.a.aXX.z
# push 48; push abs(pop-pop); printf "%d", pop
.a\055.-.n

```

# Answer
> 1 votes
# CSASM v2.3, 129 bytes

```
func main:
lda 0
sta $1
in ""
conv ~arr:char
pop $a
push "0123456789"
.lbl a
push $a
ldelem $1
sub
inc $1
push $1
push 9
sub
brtrue a
print
ret
end

```

**Commented and ungolfed:**

```
func main:
    ; Initialize $1 to 0
    lda 0
    sta $1

    ; Get the input, convert it to an array of <char>s, then store it in $a
    in ""
    conv ~arr:char
    pop $a

    push "0123456789"
    .lbl loop
        ; Get the <char> in $a at index $1
        push $a
        ldelem $1

        ; Remove it from the <str> currently on the stack and push the updated <str>
        sub

        ; Increment $1 and stop looping if $1 == 9
        inc $1
        push $1
        push 9
        sub
        brtrue loop

    ; The string will now only contain the remaining digit.  Print it
    print
    ret
end

```

# Answer
> 1 votes
# Mascarpone, ~~82~~ 53 bytes

```
[9876543210]$v[v'$>,<]v*'#<^v'.>1#########^0123456789

```

Try It Online!

### Explanation

```
[9876543210]$      // push the string '[9876543210' (we can ignore the '[')
v                  // push the current interpreter
 [      ]v*        // define an operation (under the current interpreter)
  v'$>,<           // "bind a symbol from stdin to 'Pop ToS'"
           '#<^    // bind this operation to '#' and install it to the environment
v'.>1              // push an interpreter that defaults to "Output ToS"
     #########     // bind 9 symbols from stdin to "Pop ToS"
              ^    // install this interpreter to the environment
0123456789         // one of these will output ToS, the rest will only pop
                   // the symbols to output are on the stack from line 1

```

# Answer
> 1 votes
# Factor \+ `math.unicode`, ~~25~~ 24 bytes

```
[ "0123456789"swap ∖ ]

```

Try it online!

Set difference () with `"0123456789"`.

# Answer
> 1 votes
## x86‑64 assembly machine code, 17 B

### input

* address of string buffer in 64‑bit register `rsi`
* string buffer consists of exactly 9 ASCII-encoded Western-Arabic digits

### code listing

```
  1                      missing_integer:
  2 00000000 6A09           push 9          ; rsp ≔ rsp − 8  rsp↑ ≔ 9
  3 00000002 59             pop rcx         ; rcx ≔ rsp↑     rsp ≔ rsp + 8
  4 00000003 31C0           xor eax, eax    ; eax ≔ 0
  5 00000005 BADD010000     mov edx, 477    ; edx ≔ 477
  6                      .digit_sum:
  7 0000000A AC             lodsb           ;  al ≔ rsi↑     rsi ≔ rsi + 1
  8 0000000B 29C2           sub edx, eax    ; edx ≔ edx − eax
  9 0000000D E2FB           loop .digit_sum ; ecx ≔ ecx − 1   ZF ≔ ecx = 0
 10                                         ; if ¬ZF then goto digit_sum
 11 0000000F 92             xchg eax, edx   ; shorter than `mov eax, edx`
 12 00000010 C3             ret

```

### output

* the “missing” integer in `ax`

# Answer
> 1 votes
# jq -R, 15 bytes

```
explode|477-add

```

Try it online!

# Answer
> 1 votes
# Nibbles, 2.5 bytes (5 nibbles)

```
`r-_$

```

```
`r-_$
`r      # get the first integer found in
        # the string of
  - $   # remove the command-line arg
   _    # from the string in STDIN
        # (but if there is no STDIN,
        # from all printable ASCII)

```

Input string is provided as a command-line argument.
If STDIN is empty, Nibbles assigns a default value of 'the list of printable ascii characters in a more useful order". The first (and only) integer present in this list after the input string is removed should be the missing digit from the input string.

(Note that since Nibbles will check to see if there's anything in STDIN, in the screenshot above I've pressed 'ctrl-D' to terminate STDIN with no input)

# Answer
> 1 votes
# x86‑64 assembly machine code, 13 B

```
f:      use64
6A09    push 9
59      pop rcx
6A01    push 1
5A      pop rdx
a:
AC      lodsb
30C2    xor dl, al
E2FB    loop a
92      xchg eax, edx
C3      ret

```

read string from `[rsi]` and return `rax`

# Answer
> 1 votes
# GolfScript, 6 bytes

```
10,`^~

```

Try it online!

There's a shorter, 4-byte solution if input can be taken in the form of an array of integers:

```
10,^

```

Try it online!

# Explanation

```
10,`^~

10,     # create an array of integers from 0-9
   `    # convert it into a string
    ^   # setwise difference
      ~ # dump array onto the stack

```

The 4-byter just removes the need for a string because it takes input as an array and the difference doesn't include any `[` characters, removing the need for the `~`

# Answer
> 0 votes
# Lambdabot Haskell, 14 bytes

```
(['0'..'9']\\)

```

After realizing I could just make a list with the String "0123456789" instead of the integers \[0,1,2,3,4,5,6,7,8,9\], the step for converting the string to integers could be skipped.

Type is now String -\> String (takes a string and returns a string with the correct number). Call like:

```
(['0'..'9']\\)"149263708"         -- Outputs "5"

```

## Previous:

```
([0..9]\\).map digitToInt

```

Uses set difference, unlike the other Haskell answer, type String -\> Int

Call like

```
([0..9]\\).map digitToInt$"123467890"  -- Outputs 5

```

# Answer
> 0 votes
# Ruby, 25 bytes

```
->x{'0123456789'.tr x,''}

```

Not terribly competitive, I'm afraid

# Answer
> 0 votes
# Pip, 5 bytes

5 bytes seems to be the number for all golfing languages that aren't Jelly.

```
,tDCa

```

Takes input as a command-line argument. Try it online!

### Explanation

```
,t     Range(10)
  DC   From each element, delete all characters...
    a  ...that are in 1st cmdline arg
       Concatenate and print (implicit)

```

The result is actually a list like `["";"";"";"";4;"";"";"";"";""]` (which is what you get if you put `RP` at the front of the code). Lists by default are concatenated together before printing, so all you will see is `4`.

# Answer
> 0 votes
# C (clang), 31 bytes

```
f(x){return x?f(x/10)-x%10:45;}

```

Strictly speaking, f(x) returns the sum of the missing digits. This lets me knock off a digit, get the sum of the missing digits, then add it back on.

Try it online!

# Answer
> 0 votes
# Octave, ~~20~~ ~~19~~ 14 bytes

```
@(a)477-a*~~a'

```

Try it online!

Developed independently but the same as some other answers.

```
a'          transpose of array `a`
~~a'        convert all elements of a' to 1
a*~~a'      matrix multiplication of `a` with a column vector of 1s
            that is equivalent to sum(a)
477-a*~~a'  subtract from [477=sum('0123456789')-48]

```

# Answer
> 0 votes
# Java 7, ~~61~~ 54 bytes

```
long d(int n){return(15-Long.valueOf(n+"",16)%15)%15;}

```

Based on *@Neil*'s JavaScript (ES6) answer (just like JavaScript, Java uses remainder for negative-modulo. Original port is from *@xnor*'s Python answer)

**Old answer (61 bytes):**

```
String c(int n){return"0123456789".replaceAll("["+n+"]","");}

```

Try it here.

# Answer
> 0 votes
## REXX, 36 bytes

```
#=0123456789
arg n
say verify(#,n)-1

```

# Answer
> 0 votes
# AHK, 39 bytes

```
i=[%1%]
Send % RegExReplace(99066**2,i)

```

Again, the inherent confusion between the input variable `1` and the actual number 1 causes confusion in AHK functions. At least it only cost 3 bytes this time.

`99066**2` = `99066^2` = `9814072356` (a trick I copied from Rod's answer)

# Answer
> 0 votes
# C#, 21 bytes

```
z=>45-z.Sum(v=>v-'0')

```

The expression `v-'0'` takes the char value such as `'3'` and subtracts the char value for `'0'`, leaving the value 3, essentially converting the character 3 into the integer 3.

45 is the sum of all the numbers 0 through 9. 45 - the sum of the passed-in integers yields the missing integer.

Sample code

```
public static void Main()
{
    Func<string, int> X = z=>45-z.Sum(v=>v-'0');

    Console.WriteLine(X("123456789"));
    Console.WriteLine(X("134567890"));
    Console.WriteLine(X("867953120"));
}

```

Test Here: https://dotnetfiddle.net/yanR5S

# Answer
> 0 votes
# Chip, 64 bytes

```
Azv~a
##'Bzv~b
`^v##'Czv~c
*f|`^-##'Dzv~d
Z~'~e `^-##'
ZZZZZZZ~S

```

Try it online!

Chip is a 2D language that operates on individual bits in a byte stream. Each byte of input is broken down into its component bits for computation, then stitched back together for output.

This solution uses a rather simple algorithm, that is only a minor twist on that used by many of the other solutions:

1. Start with a value of `0x2`:

```
 0+1+2+3+4+5+6+7+8+9 =  45 (0x2D)
                 ~45 = -46 (0xD2)    *
          -46 & 0x0F =   2  (0x2)

```

<sup>* I only do half of two's complement negation; I skip the increment at the end for a reason. I'll get back to this.</sup>
2. Add each code point in the string, masked with `0x0F`, ignoring carries.
3. After the ninth addition, the current value will be equal to -1 minus the missing digit, masked with `0x0F`:

Let's say we were missing the digit '4':

```
              -1 - 4 =  -5  (0xB)
               ~(-5) =   4  (0x4)    *

```

<sup>* Again, we only do half of negation. This instance cancels out the offset introduced by the previous negation.</sup>
4. Prefix the value with `0x3`, giving the codepoint for the missing digit:

```
          0x30 | 0x4 =  52 (0x34)

```

What portions of the code do each bit? Well, they're a bit mixed together, but I'll try to cover the highlights:

* The `#` elements do the addition described in step 2.
* The `z` elements near the adders carry over the current value to the next cycle so that we can have a running sum.
* The `Z` elements keep track of which digit of the input we are on, handling the condition in step 3. They also provide the signal used to initialize the adders to `0x2`, as described in step 1.
* The `S` element suppresses all output until the `Z` elements disable it on the final digit. (If you are looking at the TIO, try deleting this element to see all the intermediate values. Also, adding the flag `-v` will print the actual code points to stderr.)
* The letters `A` through `D` are reading the 4 low bits of the input, and `a` through `d` write those same bits of the output.
* The letters `e` and `f` provide the value `0x30` to the output as described in step 4.

# Answer
> 0 votes
# D, 24 bytes

```
writeln(477-readln.sum);

```

Just add up all characters in the given string (*not* terminated by a newline). The sum is `s = 48 * 9 + (0 + 1 + 2 + ... + 9 - x) = 477 - x`, therefore, `x = 477 - s`.

The calls make use of optional parentheses (-4 bytes), and `.sum` invocation uses uniform function call syntax (-1 more byte).

Try it online!

# Answer
> 0 votes
## Q, 24 bytes

```
{1#iasc"0123456789"in x}

```

Gets a boolean vector between the expectation and input, then sorts the indices of the expectation by that boolean vector in ascending order, first value always being the missing element since boolean for it is set to 0 and we know that value=index in this case.

# Answer
> 0 votes
# Noodel, 8 bytes

```
ɲdFḶṡạĖ⁻

```

Try it:)

---

## How it works

```
ɲdFḶṡạĖ⁻
         # Input implicitly pushed onto the stack.
ɲd       # Pushes the string "0123456789" onto the stack.

  FḶṡạĖ⁻ # Loops nine times removing digits from the string "0123456789" producing the missing number.
  F      # Pushes the string "F" onto the stack.
   Ḷ     # Consumes the string "F" and converts to a base 98 number producing 9 then loops the following that many times.
    ṡ    # Swaps the string "0123456789" with the input on the stack.
     ạ   # Gets the ith element from the input and pushes it onto the top of the stack.
      Ė  # Grabs the string "0123456789" at the bottom of the stack and puts it at the top.
       ⁻ # Removes the element pulled out of the input from the string.
         # Implicit end of the loop.

         # Implicit push to the screen, outputting the missing digit.

```

# Answer
> 0 votes
## Racket 106 bytes:

```
(filter-not(λ(x)(member x(string->list(number->string n))))
(for/list((i(range 48 58)))(integer->char i)))

```

Ungolfed:

```
(define (f n)
  (filter-not
   (λ(x)
     (member x
             (string->list
              (number->string n))))
   (for/list((i(range 48 58)))(integer->char i))))

```

Testing:

```
(f 867953120)

```

Output:

```
'(#\4)

```

# Answer
> 0 votes
# Pyt, 5 bytes

```
ɳą←ą\

```

Try it online!

Takes input as a string (with quotes)

```
ɳ          push "0123456789"
 ą         convert to array of characters
  ←ą       get input string; convert to array of characters
    \      set difference; implicit print

```

# Pyt, 5 bytes

```
Ś9△-~

```

Try it online!

Takes input without quotes

```
Ś        implicit input; sum of digits
 9△      45 (9th triangle number)
   -     subtract
    ~    negate; implicit print

```

# Answer
> 0 votes
# Thunno 2, 3 bytes

```
kDḍ

```

Attempt This Online!

#### Explanation

```
kDḍ  # Implicit input
  ḍ  # Symmetric set difference
kD   # with the string "0123456789"
     # Implicit output

```

# Answer
> 0 votes
# Rust, 43 bytes

```
|s:&str|s.bytes().fold(477,|s,b|s-b as i32)

```

This is the same strategy as in Level River St's Ruby answer.

Attempt This Online!

---
Tags: code-golf, string, number, sequence, integer
---


# Question
Title: What is the shortest regex for the month of January in a handful of the world's languages?
What is the shortest regular expression equivilant to the following?

```
ENERO|GENER|GENNAIO|IANUARI|IANUARII|IONAWR|JAANUARIL|JANAIRU|JANAR|JANNEWARIS|JANUAR|JANUARI|JANUARIE|JANUARO|JANUARY|JANUWALE|JANVIER|JANVYE|JENUWARI

```

The shortest regex, in bytes, wins.

If you are worried about what flavor of regex we are using, then be the first one to edit my question, and you can have a link to a description of the specific regex flavor of your choice. Please choose a mainstream regex flavor, nothing too esoteric. `*` should mean `zero or more`. `+` should be `one or more` and so on and so forth.

# Answer
### Python `re` module, 104 ~~110~~ bytes

-6 based on Neil's comment

```
JENUWARI|JA(N(VYE|VIER|UWALE|UAR(IE?|Y|O)?|NEWARIS|AIRU|AR)|ANUARIL)|IONAWR|IANUARII?|GEN(NAIO|ER)|ENERO

```
> 6 votes

# Answer
# 104 bytes

```
ENERO|GEN(ER|NAIO)|IANUARII?|IONAWR|JAANUARIL|JAN(AIRU|AR|NEWARIS|UAR(IE?|O|Y)?|UWALE|VIER|VYE)|JENUWARI

```

Should work with ~~any~~ most regex styles, since I only use `|?()`, but below is a TIO for Java:

Try it online.

The last portion of the regex above could be one of these three for the same byte count:

* `JAANUARIL|JAN(AIRU|AR|NEWARIS|UAR(IE?|O|Y)?|UWALE|VIER|VYE)|JENUWARI` (the one used above)
* `JA(ANUARIL|N(AIRU|AR|NEWARIS|UAR(IE?|O|Y)?|UWALE|VIER|VYE))|JENUWARI` (`JA` combined for suffix of two options)
* `J(AANUARIL|AN(AIRU|AR|NEWARIS|UAR(IE?|O|Y)?|UWALE|VIER|VYE)|ENUWARI)` (`J` combined for suffix of three options)

Very curious if \<104 bytes is even possible at this point.

†: Apparently not all. Thanks for the info *@ikkachu*.
> 4 votes

# Answer
# 110 bytes

```
J(A(N(U(AR([OY]|IE?)?|WALE)|V(IER|YE)|A(IRU|R)|NEWARIS)|ANUARIL)|ENUWARI)|I(ANUARI?I|ONAWR)|GEN(NAIO|ER)|ENERO

```

Which may be more easily read with designified whitespace like this:

```
J(
    A(
        N(
            U(
                AR(
                    [OY]
                   | IE?
                )?
              | WALE
            )
            | V(IER | YE)
            | A(IRU | R)
            | NEWARIS
        )
        | ANUARIL
    )
  | ENUWARI
)
| I(ANUARI?I | ONAWR)
| GEN(NAIO   | ER)
| ENERO

```

This pattern works both in engines guaranteed to select the leftmost valid alternative in an `A|B|C` set, as well as in engines guaranteed to choose the longest valid alternative overall from that set.

Because of its alternation of literal strings, this pattern runs faster in engines with the Aho–Corasick trie optimization than in those lacking that feature.
> 3 votes

# Answer
# 104 bytes

```
ENERO|GEN(NAIO|ER)|IANUARII?|IONAWR|JA(ANUARIL|N(AIRU|AR|NEWARIS|UAR(IE?|O|Y|)|UWALE|VIER|VYE))|JENUWARI

```

Or, formatted more nicely (with insignificant whitespace):

```
ENERO |
GEN(
    NAIO |
    ER
) |
IANUARI I? |
IONAWR |
JA(
    ANUARIL |
    N(
        AIRU |
        AR |
        NEWARIS |
        UAR(
            I E? |
            O |
            Y |
            [the empty string]
        ) |
        UWALE |
        VIER |
        VYE
    )
) |
JENUWARI

```
> 1 votes

# Answer
# 104 bytes

```
ENERO|GEN(ER|NAIO)|IANUARII?|IONAWR|JA(ANUARIL|N(UWALE|VIER|VYE|UAR(IE?|O|Y)?|NEWARIS|AIRU|AR))|JENUWARI

```

Spent way too long trying to find a shorter solution and am convinced it doesn't exist.
> 0 votes

---
Tags: code-golf, regular-expression
---


title: Render text in a slanted ASCII-art font

text:
# Question
Title: Render text in a slanted ASCII-art font
**Given a text input such as:**

```
THE QUICK
BROWN FOX
JUMPS OVER
THE LAZY
DOG

```

**render the following output:**

```
                            /\
                            \ \
                            /  \
                           / /\/
                          / /   /\
                         / /   / /
                      /\ \/   / / /\
                     /  \    /  \/ /
                    / /\/   / /\  / /\
                   /  \/\   \/ / / /  \
                  / /\/\/ /\  / / / /\ \
                  \ \/\  /  \ \/ /  \ \/
                   \/\/ / /\/   / /\/
                       /  \/\   \ \
                  /\  / /\/\/ /\ \ \
             /\  / /  \/ /\  /  \ \/       /\
            / / / / /\  / / / /\ \        /  \
            \ \/ / / /  \/ / / / /       / /\ \
          /\ \  / / / /\  / / / / /\    / / / /
          \ \ \/ / / / /  \ \/ / / /   / / / /
          /  \  / / / / /\ \  / / /    \ \/ /   /\
         / /\/  \ \/ / / /  \/ / / /\   \  /   / /
        / /   /\ \  / /  \     \/ / / /\ \ \  / / /\
       / /   / /  \/ / /\/     /\/ / / /  \/ / / / /
    /\ \/   / / /\  / / /\/\/\ \/\/ / / /\  / / / / /\
   /  \    /  \/ /  \/  \/\  /   /\/ / / /  \ \/ / / /
  / /\/   / /\  / /\      / / /\ \/\/ /  \   \  / / / /\
 / / /\   \/ / / /  \    / / /  \    / /\/    \/ / / /  \
/ / / / /\  / / / /\ \  / / / /\/   / / /\  /\  / / / /\ \
\ \/ / /  \ \/ /  \ \/  \/ /  \/\   \/  \/ / /  \/ / /  \/
 \/\/ / /\ \  / /\/       / /\/\/ /\    /\/ /     / /     /\
     / / / /  \ \         \/     /  \   \  /      \ \    / /
    / / / / /\ \ \              / /\ \  / /        \ \  / / /\
    \ \/ / /  \ \/       /\     \ \ \/  \/       /\ \/ /  \/ /
     \  / / /\ \        / /   /\ \ \            /  \  / /\/\/
      \/ / /  \/       / /    \ \/ /           / /\ \ \/ /\
        / / /\        / /      \  /           /  \ \/   / /
        \ \/ /       / /     /\ \/       /\  / /\/   /\ \/
         \  /        \ \    /  \        /  \ \/     /  \
          \/          \ \  / /\ \      / /\ \      / /\ \
                       \/ /  \/ /     / / / /     / / / /
                         / /\  / /\  / / / / /\  / / / / /\
                         \/ / /  \ \ \ \/ / / /  \ \/ / / /
                           / /    \ \ \  / / / /\ \  /  \/ /\
                           \/ /\/\/ /  \/ / / / /  \/ /\/\/ /
                             / /\/\/ /\   \/ / / /\  / /\/\/
                             \ \    / /   /\/ / /  \ \/ /\
                              \ \  / / /\ \/\/ / /\ \  / /
                               \/  \ \/ /     /  \ \/  \/
                                   /   /     / /\/   /\
                                  / /\/      \ \    /  \
                                  \/          \ \  / /\/
                                               \/ /  \/\
                                                 / /\/\/
                                                 \/ /\
                                                   / /
                                                   \/

```

# Rules

* The program only needs to work for upper-case A–Z, spaces and newlines. Everything else is allowed to produce undefined behaviour.
* The program is allowed to output any number of extraneous leading or trailing spaces or newlines, as long as the block of text is contiguous as shown.
* Your output may use ‘/’ (U+002F) and ‘\’ (U+005C), or (for prettier Unicode rendering) ‘╱’ (U+2571) and ‘╲’ (U+2572).
* The font must look exactly as shown above. The example contains all the letters A–Z. Arnauld has kindly provided a bitmappy version of the font here.

# Answer
# Charcoal, ~~177~~ ~~143~~ 141 bytes

```
ＷＳＦ⁶⊞υＥ⭆ι⁺?§⪪”‴!⊟γ←B)1F»$g'~δＺ@↷➙O'no⦄℅ψzＹ´´Ａ⭆≦μ6δTＫ⮌´κ？C…p⌊*RUＵρ⁻Ｅe℅²«êSＱe¹AＡＫ›Σ↓^⬤ωε!⬤fº”¶℅λ§↨℅λ²κＰ↘⪫Ｅυ⭆ι§╲ ⁼§§υ⊕κμλ¶→Ｐ↘⪫Ｅυ⭆ι§╱ ⁼§ι⊕μλ¶

```

Try it online! Link is to verbose version of code. Takes input as a list of newline-terminated strings and outputs the prettier rendering at a cost of 4 bytes. Explanation:

```
ＷＳ

```

Loop over each input string.

```
Ｆ⁶⊞υＥ⭆ι⁺?§⪪”...”¶℅λ§↨℅λ²κ

```

Look up each letter in the input string in a large compressed lookup table of ASCII encoded horizontally flipped character bitmaps. The encoded bitmaps are joined with `?` (representing blank values) before being decoded, converted into 6-bit binary (all the values are in the range 32-63), and transposed, and the bitmaps for all of the lines are collected together.

```
Ｐ↘⪫Ｅυ⭆ι§╲ ⁼§§υ⊕κμλ¶→

```

Output s where each bit changes from the next row.

```
Ｐ↘⪫Ｅυ⭆ι§╱ ⁼§ι⊕μλ¶

```

Output s at each change in bit in each row.

Edit: Saved 34 bytes by taking inspiration from @Arnauld's encoding method, but inverting the bits because that simplifies the Charcoal code. Saved 2 bytes by building up the entire bitmap at once rather than a line at a time. Note that although the bitmap has a ragged right edge the joining rows are all blank so it makes no difference. The bitmap is output rotated as compared to the previous version which explains the adjustments to the output code.
> 12 votes

# Answer
# JavaScript (Node.js), 418 bytes

Expects a list of strings.

```
a=>(m=[]).map(r=>r.join``,a.map((s,Y)=>(F=y=>~y--&&F(y,Buffer(s).map(c=>(G=x=>x^'2672020001'[c*31%87%33]^4&&G(-~x,(m[X=(a.length-Y)*6-++y+o,Y*6+y+o++]||=Array(X).fill` `).splice(X,2," /"[g(~-x)^g(x)]," \\"[v^g(x,y--)])))(g=x=>v=parseInt(['757553535371117355537131771311715575575511111444575535511117hrlhhhjlph75557353117555f3535571747722225555755552hllla552555572274217'[c*5-325+y]],32)>>x&31>>y&1),o=0)))(5))).join`
`

```

Attempt This Online!

### Font encoding

Each character is horizontally mirrored, right-aligned and converted to five 5-bit values expressed in base-32.

For instance, `N` is encoded as `"hjlph"`:

```
X...X    10001    17    'h'
X..XX    10011    19    'j'
X.X.X -> 10101 -> 21 -> 'l'
XX..X    11001    25    'p'
X...X    10001    17    'h'

```

All letter encodings are concatenated together to get a single lookup string of 130 characters. The encoding of the space (`"00000"`) is not explicitly stored.

```
 7575535353..hrlhhhjlph..5572274217
 \___/\___/  \___/\___/  \___/\___/
   A    B      M    N      Y    Z

```

To get the state of the 'pixel' at \\$(x,y)\\$ of the character whose ASCII code is \\$c\\$, we do:

```
parseInt([ lookup_string[c * 5 - 325 + y] ], 32) >> x & 31 >> y & 1

```

This code supports \\$-1\le x\le 5\\$ and \\$-1\le y\le 5\\$ so that a 1-pixel character border can be tested as well.

### Width encoding

Right padding included, most characters have a width of 4. The exceptions are as follows:

* `I` has a width of 2
* `Q` has a width of 5
* `M`, `N` and `W` have a width of 6
* the space has a width of 3

We use a lookup string, a hash function and a XOR with 4 to turn any valid ASCII code into the corresponding width:

```
'2672020001'[c * 31 % 87 % 33] ^ 4

```

Attempt This Online!

### Drawing algorithm

Basic principles:

* We draw by filling a matrix \\$m\\$, whose exact size is decided on the fly.
* We compare the pixel at \\$(x-1,y)\\$ with the pixel at \\$(x,y)\\$ to figure out if we must draw the `/` boundary.
* We compare the pixel at \\$(x,y-1)\\$ with the pixel at \\$(x,y)\\$ to figure out if we must draw the `\` boundary.

Pseudo-code:

```
for each string s at index Y in a[]:
  for y = 5 to 0:
    let o = 0
    for each character c in s:
      for x = 0 to width(c) - 1:
        let X = (a.length - Y) * 6 - y + o
        let R = Y * 6 + y + o
        if pixel(c, x, y) != pixel(c, x - 1, y):
          m[R][X] = "/"
        else:
          m[R][X] = " "
        end
        if pixel(c, x, y) != pixel(c, x, y - 1):
          m[R][X + 1] = "\"
        else:
          m[R][X + 1] = " "
        end
        o = o + 1
      end
    end
  end
end

```
> 21 votes

# Answer
# Funciton, non-competitive

Big dramatic reveal! This coding challenge was actually suggested to me by a friend. I originally wrote it in C# but then decided that this might be an excuse to flex my old Funciton muscles again. I haven’t written Funciton code in several years and this was a refreshing trip down memory lane.

If I had to do it all over again, I imagine I might implement this very differently. This is the implementation I came up with on my own before being influenced by the other answers posted here.

**Try it online!**

```
                           ╔═════════════════╗    ╓┬──╖
                           ║↓  Lookup table  ║    ╟┘➫ ║
                           ╚═════════════════╝    ╙─┬─╜
                                                 ┌──┴──────────────────────────────────────────────────────────────────────────────┐
                           ┌─────────────────────┴──────────────────────┐                                       ┌──────────────────┴─────────────────┐
                           │                               ┌────────────┴───────────┐                 ┌─────────┴────────┐                  ┌────────┴────────┐
                           │                   ╔════╗      │      ╔═══╗    ╔════╗   │   ╔═══╗ ╔═══╗   │   ╔════╗ ╔═══╗   │   ╔════╗ ╔═══╗   │   ╔═══╗ ╔═══╗   │   ╔═══╗
                           │                   ║ 16 ╟─┬────┴────┬─╢ 8 ║    ║ 16 ╟─┬─┴─┬─╢ 8 ║ ║ 4 ╟─┬─┴─┬─╢ 16 ║ ║ 8 ╟─┬─┴─┬─╢ 16 ║ ║ 8 ╟─┬─┴─┬─╢ 4 ║ ║ 2 ╟─┬─┴─┬─╢ 1 ║
                           │                   ╚════╝┌┴┐       ┌┴┐╚═══╝    ╚════╝┌┴┐ ┌┴┐╚═══╝ ╚═══╝┌┴┐ ┌┴┐╚════╝ ╚═══╝┌┴┐ ┌┴┐╚════╝ ╚═══╝┌┴┐ ┌┴┐╚═══╝ ╚═══╝┌┴┐ ┌┴┐╚═══╝
    ╔═════════════════╗    │                         └┬┘       └┬┘               └┬┘ └┬┘           └┬┘ └┬┘            └┬┘ └┬┘            └┬┘ └┬┘           └┬┘ └┬┘
    ║↓  Main program  ║    │                          │         │                 │   │             │   │              │   │              │   └────────────┐└┐ ┌┘
    ╚═════════════════╝    │                          │         │                 │   │             │   │              │   │              └──────────────┐ │ │ │
                           │                  ┌───────┴───────┐ │                 │   └─────┐ ┌─────┘   └───────┐      │   └───────────────────┐         │ │ │ │
    ╔════╗ ┌───╖ ╔═══╗     │ ╔═════╗ ╔══════╗ │ ╔═══╗ ╔═════╗ │ │ ╔═════╗ ╔═════╗ │ ╔═════╗ │ │ ╔═════╗ ╔═════╗ │      │    ╔═════╗ ╔════════╗ │         │ │ │ │
    ║ 10 ╟─┤ ǁ ╟─╢   ║     │ ║57419║ ║385324║ │ ║127║ ║56199║ │ │ ║57417║ ║57419║ │ ║25859║ │ │ ║57417║ ║57419║ │      └──┐ ║57419║ ║25312128║ │         │ │ │ │
    ╚════╝ ╘═╤═╝ ╚═══╝     │ ║47683║ ║282504║ │ ║496║ ║46254║ │ │ ║79243║ ║37781║ │ ║43344║ │ │ ║79243║ ║37781║ │         │ ║37781║ ║56720763║ │         │ │ │ │
     ╔═══╗ ┌─┴─╖           │ ║02700║ ║754621║ │ ║773║ ║80982║ │ │ ║08922║ ║62235║ │ ║36197║ │ │ ║08911║ ║62172║ │ ╔═════╗ │ ║62176║ ║11198970║ │ ╔═════╗ │ │ │ │
     ║ 0 ╟─┤ ≭ ╟─┬─┐       │ ║91420║ ║004585║ │ ║380║ ║96636║ │ │ ║39781║ ║19366║ │ ║71362║ │ │ ║32975║ ║24436║ │ ║57419║ │ ║16428║ ║26960857║ │ ║57419║ │ │ │ │
     ╚═══╝ ╘═╤═╝ └─┘       │ ║13362║ ║913748║ │ ║488║ ║66983║ │ │ ║52695║ ║61768║ │ ║83996║ │ │ ║65107║ ║21417║ │ ║47644║ │ ║21732║ ║44720451║ │ ║37781║ │ │ │ │
           ┌─┴─╖           │ ║17373║ ║829211║ │ ║444║ ║78457║ │ │ ║33243║ ║30029║ │ ║77254║ │ │ ║77280║ ║53549║ │ ║34204║ │ ║28458║ ║11713714║ │ ║62235║ │ │ │ │
           │ ʝ ╟─          │ ║1297 ║ ║812321║ │ ║9  ║ ║1361 ║ │ │ ║0305 ║ ║0529 ║ │ ║82262║ │ │ ║9697 ║ ║6673 ║ │ ║69971║ │ ║8513 ║ ║89      ║ │ ║19366║ │ │ │ │
           ╘═╤═╝           │ ╚══╤══╝ ╚═══╤══╝ │ ╚═╤═╝ ╚══╤══╝ │ │ ╚══╤══╝ ╚══╤══╝ │ ║05066║ │ │ ╚══╤══╝ ╚══╤══╝ │ ║31884║ │ ╚══╤══╝ ╚═══╤════╝ │ ║61766║ │ │ │ │
           ╔═╧══╗          │    │      ┌─┴─╖  │   │    ┌─┴─╖  │ │    │     ┌─┴─╖  │ ║58254║ │ │    │     ┌─┴─╖  │ ║27401║ │    │      ┌─┴─╖    │ ║15326║ │ │ │ │
           ║ 10 ║          │    └──────┤ ? ╟──┘   └────┤ ? ╟──┘ │    └─────┤ ? ╟──┘ ║60705║ │ │    └─────┤ ? ╟──┘ ║6737 ║ │    └──────┤ ? ╟────┘ ║5633 ║ │ │ │ │
           ╚════╝          │           ╘═╤═╝           ╘═╤═╝    │          ╘═╤═╝    ╚══╤══╝ │ │          ╘═╤═╝    ╚══╤══╝ │           ╘═╤═╝      ╚══╤══╝ │ │ │ │
                           │             │             ┌─┴─╖    │            │       ┌─┴─╖  │ │            │       ┌─┴─╖  │             │         ┌─┴─╖  │ │ │ │
                           │             └─────────────┤ ? ╟────┘            └───────┤ ? ╟──┘ │            └───────┤ ? ╟──┘             └─────────┤ ? ╟──┘ │ │ │
                           │                           ╘═╤═╝                         ╘═╤═╝    │                    ╘═╤═╝                          ╘═╤═╝    │ │ │
                           │                             │                           ┌─┴─╖    │                      │                            ┌─┴─╖    │ │ │
                           │                             └───────────────────────────┤ ? ╟────┘                      └────────────────────────────┤ ? ╟────┘ │ │
                           │                                                         ╘═╤═╝                                                        ╘═╤═╝      │ │
                           │                                                           │                                                          ┌─┴─╖      │ │
                           │                                                           └──────────────────────────────────────────────────────────┤ ? ╟──────┘ │
                           │                                                                                ╘═╤═╝        │
                           │                                                    ┌────────────────────────────────────────────┐                    ┌─┴─╖        │
                   ┌───────┴────────────────────────────────────────────────────┤                                            │                  ┌─┤ ? ╟────────┘
                   │  ┌─────────────────────┐                   ┌───────────────┴────────────────┐                  ┌────────┴────────┐         │ ╘═╤═╝
                   └──┤   ╔════╗    ╔═══╗   │   ╔════╗  ╔═══╗   │   ╔═══╗               ╔════╗   │   ╔═══╗ ╔════╗   │   ╔═══╗ ╔═══╗   │   ╔═══╗ │   │
                      └─┬─╢ 16 ║    ║ 8 ╟─┬─┴─┬─╢ 16 ║  ║ 8 ╟─┬─┴─┬─╢ 4 ║               ║ 16 ╟─┬─┴─┬─╢ 8 ║ ║ 16 ╟─┬─┴─┬─╢ 8 ║ ║ 4 ╟─┬─┴─┬─╢ 2 ║ │
                       ┌┴┐╚════╝    ╚═══╝┌┴┐ ┌┴┐╚════╝  ╚═══╝┌┴┐ ┌┴┐╚═══╝               ╚════╝┌┴┐ ┌┴┐╚═══╝ ╚════╝┌┴┐ ┌┴┐╚═══╝ ╚═══╝┌┴┐ ┌┴┐╚═══╝ │
                       └┬┘               └┬┘ └┬┘             └┬┘ └┬┘                          └┬┘ └┬┘            └┬┘ └┬┘           └┬┘ └┬┘      │
 ╔═══╗                  │          ┌──────┘   └──────┐        └┐ ┌┘                            │   └───┐          │   └───────────┐ └┐ ┌┘       │
 ║837║         ┌────────┴────────┐ │                 │         │ │                 ┌───────────┴─────┐ │          └──────┐        └┐ │ │        │
 ║432║ ╔═════╗ │ ╔═════╗ ╔═════╗ │ │ ╔═════╗ ╔═════╗ │         │ │ ╔═════╗ ╔═════╗ │ ╔═════╗ ╔═════╗ │ │ ╔═════╗ ╔═════╗ │ ╔═════╗ │ │ │        │
 ║805║ ║56199║ │ ║57419║ ║57419║ │ │ ║56204║ ║56199║ │         │ │ ║56204║ ║57419║ │ ║57419║ ║57417║ │ │ ║56199║ ║56204║ │ ║25859║ │ │ │        │
 ║150║ ║16423║ │ ║47683║ ║47644║ │ │ ║21587║ ║46138║ │         │ │ ║21548║ ║47644║ │ ║37781║ ║79243║ │ │ ║16423║ ║21587║ │ ║43343║ │ │ │        │
 ║183║ ║50812║ │ ║02700║ ║34204║ │ │ ║36609║ ║75184║ │ ╔═════╗ │ │ ║68109║ ║34204║ │ ║62235║ ║09099║ │ │ ║50635║ ║51721║ │ ║27309║ │ │ │        │
 ║327║ ║18427║ │ ║91420║ ║69971║ │ │ ║90066║ ║41781║ │ ║57417║ │ │ ║99683║ ║69948║ │ ║19366║ ║48636║ │ │ ║09595║ ║67539║ │ ║22544║ │ │ │        │
 ║828║ ║74945║ │ ║13364║ ║58272║ │ │ ║25838║ ║38014║ │ ║79243║ │ │ ║79356║ ║80052║ │ ║52971║ ║39834║ │ │ ║66024║ ║42131║ │ ║21530║ │ │ │        │
 ║094║ ║88960║ │ ║32075║ ║67052║ │ │ ║24098║ ║54677║ │ ║08911║ │ │ ║07744║ ║24853║ │ ║92198║ ║60629║ │ │ ║48808║ ║97528║ │ ║04309║ │ │ │        │
 ║25 ║ ║8161 ║ │ ║6193 ║ ║3873 ║ │ │ ║1473 ║ ║6545 ║ │ ║32908║ │ │ ║9697 ║ ║5521 ║ │ ║5873 ║ ║3473 ║ │ │ ║3937 ║ ║3169 ║ │ ║76132║ │ │ │        │
 ╚═╤═╝ ╚══╤══╝ │ ╚══╤══╝ ╚══╤══╝ │ │ ╚══╤══╝ ╚══╤══╝ │ ║09671║ │ │ ╚══╤══╝ ╚══╤══╝ │ ╚══╤══╝ ╚══╤══╝ │ │ ╚══╤══╝ ╚══╤══╝ │ ║04007║ │ │ │        │
   │    ┌─┴─╖  │    │     ┌─┴─╖  │ │    │     ┌─┴─╖  │ ║82407║ │ │    │     ┌─┴─╖  │    │     ┌─┴─╖  │ │    │     ┌─┴─╖  │ ║73755║ │ │ │        │
   └────┤ ? ╟──┘    └─────┤ ? ╟──┘ │    └─────┤ ? ╟──┘ ║3185 ║ │ │    └─────┤ ? ╟──┘    └─────┤ ? ╟──┘ │    └─────┤ ? ╟──┘ ║94977║ │ │ │        │
        ╘═╤═╝             ╘═╤═╝    │          ╘═╤═╝    ╚══╤══╝ │ │          ╘═╤═╝             ╘═╤═╝    │          ╘═╤═╝    ╚══╤══╝ │ │ │        │
          │               ┌─┴─╖    │            │       ┌─┴─╖  │ │            │               ┌─┴─╖    │            │       ┌─┴─╖  │ │ │        │
          └───────────────┤ ? ╟────┘            └───────┤ ? ╟──┘ │            └───────────────┤ ? ╟────┘            └───────┤ ? ╟──┘ │ │        │
                          ╘═╤═╝                         ╘═╤═╝    │                            ╘═╤═╝                         ╘═╤═╝    │ │        │
                            │                           ┌─┴─╖    │                              │                           ┌─┴─╖    │ │        │
 ╔═════════════════════╗    └───────────────────────────┤ ? ╟────┘                              └───────────────────────────┤ ? ╟────┘ │        │
 ║  Decode the base-4  ║                 ╓┬───╖         ╘═╤═╝                                                               ╘═╤═╝      │        │
 ║  representation    ↓║                 ╟┘⊁p ║           │                                                                 ┌─┴─╖      │        │
 ╚═════════════════════╝    ╔═══╗        ╙─┬──╜           └─────────────────────────────────────────────────────────────────┤ ? ╟──────┘        │
    ╔═══╗ ┌───╖             ║ 3 ╟───┬──────┴───────────┐                              ╔════╗ ┌────╖                         ╘═╤═╝               │
    ║ 2 ╟─┤ = ╟─────────┐   ╚═══╝  ┌┴┐   ╔═══╗ ┌────╖  │                              ║ 21 ╟─┤ >> ╟───────────┬─────────────┐ └─────────────────┘
    ╚═══╝ ╘═╤═╝ ╔════╗  │          └┬┘   ║ 2 ╟─┤ >> ╟──┴──────────┐ ╔═══════════════╗ ╚════╝ ╘══╤═╝         ╓─┴─╖     ╔═══╗ │
            │   ║ 32 ║  │           │    ╚═══╝ ╘═╤══╝             │ ║  Render a     ║         ┌─┴─╖         ║ ⊅ ║     ║ 6 ║ │
            │   ╚═╤══╝  ├───────────┴─┐        ┌─┴─╖              │ ║  row of text →║ ┌───────┤ ⊅ ╟─────┐   ╙───╜     ╚═╤═╝ │
 ╔══════╗ ┌─┴─╖ ┌─┴─╖ ┌─┴─╖      ┌────┴────────┤ · ╟────────────┐ │ ╚═══════════════╝ │       ╘═══╝   ┌─┴─╖             │   │
 ║ 9585 ╟─┤ ? ╟─┤ ? ╟─┤ = ║      │             ╘═╤═╝            │ │       ┌───╖       │         ┌─────┤ · ╟─────────┐ ┌─┴─╖ │
 ╚══════╝ ╘═╤═╝ ╘═╤═╝ ╘═╤═╝      │   ╔════╗    ┌─┴──╖           │ │     ┌─┤ ‼ ╟─┐     │ ┌───╖ ┌─┴─╖   ╘═╤═╝   ┌───╖ ├─┤ − ║ │
       ╔════╧═╗  ┌┴┐  ╔═╧═╗      │   ║ 21 ║ ┌──┤ ⊁p ╟────┐      │ │     │ ╘═╤═╝ │     └─┤ ʭ ╟─┤ ȶ ║     └─────┤ + ╟─┘ ╘═╤═╝ │
       ║ 9586 ║  └┬┘  ║ 1 ║      │   ╚═╤══╝ │  ╘════╝    │      │ │   ┌─┴─╖ │   │       ╘═╤═╝ ╘═╤═╝           ╘═╤═╝   ┌─┴─╖ │
       ╚══════╝   │   ╚═══╝ ┌┐ ┌─┴─╖ ┌─┴──╖ │   ┌─┐      │      │ │ ┌─┤ · ╟─┘ ┌─┘       ┌─┴─╖ ┌┬┘ ┌───╖ ╔═══╗ ┌─┴─╖   │ ɕ ║ │
                  └─────┬───┤├─┤ · ╟─┤ << ║ │   ├─┘   ┌──┴──┐   │ │ │ ╘═╤═╝   │     ┌───┤ · ╟─┘├──┤ ⁞ ╟─╢ 0 ╟─┤ ? ╟─┐ ╘═╤═╝ │
 ┌──────────┐   ╔═══╗ ┌─┴─╖ └┘ ╘═╤═╝ ╘═╤══╝ │ ╔═╧═╕ ┌─┴─╖ ┌─┴─╖ │ │ │   │     │     │   ╘═╤═╝  └┐ ╘═══╝ ╚═══╝ ╘═╤═╝ │ ┌─┴─╖ │
 │ ╓┬──╖    │   ║ 0 ╟─┤ ? ╟──────┘     └────┴─╢   ├─┤ · ╟─┤ ? ╟─┘ │ │ ╔═╧═╕ ╔═╧═╕ ┌─┴─╖ ┌─┴─╖ ┌─┴─╖            ─┘   └─┤ · ╟─┴─┐
 │ ╟┘⊁ ║    │   ╚═╤═╝ ╘═╤═╝                   ╚═╤═╛ ╘═╤═╝ ╘═╤═╝   │ └─╢   ├─╢   ├─┤ · ╟─┤ ʑ ╟─┤ ʭ ║ ┌─┬─────────────┐ ╘═╤═╝   │
 │ ╙─┬─╜    │     │   ┌─┴─╖                     └─────┘     │     │   ╚═╤═╛ ╚═╤═╛ ╘═╤═╝ ╘═╤═╝ ╘═╤═╝ │ │ ┌───╖ ┌───╖ └───┘     │
 │ ┌─┴──╖ ╔═╧═╕   └───┤ ? ╟───────────────────────┐ ╔═══╗ ┌─┴─╖   │     │   ╔═╧═╗ ┌─┴─╖ ┌─┴─╖   └───┘ └─┤ ⊁ ╟─┤ ➫ ╟───────┐   │
 └─┤ ⊁p ╟─╢   ├─┬─┐   ╘═╤═╝                       │ ║ 0 ╟─┤ ? ╟─┐ │     └───╢ 0 ║ │ ȶ ╟─┤ ? ╟─┐         ╘═══╝ ╘═══╝      ┌┴┐  │
   ╘════╝ ╚═╤═╛ └─┘    ─┘                         │ ╚═══╝ ╘═╤═╝ ├─┘         ╚═══╝ ╘═╤═╝ ╘═╤═╝ │              ╔═════════╗ └┬┘  │
    ╓───╖   │   ╔════════════╗                    │         └─  │                 ╔═╧═╗   └─  │              ║ 2097151 ╟──┴─┐ │
    ║ ✰ ║       ║  Generate  ║                    └─────────────┘                 ║ 6 ║       │              ╚═════════╝    ├─┘
    ╙─┬─╜       ║  padding  ↓║                                                    ╚═══╝       └─────────────────────────────┘
  ┌───┴───┐     ╚════════════╝   ╔═══════════╗   ┌───────────────────────────────────────────────────────┐
  │     ┌─┴─╖ ┌───╖       ╔═══╗  ║  Prepend  ║   │ ┌───╖                                                 │
  │     │ + ╟─┤ ♫ ╟───────╢ 0 ║  ║  a row    ║ ┌─┴─┤ < ╟─────────────────┐                               │
  │     ╘═╤═╝ ╘═╤═╝   ┌─┐ ╚═╤═╝  ║  of text →║ │   ╘═╤═╝               ┌─┴─╖                             │
  │     ╔═╧═╗   │   ┌─┴─╖ ╔═╧═╕  ╚═══════════╝ │   ┌─┴─╖ ┌─────────────┤ · ╟─────────────┐               │
  │     ║ 6 ║   └───┤ ɱ ╟─╢   ├──────────────┐ │ ┌─┤ ? ╟─┤ ┌───╖ ┌───╖ ╘═╤═╝             │   ╔═══╗ ╓───╖ │
  │     ╚═══╝       ╘═══╝ ╚═╤═╛              │ │ │ ╘═╤═╝ └─┤ + ╟─┤ ~ ╟─┐ │ ┌───╖         │   ║ 0 ║ ║ ≭ ╟─┘
  │   ┌───╖ ┌───╖           │                │ └─┤   │     ╘═╤═╝ ╘═══╝ │ ├─┤ ⊅ ╟───┐     │   ╚═╤═╝ ╙─┬─╜
  │ ┌─┤ + ╟─┤ ~ ╟───────────┴───┐            │ ┌─┘   │     ┌─┴─╖       ├─┘ ╘═╤═╝ ┌─┴─╖ ┌─┴─╖ ┌─┴─╖   │
  └─┤ ╘═╤═╝ ╘═══╝             ┌─┴──╖         │ │     └─────┤ · ╟───────┴─┐   └───┤ · ╟─┤ · ╟─┤   ╟───┴───────────┐
    │ ┌─┴──╖    ┌───╖ ╔════╗  │ << ╟──┐      │ │           ╘═╤═╝         │       ╘═╤═╝ ╘═╤═╝ └─┬─╜               │
    │ │ << ╟────┤ + ╟─╢ 11 ║  ╘═╤══╝  │      │ │           ┌─┴─╖         │   ╔═══╗ │ ┌───┘     │                 │
    │ ╘═╤══╝    ╘═╤═╝ ╚════╝  ╔═╧═╗ ┌─┴─╖    │ │           │ ✰ ║         │   ║ 0 ║ │ │   ┌─────┘                 │
    │ ╔═╧═╗       │  ╔════╗   ║ 1 ║ │ ♯ ║    │ │           ╘═╤═╝         │   ╚═╤═╝ │ │   │                       │
    │ ║ 1 ║       │  ║ 12 ╟─┐ ╚═══╝ ╘═╤═╝    │ │           ┌─┴─╖ ┌───╖ ┌─┴─╖ ┌─┴─╖ │ │ ┌─┴─╖                     │
    │ ╚═══╝ ┌───╖ │  ╚════╝ │ ┌───╖   │      │ │           │ ʭ ╟─┤ ʭ ╟─┤ ȶ ║ │ ⁞ ║ │ └─┤ ≭ ╟─────────────┐       │
  ┌─┴──╖  ┌─┤ > ╟─┴─────┐ ┌─┴─┤ > ╟───┴───┐  │ │           ╘═╤═╝ ╘═╤═╝ ╘═╤═╝ ╘═╤═╝ │   ╘═╤═╝ ╔═══╗ ┌───╖ │       │
  │ << ╟──┤ ╘═╤═╝       │ │   ╘═╤═╝       │  │ │             │   ┌─┴─╖   ├─────┘   │     │   ║ 5 ╟─┤ + ╟─┴─────┐ │
  ╘═╤══╝  │ ┌─┴─╖       │ │   ┌─┴─╖       │  │ │     ┌─────┐ └───┤ · ╟───┴─┐       │     │   ╚═══╝ ╘═╤═╝       │ │
  ╔═╧═╗   └─┤ ? ╟───┐   │ └───┤ ? ╟───┐   │  │ │   ┌─┴─╖ ┌─┴─╖   ╘═╤═╝   ┌─┴─╖ ┌───┘     │         ┌─┴─╖       │ │
  ║ 1 ║     ╘═╤═╝ ┌─┴─╖ │     ╘═╤═╝ ┌─┴─╖ │  │ │ ┌─┤ · ╟─┤ ‼ ║   ┌─┴─╖ ┌─┤ ʭ ║ │ ┌───────┘     ┌───┤ + ║       │ │
  ╚═══╝       └───┤ · ╟─┘       └───┤ · ╟─┘  │ │ │ ╘═╤═╝ ╘═╤═╝ ┌─┤ ʑ ╟─┘ ╘═╤═╝ │ │     ┌───╖ ┌─┴─╖ ╘═╤═╝       │ │
                  ╘═╤═╝ ┌───╖       ╘═╤═╝    │ │ │ ╔═╧═╕ ╔═╧═╕ │ ╘═╤═╝     └───┘ │ ┌───┤ ʝ ╟─┤ ȶ ║ ┌─┴─╖       │ │
                  ┌─┴───┤ > ╟───────┐ │      │ │ └─╢   ├─╢   ├─┤ ┌─┴─╖     ┌─────┘ │   ╘═╤═╝ ╘═╤═╝ │ ~ ║       │ │
                  │     ╘═╤═╝       ├─┘      │ │   ╚═╤═╛ ╚═╤═╛ └─┤ ʑ ╟─┐ ┌─┴─╖   ╔═╧═╗ ╔═╧═╕ ┌─┴─╖ ╘═╤═╝       │ │
                  │     ┌─┴─╖       │        │ │   ╔═╧═╗   │     ╘═╤═╝ └─┤ ʭ ║   ║ 0 ╟─╢   ├─┤ · ╟───┘         │ │
                  └─────┤ ? ╟───┐   │        │ │   ║ 0 ╟───┘     ┌─┴─╖   ╘═╤═╝   ╚═╤═╝ ╚═╤═╛ ╘═╤═╝             │ │
                        ╘═╤═╝ ┌─┴─╖ │ ╔════╗ │ │   ╚═╤═╝ ┌───────┤ ? ╟───┐ │     ┌─┴─╖ ┌─┴─╖ ┌─┴─╖ ╔═══╗ ┌───╖ │ │
                          └───┤ · ╟─┘ ║ 32 ║ │ │     │ ┌─┴─╖     ╘═╤═╝   │ └─────┤ · ╟─┤ ɱ ║ │ ⁞ ║ ║ 6 ╟─┤ + ╟─┘ │
                              ╘═╤═╝   ╚═╤══╝ │ │   ┌─┴─┤ · ╟─────┐ │     │       ╘═╤═╝ ╘═╤═╝ ╘═╤═╝ ╚═══╝ ╘═╤═╝   │
                  ╔═══╗ ┌───╖ ┌─┴─╖   ┌─┴─╖  │ │   │   ╘═╤═╝   ┌─┴───┐   │ ╔═══╗ ┌─┴─╖   │  ╔══╧═╗ ╔═══╗ ┌─┴─╖   │
                  ║ 0 ╟─┤ ʝ ╟─┤ ȶ ║   │ ⁞ ║  │ │ ┌─┴─╖ ┌─┴─╖ ╔═╧═╕ ┌─┴─╖ │ ║ 6 ║ │ ♫ ╟───┘  ║ 32 ║ ║ 0 ╟─┤ ? ╟─┐ │
                  ╚═══╝ ╘═╤═╝ ╘═╤═╝   ╘═╤═╝  │ │ │ ♫ ╟─┤ ɱ ╟─╢   ├─┤ ʝ ║ │ ╚═╤═╝ ╘═╤═╝      ╚════╝ ╚═══╝ ╘═╤═╝ ├─┘
                          │     └───────┘    │ │ ╘═╤═╝ ╘═══╝ ╚═╤═╛ ╘═╤═╝ │   └─────┘                       └─  │
                          └──────────────────┘ └───┘  ┌────────┘     └─┐ └─────────────────────────────────────┘
                                                      │ ╔════╗ ┌───╖ ┌─┴─╖
                                                      │ ║ 32 ╟─┤ ⁞ ╟─┤ ȶ ╟─┐
                                                      │ ╚════╝ ╘═══╝ ╘═══╝ │
                                                      └────────────────────┘

```

## How it works

* First, there is a lookup-table-like function () that maps ASCII codes to a number which represents the letter’s shape in base-4. For example, `I` maps to a number which is 1012301212012120121201212013201 in base-4. This function looks at just enough least-significant bits to identify just the letters A–Z and the space. Any other Unicode character will therefore be mapped to one of those. For example, the digits 0–9 become letters P–Y.
* Then there’s a function () that turns this base-4 representation into a sequence of strings, one per line, turning 1 into space, 2 into , 3 into , and appending to the sequence and starting a new string when encountering a 0. Thus, `I` becomes `·\n·╱╲\n·╱·╱\n·╱·╱\n·╱·╱\n·╱·╱\n·╲╱\n·`. This string representation includes both a single space after each character and one on top of each character, so as to create the one-space margin.
* The next function, , takes a string (e.g. `DOG`) and simply concatenates these string representations at the appropriate offsets (`D` at the start, `O` 6 lines down, and `G` 12 lines down). It also calculates the total width of this row of text.
* The main logic (implemented in ) operates as a recursive function that iterates over the lines of text in the input:
    + The function first calls  to render the current line and calculate its width.
    + Then the recursive call happens, and we pass the maximum width to the next level of recursion. This way, each invocation knows how wide the widest line of text above it is.
    + At the base of the recursion, we know the widest width we need to accommodate and we can generate the bottom-left triangle of spaces (shown as  in the example below).
    + After the recursive call, we prepend the current line of text. This is done in three steps:
        - 6 new lines are added at the top, containing the necessary spaces at the start (shown as  (iteration 2) and  (iteration 1) in the example below). With each returning iteration, the amount of spaces to be added is incremented by 6.
        - The rendered letter shapes are appended (starting at the top).
        - Extra spaces are generated (by ) to bring the width all the way to the widest width we need (shown as  in the example below).
* Finally, the main program just splits the input at `\n`s, calls  with that, and then joins the resulting strings with newlines.

Here’s the example for the input `W\nA`:

```
■■■■■■■■■■■·
■■■■■■■■■■╱╲·
■■■■■■■■■╱·╱··
■■■■■■■■╱·╱····
■■■■■■■╱·╱·╱╲···
■■■■■■·╲╱·╱·╱·╱╲·
●●●●●··╱╲╱·╱·╱·╱·
●●●●╱╲·╲╱╲╱·╱·╱·
●●●╱··╲··╱╲╱·╱·
●●╱·╱╲·╲·╲╱╲╱·
●╱··╲╱·╱·▲···
╱·╱╲··╱·▲▲▲·
╲╱·╱·╱·▲▲▲▲
•·╱·╱·▲▲▲▲
••╲╱·▲▲▲▲
•••·▲▲▲▲
••••▲▲▲
•••••▲

```

Example output:
> 13 votes

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


title: Is it a super-prime?

text:
# Question
Title: Is it a super-prime?
# Background

A super-prime is a prime number whose index in the list of all primes is also prime. The sequence looks like this:

> 3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, ...

This is sequence A006450 in the OEIS.

# Challenge

Given a positive integer, determine whether it is a super-prime.

# Test Cases

```
2: false
3: true
4: false
5: true
7: false
11: true
13: false
17: true
709: true
851: false
991: true

```

# Scoring

This is , so the shortest answer in each language wins.

# Answer
# Jelly, 5 bytes

```
ÆRÆNċ

```

Try it online!

### How it works

```
ÆRÆNċ  Main link. Argument: n

ÆR     Prime range; yield the array of all primes up to n.
  ÆN   N-th prime; for each p in the result, yield the p-th prime.
    ċ  Count the occurrences of n.

```
> 21 votes

# Answer
## Mathematica, ~~26~~ 23 bytes

*Thanks to user202729 for saving 3 bytes.*

```
PrimeQ/@(#&&PrimePi@#)&

```

This makes use of the fact that Mathematica leaves most nonsensical expressions unevaluated (in this case, the logical `And` of two numbers) and `Map` can be applied to any expression, not just lists. So we compute the `And` of the input and its prime index, which just remains like that, and then we `Map` the primality test over this expression which turns the two operands of the `And` into booleans, such that the `And` can then be evaluated.
> 15 votes

# Answer
# Japt, ~~13~~ 11 bytes

```
õ fj bU Ä j

```

Test it online!

### Explanation

This is actually very straight-forward, unlike my original submission:

```
 õ fj bU Ä  j
Uõ fj bU +1 j    Ungolfed
                 Implicit: U = input integer
Uõ               Generate the range [1..U].
   fj            Take only the items that are prime.
      bU         Take the (0-indexed) index of U in this list (-1 if it doesn't exist).
         +1 j    Add 1 and check for primality.
                 This is true iff U is at a prime index in the infinite list of primes.
                 Implicit: output result of last expression

```
> 10 votes

# Answer
# Jelly, 6 bytes

```
ÆRi³ÆP

```

Try it online!

Uses the same technique as my Japt answer: Generate the primes up to **n**, get the index of **n** in that list, and check that for primality. If **n** itself is not prime, the index is **0**, which is also not prime, so **0** is returned anyway.
> 10 votes

# Answer
# Regex (Perl / PCRE), ~~55~~ ~~54~~ 53 bytes

```
^(?=((?=((\2x*?|^)((?!(xx+)\5+$)))xx)x)*(x*))\6(?4)xx

```

Try it online! \- Perl
Try it online! \- PCRE

Takes its input in unary, as a string of `x` characters whose length represents the number. Based on Prime counting function.

```
^       # tail = N = input value
(?=
    # Calculate π(N) = the number of primes <= N, by counting
    # from the largest to the smallest prime.
    (       # J = 0
        (?=
            # \2 starts at zero, and on each subsequent iteration, contains the
            # difference N-P-(J-1) where P is the previously found prime, and J
            # is the running total of our prime count.
            (
                (
                    \2           # Start from the previous value of \2. This
                                 # will make tail = P-1, where P is the
                                 # previously found prime.
                    x*?          # Advance as little as necessary to make the
                                 # following match, and add this to \2, while
                                 # subtracting it from tail.
                |        # or
                    ^            # Don't advance at all on the first iteration
                                 # (when \2 is is still unset), so as to assert
                                 # that N is not composite.
                )
                ((?!(xx+)\5+$))  # Define and use subroutine (?4): Assert tail
                                 # is prime. Note that this needs to be inside
                                 # group \2 for it to work in PCRE1 and older
                                 # versions of PCRE2, which atomicize groups
                                 # that have nested backreferences.
            )
            xx                   # Assert tail is prime by eliminating the
                                 # false positives 0, 1
        )
        x   # J += 1; tail -= 1
    )*      # Iterate zero or more times, until there are no smaller primes
            # remaining.
    # At this point, head = π(N), and tail = N - π(N)
    (x*)    # \6 = tail = N - head = tool to make tail = head
)
\6          # tail = π(N)
(?4)xx      # Assert tail is prime

```

Alternative **~~55~~ ~~54~~ 53 bytes**:

```
^(?=((?=((\2x*?|^)((?!(xx+)\5+$|x?$))))x)*(x*))\6(?4)

```

Try it online! \- Perl
Try it online! \- PCRE

This eliminates the false negatives \\$0\\$ and \\$1\\$ in the definition of the primality subroutine instead of patching its ~~second and third~~ individual uses.

# Regex (.NET), ~~70~~ ~~60~~ 58 bytes

```
^(?=(\3*?(?!(xx+)\2+$)(x))*x)(?<-3>x){2,}(?<!\3|^\4+(x+x))

```

Try it online!

This uses the .NET feature of balanced groups to do the prime counting. Since .NET regex has no subroutines, this has ~~three~~ two copies of the primality test.

```
^                      # tail = N = input value
# Calculate π(N) = the number of primes <= N, by counting
# from the largest to the smallest prime.
(?=                    # Atomic lookahead - lock in this match once it completes
    (
        \3*?           # Advance as little as necessary to make the following
                       # match, but don't advance at all on the first iteration
                       # (when \3 is is still unset), so as to assert that N is
                       # not composite.
        (?!(xx+)\2+$)  # Assert tail is not composite
        (x)            # Eliminate the false primality positive of 0, and advance
                       # forward so that the next prime can be found (if we didn't
                       # do this, the regex engine would exit the loop due to a
                       # zero-width match); \3 = 1, to signal the first iteration
                       # has been done, and push a capture onto the Group 3 stack.
    )*                 # Loop as many times as can be done until its stops
                       # matching.
    x                  # Eliminate the false primality positive of 1
)
(?<-3>x){2,}           # Pop all Group 3 captures off the stack, asserting that
                       # the count is ≥ 2, and doing head += 1 for each one. Since
                       # this isn't done atomically, we need to subsequently
                       # verify that all captures were popped, due to backtracking
                       # if the following assertion fails.
(?<!\3|^\4+(x+x))      # Assert that the Group 3 capture stack is empty, and that
                       # head is not composite (and since it's already been
                       # forced to be ≥ 2, this asserts it to be prime).

```

# Regex (Perl / Java / PCRE / .NET), 60 bytes

```
^(?=((?=((\2x*?|^)(?!(xx+)\4+$))xx)x)*(x*))\5(?!(xx+)\6+$)xx

```

Try it online! \- Perl
**Try it online! \- Java**
Try it online! \- PCRE
Try it online! \- .NET

This is a straight port of the Perl/PCRE version, to regex engines that lack subroutine calls but support nested backreferences. The subroutine call has been replaced with a copy of the routine.

# Regex (Perl / PCRE / Python`regex`), 61 bytes

```
^(?=((?=((\6x*?|^)((?!(xx+)\5+$)))xx)(?=(\2))x)*(x*))\7(?4)xx

```

Try it online! \- Perl
Try it online! \- PCRE
**Try it online! \- Python `import regex`**

This is a port of the Perl/PCRE version. `\2` is copied into `\6` using the lookahead `(?=(\2))`, since Python (even with `import regex`) lacks nested backreferences.

# Regex (PCRE / Ruby), 62 bytes

```
^(?=((?=((\6x*?|^)((?!(xx+)\5+$)))xx)(?=(\2))x)*(x*))\7\g<4>xx

```

Try it online! \- PCRE
**Try it online! \- Ruby**

This is a straight port of the Python`regex` version, to Ruby's subroutine call syntax.

# Regex (Perl / Java / PCRE / Python`regex` / Ruby / .NET), 68 bytes

```
^(?=((?=((\5x*?|^)(?!(xx+)\4+$))xx)(?=(\2))x)*(x*))\6(?!(xx+)\7+$)xx

```

Try it online! \- Perl
Try it online! \- Java
Try it online! \- PCRE
Try it online! \- Python `import regex`
Try it online! \- Ruby
Try it online! \- .NET

To be portable to all 6 regex engines, this uses neither nested backreferences nor subroutine calls.
> 5 votes

# Answer
# Python 3, ~~104~~ ~~97~~ 93 bytes

```
p=lambda m:(m>1)*all(m%x for x in range(2,m))
f=lambda n:p(n)*p(len([*filter(p,range(n+1))]))

```

Returns `0`/`1`, at most 4 bytes longer if it has to be `True`/`False`.

Try it online!
> 4 votes

# Answer
# Python 2, 79 bytes

```
n=input()
s={2};p=i=1
while i<n:
 p*=i;i+=1
 if p*p%i:s|={i}
print{n,len(s)}<=s

```

Try it online!
> 4 votes

# Answer
# Jelly, 7 bytes

```
ÆCÆPaÆP

```

Try it online!

`ÆC` counts the number of primes less than or equal to the input (so, if the input is the *n*th prime, it returns *n*). Then `ÆP` tests this index for primality. Finally, `a` does a logical AND between this result and `ÆP` (primality test) of the original input.
> 3 votes

# Answer
# Haskell, 62 bytes

```
p x=2==sum[1|0<-mod x<$>[1..x]]
f x=p$sum[1|y<-[1..x],p y,p x]

```

Try it online! Usage: `f 991` yields `True`.
> 3 votes

# Answer
# Husk, 2 bytes

```
ṗṗ

```

Try it online!

One of the cases when the behaviours of functions returning non booleans is really helpful.

user's solution.

# Husk, 4 bytes

```
ṗ£İp

```

Try it online! or Verify all test cases
> 3 votes

# Answer
# Pyth, 12 bytes

```
&P_QP_smP_dS

```

Try it online!

### Explanation

```
&P_QP_smP_dS
                Implicit input
       mP_dS    Primality of all numbers from 1 to N
      s         Sum of terms (equal to number of primes ≤ N)
    P_          Are both that number
&P_Q            and N prime?

```
> 2 votes

# Answer
# Mathematica, ~~35~~ 29 bytes

```
P=Prime;!P@P@Range@#~FreeQ~#&

```

*-6 bytes from @MartinEnder*
> 2 votes

# Answer
# 05AB1E, 6 bytes

```
ÝØ<Øså

```

Try it online!

### Explanation

```
ÝØ<Øså
Ý      # Push range from 0 to input
 Ø     # Push nth prime number (vectorized over the array)
  <    # Decrement each element by one (vectorized)
   Ø   # Push nth prime number again
    s  # swap top items of stack (gets input)
     å # Is the input in the list?

```
> 2 votes

# Answer
## Pyke, 8 bytes

```
sI~p>@hs

```

Try it here!

```
s        -  is_prime(input)
 I~p>@hs - if ^:
  ~p>    -    first_n_primes(input)
     @   -    ^.index(input)
      h  -   ^+1
       s -  is_prime(^)

```
> 2 votes

# Answer
# Raku, ~~46~~ 35 bytes

~~`{$/=&is-prime;all($_∈*,$/)([grep $/,1..$_])}`~~

```
grep {.is-prime&&is-prime ++$},^∞

```

Try it online!

Six years of golfing experience let me cut down on this solution considerably.
> 2 votes

# Answer
# Python 2, 89 bytes

```
def a(n):
 r=[2];x=2
 while x<n:x+=1;r+=[x]*all(x%i for i in r)
 return{n,len(r)}<=set(r)

```

Try it online!

Constructs `r`, the list of primes \<= n; if n is prime, then `n` is the `len(r)`'th prime. So n is a super prime iff n in r and len(r) in r.
> 2 votes

# Answer
# Factor \+ `math.primes`, ~~51~~ ~~49~~ ~~36~~ 32 bytes

Saved 13 bytes thanks to @Bubbler! Saved 4 bytes thanks to @chunes!

```
[ dup nprimes index ?1+ prime? ]

```

Try it online!

```
[ dup nprimes index ?1+ prime? ]
  dup nprimes                    ! First n primes (generates extra primes)
              index              ! Find the index of the input in that
                                 ! when the index is not found, an f is outputted
                                 ! If the index exists,
                    ?1+          ! If it's a number, increment
                                 ! If it's f, output 0 (which is not prime)
                        prime?   ! Is that prime?

```
> 2 votes

# Answer
# Vyxal `g`, 4 bytes

```
¡†"æ

```

Try it Online! \- test cases only

This is the same as the 5 byte answer below except the minimum is taken by the `g` flag rather than a `g` element.

# Vyxal, 5 bytes

```
¡†"æg

```

Try it Online!
Try it Online! \- test cases only

This makes use of Prime counting function, based on Dennis's 05AB1E solution to that challenge. This is actually much faster than the other two 5 byte solutions presented below it.

```
¡  # Factorial
†  # Number of distinct prime factors – when applied to the factorial, this
   # gives the index of the greatest prime ≤ the input number (1-indexed).
"  # Wrap the top two items (the input number, and the above result) in a list.
æ  # Is the number prime? (Vectorized)
g  # Minimum - effectively applies a boolean AND to the list

```

---

Alternative 5 bytes:

```
Þpḟ›æ

```

Try it Online!
Try it Online! \- test cases only

```
Þp  # An infinite list of primes
ḟ   # Index of input number in that list (0-indexed; -1 if not found)
›   # Add 1
æ   # Is the number prime?

```

---

Another alternative 5 bytes:

```
Þp‹ǎc

```

Try it Online!
Try it Online! \- test cases only

Port of Datboi's 05AB1E solution. This is much slower than the primary 5 byte solution above, but much faster than its 05AB1E counterpart.

```
Þp # An infinite list of primes
‹  # Subtract 1 from every item on the list
ǎ  # Nth prime - vectorized to the entire list
c  # Contains - Is the input number a member of that list?

```
> 2 votes

# Answer
# Thunno `D`, \\$ 8 \log\_{256}(96) \approx \\$ 6.58 bytes

```
FAFLZPNP

```

Attempt This Online!

Port of Deadcode's Vyxal answer.

It's all uppercase letters!

#### Explanation

```
FAFLZPNP  # Implicit input
F         # Factorial
 AF       # Unique prime factors
   L      # Length
    ZP    # Pair
      N   # Is prime
       P  # Product
          # Implicit output

```
> 2 votes

# Answer
# QBIC, 33 bytes

```
~µ:||\_x0]{p=p-µq|~q=a|_xµp]q=q+1

```

## Explanation

```
~   |   IF   ....  THEN (do nothing)
  :         the number 'a' (read from cmd line)
 µ |        is Prime
\_x0        ELSE (non-primes) quit, printing 0
]           END IF
{           DO
            In this next bit, q is raised by 1 every loop, and tested for primality.
            p keeps track of how may primes we've seen (but does so negatively)
    µq|     test q for primality (-1 if so, 0 if not)
p=p-        and subtract that result from p (at the start of QBIC: q = 1, p = 0)
~q=a|       IF q == a
_xµp        QUIT, and print the prime-test over p (note that -3 is as prime as 3 is)
]           END IF
q=q+1       Reaise q and run again.

```
> 1 votes

# Answer
## Haskell, 121 bytes

```
f=filter
p x=2==(length$f(\a->mod(x)a==0)[1..x])
s=map(\(_,x)->x)$f(\(x,_)->p x)$zip[1..]$f(p)[2..]
r x=x`elem`(take x s)

```
> 1 votes

# Answer
# Positron, 148 bytes

```
x=#(input@@)a=function{p=1;k=$1==2;f=2;while(f<$1)do{p=p*$1%f;k=1;f=f+1};return p*k}r=1;i=2;while(i<x)do{if(a@i)then{r=r+1}i=i+1}print@((a@x*a@r)>0)

```

Try it online!
> 1 votes

# Answer
# Pari/GP, 31 bytes

```
n->(p=isprime)(n)*p(primepi(n))

```

Try it online!
> 1 votes

# Answer
# Matlab, ~~36~~ 34 bytes

*Saved 2 bytes thanks to Tom Carpenter.*

A very naive implementation using built-in functions:

```
isprime(x)&isprime(nzz(primes(x)))

```
> 1 votes

# Answer
# Julia 0.6, 61 bytes

return 1 if x is a super-prime, 0 otherwise.

without using an isprime-kind function.

```
x->a=[0,1];for i=3:x push!(a,0∉i%(2:i-1))end;a[sum(a)]&a[x]

```
> 1 votes

# Answer
# Japt, 11 bytes

```
ÒÈj}jU bU)j

```

Try it
> 1 votes

# Answer
# Pyth, 9 bytes

```
P_hx.fP_Z

```

Test suite

Uses a fairly different approach to the existing Pyth solution. Returns `True` for super-primes, `False` for non-super-primes, and `[]` (falsy) for composite numbers.
> 1 votes

# Answer
# Ruby, 72 bytes

Tired of all the extremely obscure golfing languages in this thread? Here's the practical language solution you're looking for! Let me know if you see a way to shave off a few bytes.

```
require'prime';n=gets.to_i;p n.prime?&&(Prime.take(n).index(n)+1).prime?

```

Try it online!
> 1 votes

# Answer
# 05AB1E, 6 bytes

```
.Ø>‚pß

```

Try it online! \- 05AB1E
Try it online! \- 05AB1E - test cases only
Try it online! \- 05AB1E (legacy) - test cases only

Equal in length to Datboi's solution, but much faster on numbers that are not super-prime.

```
.Ø  # Get 0-indexed number of the greatest prime ≤ input number
>   # Add 1
‚   # Wrap the top two items (the input number, and the above result) in a list
p   # Is the number prime? (Vectorized)
ß   # Minimum - effectively applies a boolean AND to the list

```

---

Alternative 6 bytes:

```
!fg‚pß

```

Try it online!
Try it online! \- test cases only

This makes use of Dennis's Prime counting function solution, which is equal in length to (but slower than) the ones using built-in prime-counting functions.
> 1 votes

# Answer
# C89 (clang), 92 bytes

```
#define s for(i=e;--i&&e%i;)p+=i <3
p,r,i;m(e){s;for(p=r=i==e%2;--e;)s;e=p+1;s;return r<i<r;}

```

*(added whitespace for readability)*

### Some alternatives:

* `i==e%2` \\$\equiv\\$ `i==1&e`
* `r<i<r` \\$\equiv\\$ `1<i<r` \\$\equiv\\$ `i<2&r` \\$\equiv\\$ `i/2<r` \\$\equiv\\$ `i<r+r` \\$\equiv\\$ `i<2*r`

Try it online!
> 1 votes

# Answer
# , 13 bytes

```
e.p:@<:@p:@i.

```

Same idea as 05AB1E, Vyxal, and kind of Factor. Reminder `(f g) y → y f g y`.

Attempt This Online!

```
e.p:@<:@p:@i.
           i.  NB. range 0..y
        p:@    NB. then get nth prime, vectorized
     <:@       NB. then decrement each
  p:@          NB. then get primes again
e.             NB. is y a member of

```
> 1 votes

# Answer
# Pyt, 5 bytes

```
Đřᵽᵽ∈

```

Try it online!

```
Đ            implicit input; Đuplicate
 ř           řangify [1,2,...,n]
  ᵽ          get ᵽrimes with given indices
   ᵽ         get ᵽrimes with given indices
    ∈        is input in the resulting array?; implicit print

```
> 1 votes

# Answer
# Regex (.NET), 57 bytes

```
^(?=((?!(xx+)\2+$)(x+?))+x$)(?<-3>x){2,}(?<!\3|^\4+(x+x))

```

Try it online!

This uses the .NET feature of balanced groups to do the prime counting, saving 3 bytes relative to the shortest version that doesn't use this feature and is still .NET-compatible. Since .NET regex has no subroutines, this has two copies of the primality test.

It is based on my **58 byte** .NET regex answer. Shown side-by-side with it:

```
^(?=(\3*?(?!(xx+)\2+$)(x))*x)(?<-3>x){2,}(?<!\3|^\4+(x+x))
^(?=((?!(xx+)\2+$)(x+?))+x$)(?<-3>x){2,}(?<!\3|^\4+(x+x))

```

This -1 byte golf relies on a mathematical conjecture, which is extremely likely to be true, but as far I can tell has not been proven: that \\$g(n)≤n\\$ always, where \\$g(n)\\$ is the \\$1\\$-indexed \\$n\\$th prime gap, i.e. OEIS A001223. For this reason I'm posting it as a separate answer, as the existing answer is already quite long and diluted with answers for other regex engines.

For this regex to fail, there would need to be a counterexample \\$g(p)\>p\\$ where \\$p\\$ is prime. This would give the regex false positives for the \\$\\{p+1\\}\\$th prime and every subsequent prime.

It is known to hold true at least up to \\$n=423,731,791,997,205,041\\$, with \\$g(n)=1,550\\$ of course being far less than \\$n\\$. The prime is \\$p\_n=18,361,375,334,787,046,697\\$, which is of course far too large for any conventional regex engine to match in unary, but theoretical accuracy up to infinity is the goal here.

```
^                      # tail = N = input value
# Calculate π(N) = the number of primes <= N, by counting
# from the largest to the smallest prime.
(?=                    # Atomic lookahead - lock in this match once it completes
    (
        (?!(xx+)\2+$)  # Assert tail is not composite; since this is done at the
                       # beginning of the loop, it also asserts N is not composite
                       # on the first iteration.
        (x+?)          # Eliminate the false primality positive of 0, and advance
                       # forward as little as necessary to make the next iteration
                       # match the next prime; push a capture onto the Group 3
                       # stack (containing the Kth prime gap, counting down from
                       # K=π(N) to K=1, such that by the time this loop finishes,
                       # on the top of the stack will be the value 1, and below
                       # that, the first prime gap, which is also 1).
    )+                 # Loop at least once, and as many times as can be done
                       # until it stops matching.
    x                  # Assert that tail == 1, to force the above loop to keep
                       # finding subsequent smaller primes (instead of exiting
                       # after finding only one prime) until the smallest prime,
                       # 2, is reached.
)
(?<-3>x){2,}   # Pop all Group 3 captures off the stack, asserting that the count
               # is ≥ 2 (to eliminate the non-composite numbers 0 and 1 from being
               # falsely identified as prime), and doing head += 1 for each one.
               # Since this isn't done atomically, we need to subsequently verify
               # that all captures were popped, due to backtracking if the
               # following assertion fails.
(?<!
    \3         # Assert that the Group 3 capture stack is empty. Note that this
               # will only work up to infinity if the Kth prime gap is always less
               # than or equal to K, i.e. that in OEIS A001223, a(K) ≤ K up to
               # infinity. This is because if the below alternative matches, due
               # to N being prime but not super-prime, it will cause the negative
               # lookbehind to fail to match, causing the regex engine to
               # backtrack into the "(?<-3>x){2,}" loop above, which at each step
               # will subtract 1 from head, and restore a prime gap onto the top
               # of the stack, starting with the last one. This will never reach
               # the point of restoring either of the bottom two stack values
               # (which are 1, 1) due to the "{2,}" constraint, which is good
               # because the bottom-most one would compare 1 against 0, which is
               # not less than or equal and would prevent this golf from working.
               #
               # Thus if there is any counterexample where a(P) > P, such that P
               # is prime, this would cause \3 to fail to match with a non-empty
               # capture stack (whereas it's intended only to fail to match due to
               # the stack being empty and \3 being unset), and then the below
               # alternative would be tried, also failing to match due to P being
               # prime, resulting in the negative lookbehind matching, resulting
               # in a false positive for the {P+1}th prime and every subsequent
               # prime.
|
    ^\4+(x+x)  # Assert that head is not composite (and since it's already
               # been forced to be ≥ 2, this asserts it to be prime).
)

```
> 1 votes

# Answer
# Nekomata \+ `-e`, 3 bytes

```
QƥQ

```

Attempt This Online!

```
QƥQ
Q       Check if the input is a prime
 ƥ      Count number of primes <= input
  Q     Check if the result is a prime

```
> 1 votes

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