# What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on the first try can be difficult. There is a much better chance of your challenge being well received if you post it in the Sandbox first.

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

## This Question Has _____ Views code-golfstack-exchange-api

posted

• I think currently the challenge will only be who can get the shortest domain that'll respond with the output. I think you should limit the challenge to only accessing the stack exchange api, and not any other website – Command Master Apr 16 at 7:59
• @CommandMaster But any other domain will be wrong as soon as the number of views goes up. The program should always print out the number of views this question has at the moment you actually run the program. – izlin Apr 16 at 8:48
• someone can register a domain which will retrive the live number – Command Master Apr 16 at 8:51
• @CommandMaster that is either the "Fetching the desired output from an external source" or the "Outsourcing the real answer" loophole. – my pronoun is monicareinstate Apr 16 at 10:30

# Reconstruct an image from columns graphical-output

You are given an image with all pixel-wide columns shuffled. The challenge is to attempt to reconstruct the image.

[image gallery of varying difficulties]

## Sandbox stuff

or (probably asking for fewest inversions)?

Random thought: if rearranging the pixels was similar to the assignment problem, this seems to be similar to the traveling salesman problem.

## A065825 code-golfsequencearithmetic

(This is A065825.) The defaults apply, so you can pick another format other than this one.

Given an input integer n, find the smallest number k so that there exists an n-item subset of {1,...,k} where no three items form an arithmetic progression.

## Procedure

Here, we calculate A065825(9).

We assume you have already looped from 1 to 19, and k=20 (it's just an example).

### 1. Generate a range from 1 to k.

[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]


### 2. Pick n items from that sequence, following the original order of the sequence.

[1 2 6 7 9 14 15 18 20]


### 3. No 3 items form an arithmetic progression.

If a sequence has arithmetic progression, it basically means the sequence has the same step between every two consecutive items.

For example, the sequence of positive even numbers ([2 4 6 8 ...]) has a consistent step (i.e. 4-2=2, and 6-4=2, etc.), so it has arithmetic progression.

The Fibonacci sequence ([1 1 2 3 5 8 13 21 ...]) does not have arithmetic progression, since it does not have a consistent step. (3-2=1, 5-3=2, 8-5=3, etc.)

As an example, let's pick 3 items from our generated sequence.

[1 2 6 [7 9 14] 15 18 20]


The picked 3-item sequence does not have arithmetic progression, since the differences are respectively 9-7=2 and 14-9=5.

This has to apply to every 3-item pair:

[[1 2 6] 7 9 14 15 18 20] (2 -1 =1, 6 -2 =4)
[1 [2 6 7] 9 14 15 18 20] (6 -2 =4, 7 -6 =1)
[1 2 [6 7 9] 14 15 18 20] (7 -6 =1, 9 -7 =2)
[1 2 6 [7 9 14] 15 18 20] (9 -7 =2, 14-9 =5)
[1 2 6 7 [9 14 15] 18 20] (14-9 =5, 15-14=1)
[1 2 6 7 9 [14 15 18] 20] (15-14=1, 18-15=3)
[1 2 6 7 9 14 [15 18 20]] (18-15=3, 20-18=2)


Here are some examples of picking non-consecutive items from the output sequence:

[1 [2] 6 [7] 9 [14] 15 18 20] (7-2=5,14-7=7)
[[1] 2 6 [7] [9] 14 15 18 20] (7-1=6,9 -7=2)


If the above is satisfied for k, then k is a valid output for A065825(9).

## Meta

Do you think this challenge should be splitted into separate challenges? It seems that it is a single sequence on OEIS.

## Test cases

Here is a reference program I use to check my test cases.

n       a(n)
1       1
2       2
3       4
4       5
5       9
6       11
7       13
8       14
9       20


# Are these two DFAs equivalent?

Two Deterministic Finite Automata or DFAs can be checked to see if they accept same set of strings in polynomial time. See section 3.3 of this for a long list of methods and this SO question/answer for a much shorter list.

Input

Your input will be two DFAs. In order to be able to test your code, it needs to be able to handle DFAs in the following format. This is taken directly from GAP (and slightly simplified).

Automaton( Type, Size, Alphabet, TransitionTable, Initial, Accepting )


For the input, Type will always be "det". Size is a positive integer representing the number of states of the automaton. Alphabet is the number of letters of the alphabet. TransitionTable is the transition matrix. The entries are non-negative integers not greater than the size of the automaton are also allowed. Initial and Accepting are, respectively, the lists of initial and accepting states.

For example:

Automaton("det",4,2,[ [ 1, 3, 4, 0 ], [ 1, 2, 3, 4 ] ],[ 3 ],[ 2, 3, 4 ])


This has transition table:

   |  1  2  3  4
-----------------
a |  1  3  4
b |  1  2  3  4
Initial state:    [ 3 ]
Accepting states: [ 2, 3, 4 ]


And diagram:

It is equivalent to:

Automaton("det",3,2,[ [ 1, 3, 1 ], [ 1, 2, 3 ] ],[ 2 ],[ 2, 3 ])


which has diagram:

A more complicated example:

Automaton("det",6,4,[ [ 0, 2, 3, 5, 0, 0 ], [ 1, 3, 5, 0, 0, 0 ], [ 1, 3, 5, 6, 0, 0 ], [ 2, 3, 5, 0, 0, 0 ] ],[ 1 ],[ 1, 4, 5, 6 ])


has diagram:

It is equivalent to:

Automaton("det",5,4,[ [ 2, 2, 2, 4, 5 ], [ 2, 2, 3, 1, 4 ], [ 2, 2, 3, 1, 4 ], [ 2, 2, 5, 1, 4 ] ],[ 3 ],[ 1, 3 ])


with diagram:

# More example of equivalent DFAs

1.

Automaton("det",18,4,[ [ 2, 2, 6, 10, 2, 6, 7, 16, 14, 10, 18, 14, 7, 14, 15, 16, 7, 18 ], [ 3, 3, 7, 11, 3, 7, 15, 11, 7, 17, 15, 18\
, 18, 7, 15, 17, 15, 15 ], [ 4, 4, 8, 7, 4, 13, 15, 15, 16, 7, 8, 7, 15, 7, 15, 15, 16, 13 ], [ 5, 5, 9, 12, 5, 14, 7, 13, 9, 14, 17, 12, \
13, 14, 15, 7, 17, 7 ] ],[ 1 ],[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18 ])

Automaton("det",16,"abcd",[ [ 1, 2, 15, 15, 5, 6, 7, 7, 6, 2, 16, 12, 12, 16, 15, 16 ], [ 1, 3, 1, 7, 9, 15, 1, 1, 15, 8, 7, 3, 8, 15, 1, \
15 ], [ 1, 1, 2, 1, 13, 4, 4, 10, 10, 1, 15, 15, 15, 2, 1, 15 ], [ 1, 15, 3, 4, 5, 16, 15, 3, 14, 4, 11, 16, 11, 14, 15, 16 ] ],[ 5 ],[ 2,\
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ])

2.
Automaton("det",50,4,[ [ 2, 2, 9, 13, 17, 9, 13, 17, 9, 24, 28, 30, 13, 33, 36, 30, 17, 9, 13, 9, 13, 39, 30, 24, 25, 44, 42, 28, 24, 30, 47, 39, 33, 50, 36, 36, 42, 46, 39, 25, 24, 42, 43, 44, 36, 46, 47, 42, 25, 50 ], [ 3, 6, 10, 14, 18, 10, 14, 20, 10, 25, 14, 10, 32, 34, 34, 38, 20, 10, 14, 10, 14, 38, 10, 25, 43, 34, 25, 45, 46, 10, 32, 49, 34, 43, 34, 49, 50, 50, 49, 50, 46, 25, 43, 49, 49, 50, 45, 50, 43, 43 ], [ 4, 7, 11, 15, 19, 11, 15, 21, 22, 26, 26, 31, 15, 11, 25, 15, 21, 11, 15, 11, 15, 40, 15, 40, 43, 43, 44, 26, 26, 15, 44, 31, 41, 26, 47, 25, 25, 22, 40, 43, 40, 25, 43, 43, 47, 41, 44, 44, 44, 40 ], [ 5, 8, 12, 16, 5, 12, 16, 8, 23, 27, 29, 12, 23, 35, 37, 16, 8, 12, 16, 12, 16, 41, 23, 42, 25, 40, 27, 27, 29, 23, 48, 45, 37, 49, 35, 42, 37, 48, 42, 40, 41, 42, 43, 25, 45, 37, 27, 48, 49, 25 ] ],[ 1 ],[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50 ])

Automaton("det",39,4,[ [ 1, 2, 3, 3, 5, 24, 7, 8, 22, 20, 8, 32, 18, 18, 3, 19, 25, 18, 19, 20, 25, 22, 23, 24, 25, 25, 24, 23, 5, 2, 35, 32, 19, 19, 35, 36, 36, 36, 36 ], [ 1, 38, 1, 23, 15, 9, 11, 26, 23, 28, 26, 10, 9, 26, 1, 3, 22, 26, 3, 28, 22, 23, 1, 15, 3, 3, 15, 1, 28, 27, 10, 27, 23, 23, 38, 15, 28, 15, 28 ], [ 1, 5, 1, 1, 1, 4, 12, 6, 6, 31, 31, 37, 37, 30, 5, 5, 29, 37, 3, 21, 4, 21, 4, 4, 4, 29, 30, 29, 1, 5, 29, 37, 5, 3, 29, 3, 3, 2, 2 ], [ 1, 16, 3, 4, 3, 21, 7, 18, 33, 39, 14, 13, 13, 14, 15, 16, 17, 18, 19, 34, 21, 34, 3, 19, 19, 16, 38, 15, 4, 33, 17, 18, 33, 34, 16, 19, 34, 38, 39 ] ],[ 7 ],[ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 ])


3.

Automaton("det",288,4,[[2, 6, 10, 14, 18, 6, 10, 14, 18, 25, 29, 33, 36, 40, 43, 46, 36, 53, 10, 14, 18, 10, 14, 18, 25, 29, 60, 36, 29, 67, 71, 75, 77, 81, 83, 87, 88, 90, 94, 40, 98, 46, 104, 108, 111, 46, 116, 120, 75, 123, 127, 129, 53, 10, 14, 131, 129, 71, 75, 136, 140, 143, 146, 87, 149, 75, 67, 68, 155, 153, 156, 159, 161, 163, 75, 165, 77, 170, 81, 172, 81, 67, 88, 123, 156, 146, 87, 88, 156, 90, 183, 186, 188, 87, 90, 183, 94, 192, 143, 197, 199, 116, 75, 104, 108, 204, 172, 108, 208, 120, 127, 159, 90, 199, 163, 159, 215, 156, 149, 120, 153, 217, 123, 218, 131, 221, 127, 159, 87, 123, 225, 88, 155, 67, 165, 136, 227, 143, 221, 123, 218, 221, 143, 68, 67, 88, 123, 127, 143, 217, 68, 67, 153, 154, 155, 156, 234, 235, 159, 120, 161, 237, 143, 217, 165, 143, 241, 199, 188, 242, 197, 75, 67, 165, 241, 217, 248, 250, 172, 146, 221, 161, 225, 234, 111, 186, 153, 75, 217, 75, 188, 192, 257, 188, 68, 120, 90, 186, 127, 90, 208, 146, 221, 259, 140, 120, 235, 208, 165, 262, 199, 188, 68, 120, 215, 267, 217, 218, 250, 83, 75, 165, 75, 215, 225, 208, 234, 71, 149, 153, 75, 235, 208, 234, 67, 265, 272, 233, 241, 143, 120, 242, 257, 155, 153, 143, 153, 248, 267, 250, 116, 120, 75, 237, 71, 235, 250, 163, 259, 227, 153, 262, 67, 75, 155, 233, 272, 265, 116, 241, 281, 272, 68, 149, 120, 155, 283, 163, 67, 208, 285, 265, 287, 233, 285, 68, 287, 68], [3, 7, 11, 15, 19, 7, 11, 15, 22, 26, 30, 15, 37, 41, 44, 47, 50, 54, 11, 15, 19, 11, 15, 22, 26, 30, 61, 37, 30, 68, 72, 30, 78, 47, 84, 26, 30, 91, 37, 96, 99, 102, 105, 109, 112, 115, 117, 109, 122, 124, 128, 130, 54, 11, 15, 130, 132, 72, 30, 137, 141, 122, 147, 132, 150, 30, 68, 154, 109, 68, 157, 109, 162, 164, 30, 166, 168, 99, 102, 173, 175, 176, 177, 124, 128, 147, 132, 30, 72, 168, 184, 115, 189, 132, 96, 99, 37, 166, 195, 96, 99, 201, 150, 105, 109, 205, 164, 109, 154, 109, 157, 109, 211, 112, 213, 109, 154, 72, 109, 195, 208, 215, 124, 208, 130, 150, 166, 224, 26, 124, 157, 30, 226, 217, 166, 115, 213, 150, 30, 124, 208, 150, 195, 208, 176, 177, 124, 72, 224, 208, 233, 217, 68, 154, 195, 214, 195, 208, 109, 109, 236, 117, 195, 208, 214, 195, 201, 99, 173, 166, 168, 177, 68, 246, 213, 215, 68, 251, 173, 147, 150, 254, 166, 195, 99, 175, 208, 30, 215, 122, 164, 166, 251, 173, 154, 195, 78, 258, 166, 168, 154, 147, 150, 260, 141, 226, 217, 154, 214, 254, 184, 263, 154, 195, 154, 109, 208, 208, 269, 84, 177, 246, 150, 154, 166, 215, 195, 166, 150, 208, 150, 208, 215, 195, 215, 213, 195, 208, 213, 150, 195, 166, 254, 109, 68, 224, 233, 68, 109, 236, 201, 226, 150, 213, 166, 208, 277, 117, 278, 213, 233, 236, 215, 279, 195, 208, 224, 201, 117, 280, 254, 195, 208, 109, 109, 226, 213, 213, 215, 215, 277, 280, 195, 208, 236, 233, 195, 208], [4, 8, 12, 16, 20, 8, 12, 16, 23, 27, 31, 34, 38, 42, 12, 48, 51, 55, 12, 16, 20, 12, 16, 23, 56, 58, 62, 51, 65, 69, 73, 76, 79, 69, 85, 42, 89, 92, 95, 42, 100, 48, 106, 31, 113, 48, 118, 68, 48, 125, 48, 51, 55, 12, 16, 62, 51, 133, 135, 138, 56, 144, 62, 148, 151, 48, 144, 154, 154, 155, 69, 118, 154, 69, 48, 161, 79, 171, 69, 174, 69, 69, 178, 180, 69, 85, 148, 138, 182, 92, 95, 155, 135, 42, 92, 95, 148, 193, 76, 198, 200, 118, 48, 202, 58, 62, 206, 207, 69, 209, 210, 89, 92, 200, 135, 178, 216, 69, 174, 68, 68, 138, 202, 65, 219, 222, 48, 118, 148, 56, 138, 118, 154, 69, 155, 138, 228, 144, 206, 106, 229, 174, 144, 154, 144, 138, 202, 48, 144, 138, 154, 144, 68, 154, 154, 69, 228, 133, 152, 165, 154, 69, 182, 240, 155, 135, 155, 200, 135, 243, 198, 210, 244, 155, 165, 152, 249, 144, 206, 219, 252, 154, 178, 255, 113, 155, 155, 210, 240, 135, 135, 65, 151, 48, 155, 209, 92, 155, 210, 92, 244, 62, 206, 138, 202, 68, 151, 144, 161, 68, 200, 135, 265, 165, 266, 73, 152, 207, 144, 62, 48, 161, 76, 249, 138, 69, 271, 133, 73, 265, 135, 151, 144, 266, 144, 155, 182, 133, 155, 182, 161, 274, 151, 161, 265, 135, 155, 266, 151, 144, 138, 161, 275, 69, 73, 276, 144, 135, 138, 249, 68, 68, 244, 135, 161, 151, 144, 155, 138, 155, 151, 144, 155, 151, 161, 161, 249, 69, 69, 244, 144, 155, 271, 276, 144, 155, 266, 265], [5, 9, 13, 17, 21, 9, 13, 17, 24, 28, 32, 35, 39, 28, 45, 49, 52, 9, 13, 17, 21, 13, 17, 24, 57, 59, 63, 64, 66, 70, 74, 32, 80, 82, 86, 28, 32, 93, 39, 97, 101, 103, 107, 110, 114, 66, 119, 121, 49, 126, 49, 52, 9, 13, 17, 63, 64, 134, 59, 139, 142, 145, 63, 64, 152, 66, 153, 68, 144, 70, 158, 160, 151, 134, 66, 167, 169, 101, 134, 59, 70, 82, 179, 181, 82, 86, 64, 66, 74, 169, 185, 187, 190, 97, 191, 101, 64, 194, 196, 191, 101, 160, 103, 203, 160, 63, 103, 121, 195, 110, 179, 110, 212, 114, 214, 167, 213, 134, 160, 153, 121, 158, 203, 187, 220, 223, 66, 119, 57, 142, 139, 59, 151, 134, 187, 66, 214, 152, 66, 107, 230, 231, 153, 144, 145, 139, 203, 103, 232, 187, 151, 152, 153, 154, 68, 70, 214, 187, 121, 160, 68, 238, 239, 230, 70, 214, 187, 101, 59, 194, 169, 179, 245, 247, 214, 232, 70, 152, 66, 220, 253, 144, 194, 196, 101, 70, 187, 194, 256, 190, 231, 66, 152, 66, 195, 196, 80, 247, 194, 169, 213, 63, 103, 139, 203, 261, 152, 68, 239, 121, 185, 264, 213, 214, 68, 268, 121, 121, 145, 63, 139, 270, 223, 195, 66, 238, 239, 187, 74, 230, 231, 121, 266, 153, 232, 195, 236, 273, 70, 74, 239, 66, 121, 268, 245, 119, 247, 153, 144, 153, 187, 270, 253, 195, 167, 230, 232, 119, 66, 70, 261, 153, 256, 264, 236, 144, 266, 273, 158, 247, 144, 68, 273, 121, 167, 282, 195, 70, 158, 284, 266, 286, 236, 288, 68, 286, 68, 288]],[1],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288])

Automaton("det",266,4,[[1, 127, 50, 50, 115, 249, 50, 8, 257, 10, 151, 12, 13, 14, 81, 78, 34, 106, 137, 107, 21, 22, 82, 89, 71, 43, 43, 62, 63, 63, 44, 10, 179, 171, 214, 265, 206, 38, 137, 152, 21, 151, 71, 22, 41, 41, 47, 13, 49, 50, 50, 210, 50, 210, 116, 90, 64, 49, 207, 207, 207, 62, 232, 64, 64, 89, 151, 236, 236, 70, 71, 236, 116, 260, 128, 75, 13, 38, 77, 133, 14, 82, 13, 13, 77, 235, 64, 64, 231, 206, 138, 91, 91, 206, 90, 264, 137, 169, 10, 10, 41, 71, 232, 228, 232, 21, 21, 107, 106, 110, 111, 266, 256, 114, 114, 116, 251, 251, 116, 114, 114, 111, 266, 260, 122, 182, 127, 128, 129, 213, 132, 132, 129, 49, 49, 138, 138, 138, 249, 71, 43, 43, 210, 235, 183, 214, 132, 265, 206, 138, 232, 64, 64, 153, 153, 64, 152, 152, 82, 236, 236, 82, 116, 116, 64, 207, 266, 64, 231, 169, 171, 250, 227, 70, 175, 175, 176, 10, 47, 178, 178, 110, 111, 266, 260, 122, 266, 127, 213, 49, 49, 152, 257, 153, 257, 90, 90, 183, 250, 264, 62, 228, 229, 82, 82, 206, 64, 266, 249, 249, 249, 242, 213, 214, 64, 116, 114, 114, 50, 50, 236, 236, 261, 115, 152, 251, 8, 228, 229, 229, 231, 232, 237, 235, 235, 236, 237, 235, 235, 235, 235, 235, 235, 242, 242, 242, 115, 251, 249, 250, 116, 116, 116, 207, 64, 265, 266, 257, 256, 266, 264, 261, 260, 264, 265, 266], [1, 125, 1, 114, 114, 121, 115, 3, 23, 19, 13, 15, 230, 28, 201, 202, 16, 84, 123, 103, 105, 208, 114, 84, 172, 199, 199, 119, 83, 83, 123, 170, 16, 31, 27, 26, 25, 104, 102, 23, 28, 13, 120, 208, 48, 103, 19, 230, 239, 1, 114, 218, 115, 219, 82, 140, 23, 208, 204, 216, 216, 119, 174, 119, 119, 84, 13, 115, 115, 50, 120, 50, 82, 204, 262, 79, 230, 104, 203, 85, 28, 114, 230, 230, 203, 3, 23, 119, 96, 96, 96, 123, 102, 140, 208, 3, 200, 200, 98, 97, 103, 120, 119, 120, 119, 28, 105, 103, 105, 54, 3, 23, 141, 1, 250, 50, 82, 114, 50, 1, 250, 3, 3, 219, 219, 125, 54, 263, 124, 124, 27, 124, 223, 208, 239, 25, 208, 208, 120, 120, 217, 217, 217, 120, 120, 142, 142, 141, 140, 140, 174, 174, 174, 204, 216, 23, 119, 23, 250, 114, 114, 250, 162, 162, 159, 205, 159, 159, 208, 123, 170, 1, 219, 50, 208, 208, 123, 177, 177, 19, 170, 173, 172, 172, 199, 199, 23, 186, 185, 184, 184, 23, 120, 216, 23, 140, 208, 120, 1, 3, 119, 120, 114, 114, 250, 239, 119, 3, 121, 3, 120, 219, 212, 212, 23, 50, 1, 250, 1, 114, 50, 114, 219, 114, 23, 114, 3, 120, 114, 114, 208, 119, 125, 121, 3, 50, 54, 120, 3, 120, 121, 3, 120, 218, 219, 217, 114, 114, 3, 1, 250, 250, 250, 253, 252, 173, 172, 120, 125, 3, 3, 219, 219, 3, 54, 3], [1, 1, 249, 249, 6, 1, 1, 247, 7, 130, 167, 17, 11, 66, 33, 33, 131, 136, 10, 32, 150, 9, 112, 36, 149, 112, 149, 56, 167, 37, 181, 130, 35, 147, 139, 51, 139, 11, 10, 234, 147, 37, 148, 113, 136, 136, 146, 24, 249, 1, 1, 249, 249, 249, 139, 6, 238, 127, 134, 238, 134, 9, 148, 238, 134, 167, 36, 50, 249, 247, 73, 249, 51, 139, 112, 167, 76, 76, 11, 167, 80, 73, 67, 66, 66, 135, 58, 58, 112, 139, 233, 100, 100, 2, 6, 95, 10, 32, 130, 130, 99, 94, 94, 56, 149, 150, 147, 150, 136, 51, 51, 51, 7, 51, 51, 51, 7, 6, 139, 139, 139, 2, 58, 134, 139, 7, 1, 112, 112, 249, 238, 238, 112, 249, 127, 238, 233, 238, 1, 149, 112, 149, 249, 135, 7, 139, 238, 51, 139, 238, 112, 238, 233, 234, 234, 134, 234, 190, 112, 50, 249, 73, 139, 51, 238, 134, 51, 134, 148, 32, 147, 145, 145, 145, 258, 259, 180, 130, 146, 189, 189, 51, 51, 134, 134, 139, 2, 1, 249, 127, 249, 191, 191, 191, 188, 188, 188, 188, 198, 197, 196, 196, 195, 187, 187, 139, 233, 134, 127, 127, 127, 49, 249, 139, 243, 211, 211, 211, 210, 210, 210, 210, 95, 209, 241, 209, 126, 117, 117, 9, 112, 112, 50, 50, 50, 50, 50, 50, 49, 49, 127, 127, 127, 249, 249, 249, 7, 7, 1, 247, 51, 139, 211, 134, 134, 51, 51, 7, 7, 2, 126, 145, 139, 247, 51, 51], [1, 51, 3, 4, 4, 7, 7, 50, 73, 61, 11, 12, 40, 109, 101, 93, 45, 18, 19, 20, 21, 64, 161, 29, 193, 118, 193, 65, 11, 42, 19, 59, 30, 46, 163, 164, 163, 40, 39, 57, 46, 42, 246, 60, 18, 21, 61, 158, 72, 50, 51, 53, 53, 3, 55, 55, 57, 246, 156, 64, 65, 64, 155, 64, 65, 11, 29, 68, 69, 236, 160, 72, 73, 55, 157, 11, 154, 154, 40, 11, 46, 160, 225, 192, 192, 86, 87, 88, 157, 118, 155, 19, 39, 74, 161, 239, 92, 92, 166, 254, 20, 144, 88, 240, 65, 109, 108, 21, 21, 50, 50, 73, 73, 50, 247, 236, 73, 161, 72, 3, 5, 54, 86, 239, 3, 51, 50, 64, 64, 161, 165, 64, 157, 161, 245, 165, 60, 64, 51, 240, 161, 240, 4, 144, 51, 55, 57, 73, 55, 57, 157, 157, 155, 57, 64, 156, 64, 87, 118, 160, 161, 248, 163, 164, 165, 168, 164, 168, 60, 19, 108, 3, 3, 72, 64, 60, 19, 194, 194, 61, 59, 247, 247, 193, 193, 5, 74, 7, 69, 244, 69, 156, 240, 65, 74, 74, 246, 143, 219, 86, 88, 144, 222, 222, 226, 72, 60, 239, 52, 54, 143, 239, 72, 72, 215, 221, 219, 224, 219, 220, 221, 222, 239, 220, 215, 222, 54, 160, 160, 161, 64, 64, 160, 68, 236, 236, 236, 160, 239, 240, 244, 245, 246, 69, 72, 161, 51, 160, 50, 50, 248, 118, 226, 255, 255, 248, 248, 160, 160, 245, 245, 72, 72, 236, 236, 236]],[12],[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266])


4.

Automaton("det",9,4,[[1, 1, 2, 3, 1, 1, 2, 5, 2], [1, 1, 2, 8, 2, 2, 1, 6, 2], [1, 1, 2, 7, 2, 1, 2, 2, 2], [1, 1, 2, 9, 1, 1, 1, 1, 1]],[4],[2, 6])

Automaton("det",100,4,[[0, 1, 3, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 34, 36, 37, 40, 41, 42, 43, 44, 45, 46, 47, 48, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 68, 69, 71, 72, 73, 78, 79, 81, 84, 85, 86, 90, 93, 94, 95, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 4, 6, 7, 9, 10, 11, 12, 13, 15, 16, 19, 20, 21, 22, 23, 24, 25, 27, 28, 30, 31, 32, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 59, 60, 61, 64, 66, 67, 69, 70, 71, 75, 76, 78, 80, 81, 84, 85, 86, 87, 89, 92, 93, 95, 96, 97, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 22, 23, 26, 28, 29, 30, 32, 34, 35, 38, 40, 41, 45, 47, 49, 50, 53, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 76, 77, 79, 81, 82, 83, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 12, 14, 15, 19, 21, 22, 23, 24, 26, 27, 28, 32, 33, 34, 35, 39, 40, 42, 43, 46, 47, 51, 54, 55, 59, 60, 61, 63, 64, 67, 71, 72, 73, 74, 75, 76, 77, 78, 79, 82, 84, 85, 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],[39],[1, 2, 5, 8, 10, 12, 13, 14, 15, 16, 17, 18, 19, 21, 24, 25, 28, 30, 31, 33, 35, 37, 41, 42, 43, 44, 49, 50, 52, 53, 57, 61, 63, 65, 66, 67, 69, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 100])


5.

# Non-equivalent DFAs


Automaton("det",100,4,[[0, 1, 2, 3, 5, 7, 9, 12, 13, 15, 20, 21, 23, 24, 25, 27, 29, 30, 31, 33, 34, 35, 36, 37, 40, 41, 42, 45, 46, 47, 48, 56, 57, 60, 62, 64, 65, 69, 70, 73, 74, 76, 80, 81, 82, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 9, 11, 12, 13, 16, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 36, 37, 38, 39, 40, 42, 47, 49, 52, 53, 54, 59, 60, 61, 62, 63, 64, 65, 68, 69, 71, 72, 75, 76, 78, 81, 82, 84, 86, 87, 88, 89, 90, 91, 92, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 24, 25, 26, 27, 28, 29, 30, 33, 35, 36, 37, 38, 39, 41, 43, 46, 50, 51, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 70, 73, 74, 76, 77, 78, 80, 83, 86, 87, 89, 91, 92, 93, 95, 98, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 6, 8, 13, 14, 15, 17, 19, 21, 22, 23, 25, 27, 28, 29, 30, 31, 32, 35, 36, 37, 40, 42, 46, 47, 48, 50, 51, 53, 54, 56, 58, 60, 61, 63, 64, 65, 66, 68, 70, 71, 72, 74, 75, 76, 79, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 93, 94, 95, 96, 97, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],[52],[1, 5, 6, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 39, 40, 41, 42, 44, 46, 47, 49, 51, 52, 53, 54, 55, 60, 61, 62, 66, 67, 70, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 86, 87, 89, 90, 92, 94, 96, 97, 98, 99, 100])

Automaton("det",100,4,[[0, 2, 3, 4, 6, 7, 10, 11, 14, 15, 16, 17, 19, 20, 21, 22, 24, 25, 26, 27, 28, 31, 34, 35, 36, 37, 38, 40, 42, 43, 44, 46, 48, 49, 51, 55, 56, 57, 58, 59, 61, 62, 63, 64, 69, 71, 72, 73, 76, 78, 79, 80, 83, 86, 87, 88, 89, 90, 91, 95, 96, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 17, 18, 19, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 40, 41, 42, 43, 45, 47, 48, 50, 51, 53, 56, 57, 59, 60, 62, 63, 64, 71, 72, 73, 75, 76, 77, 79, 80, 83, 85, 86, 87, 89, 90, 91, 92, 93, 96, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 16, 18, 21, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 39, 40, 41, 42, 45, 47, 48, 50, 51, 52, 53, 56, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 78, 79, 80, 82, 84, 85, 86, 89, 90, 93, 94, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 16, 18, 21, 22, 23, 24, 28, 30, 31, 32, 34, 36, 37, 38, 39, 40, 42, 44, 45, 47, 48, 51, 52, 53, 56, 57, 59, 60, 61, 62, 63, 64, 65, 67, 70, 74, 76, 83, 84, 86, 88, 90, 91, 93, 94, 95, 96, 97, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],[17],[1, 6, 7, 8, 9, 10, 11, 12, 13, 16, 18, 19, 22, 23, 27, 28, 29, 30, 32, 35, 36, 38, 40, 41, 42, 44, 46, 47, 48, 50, 51, 53, 54, 55, 62, 64, 66, 71, 72, 74, 75, 76, 79, 83, 86, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, 100])

Automaton("det",100,4,[[2, 3, 6, 7, 8, 9, 10, 12, 14, 15, 16, 20, 21, 25, 26, 28, 29, 30, 32, 35, 36, 37, 40, 42, 43, 44, 46, 47, 48, 50, 53, 54, 55, 57, 58, 59, 62, 63, 64, 65, 67, 68, 69, 72, 73, 75, 77, 79, 81, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 4, 5, 8, 13, 14, 15, 17, 18, 19, 20, 22, 23, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 58, 59, 60, 63, 64, 65, 66, 67, 68, 70, 71, 72, 74, 75, 77, 78, 79, 82, 83, 84, 85, 86, 87, 93, 95, 96, 97, 98, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 3, 6, 7, 9, 10, 12, 13, 14, 15, 16, 17, 19, 20, 21, 23, 25, 27, 28, 30, 31, 32, 37, 38, 40, 41, 42, 45, 47, 49, 50, 51, 52, 56, 59, 61, 63, 64, 65, 68, 70, 72, 73, 74, 76, 77, 78, 80, 81, 85, 86, 87, 88, 92, 93, 94, 96, 98, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 20, 21, 22, 23, 24, 26, 27, 28, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 48, 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 62, 64, 65, 66, 68, 69, 70, 71, 72, 74, 75, 76, 77, 79, 84, 86, 91, 92, 93, 96, 97, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],[46],[1, 2, 7, 8, 10, 12, 13, 15, 17, 18, 20, 22, 23, 24, 25, 27, 28, 29, 30, 32, 33, 35, 36, 37, 39, 41, 42, 44, 45, 47, 49, 50, 51, 52, 54, 55, 57, 59, 61, 63, 65, 66, 67, 68, 69, 70, 71, 73, 75, 76, 77, 79, 80, 81, 82, 85, 86, 88, 91, 92, 93, 94, 95, 96, 97, 98])

Automaton("det",100,4,[[0, 1, 4, 5, 7, 8, 9, 10, 11, 12, 15, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 35, 36, 37, 39, 43, 44, 45, 46, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 62, 63, 67, 68, 70, 72, 73, 74, 76, 77, 78, 81, 82, 83, 85, 87, 93, 94, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 4, 5, 8, 10, 12, 15, 16, 17, 18, 19, 20, 21, 27, 29, 30, 31, 32, 34, 35, 36, 39, 40, 42, 45, 46, 47, 49, 50, 51, 52, 55, 58, 59, 60, 61, 62, 63, 64, 66, 67, 70, 71, 72, 73, 74, 75, 77, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 92, 94, 96, 98, 99, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 3, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 20, 21, 23, 30, 31, 33, 34, 35, 37, 38, 39, 42, 43, 44, 46, 47, 48, 50, 52, 53, 54, 55, 56, 58, 59, 60, 61, 63, 64, 65, 66, 67, 70, 71, 75, 76, 77, 80, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 94, 98, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 3, 4, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18, 19, 20, 21, 22, 24, 26, 27, 28, 29, 31, 33, 34, 35, 37, 38, 40, 41, 43, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 62, 64, 65, 66, 67, 68, 69, 71, 72, 75, 76, 77, 80, 81, 82, 83, 86, 87, 88, 91, 93, 94, 95, 96, 97, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],[45],[2, 4, 6, 7, 11, 12, 14, 15, 16, 17, 19, 20, 24, 25, 27, 28, 29, 30, 37, 39, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 67, 71, 72, 76, 81, 82, 83, 84, 85, 86, 87, 88, 91, 92, 94, 95, 99, 100])


# Score

This question is and . Your code must be able to run all the test cases in less than a minute on TIO.

# Boolean Variable Satisfiability code-golf

You are given a logical expression containing 'true', 'false', 'variable' and some common boolean operators. Assuming that all variables are independent and can be freely set to either true or false, is it possible assign values to the variables such that the expression evaluates to true?

For example, the expression true and variable and not variable can indeed evaluate to true (if the first variable is true and the second is false). However, the expression false and variable cannot ever evaluate to true, regardless of what values you set the variable to.

Note that you are not required to construct a solution; you only need to determine whether or not it exists.

# Input

You are given an expression in Reverse Polish notation, using the following symbols:

• T - True
• F - False
• V - Variable
• & - Logical AND
• | - Logical OR
• ^ - Logical XOR
• ! - Logical NOT

As an example, TFV!T^|& represents the expression true and (false or (not variable xor true)).

# Output

The program should output a truthy value iff the expression can be evaluated to true for some set of variable assignments. Otherwise, a falsy value should be outputted.

# Examples

Here are a few example expressions and their expected outputs:

TF&
False

FV|V&
True

VV!&
True

VV^!
True

VV&F|VVT|!&V!&&
False

VV&F|VVT|!&V!^&
True

TFV!T^|&
True

VT|!V&F|VF&!T^^
False


# Scoring

This is , so the shortest answer wins.

I've written this as if I would post it right away. However, seeing as this is the first challenge I've written for this site, any and all input is welcome so as to make sure it's of an acceptable standard.

• Thanks you for using the sandbox. – Adám Apr 23 at 12:00
• One thing that bothers me here is the combination of two tasks: a) parsing the RPN b) finding if the expression is satisfiabiable. – Adám Apr 23 at 12:13
• So every appearance of V is independent of each other? Then it can be solved in O(n) by resolving each inner node into T/F/V on the fly. Cool challenge. But as Adám said, the task right now is two tasks combined, and we want to get it focused to b). My suggestion is to allow the programs to take any unambiguous format that can describe a statement as input. That includes RPN, PN, fully parenthesized infix, and (most notably) a syntax tree. – Bubbler Apr 24 at 0:08

## Island Rose Breeder

Island Roses have an extremely simple genetic code, with just 4 genes: R, Y, W, and B, each with two alleles. This means their entire genome can be represented by four 2-bit gene pairs of the form: 00-00-00-00 (01 and 10 are equivalent)

Island Roses can be bred together. When two roses are bred, each parent flower donates one allele for each gene. This can be represented by Mendelian genetics via a Punnett square:

For instance, a 01-00-11-11 flower that is bred with a 01-00-11-11 flower will result in either:

• a 00-00-11-11 flower (25% chance)
• a 01-00-11-11 flower (50% chance)
• a 11-00-11-11 flower (25% chance)

Based on their genes, Island Roses can display one of 8 phenotypes -- colors.

A list of the genotypes and their corresponding phenotypes can be found here.

## Challenge

Given a starting stock of Roses, determine how many generations (and which Roses to use) it would take to breed a particular phenotype.

Because genetic testing is expensive, you can only identify the results of breeding by observing the phenotype of the offspring. For example, Breeding two 11-00-00-01 (Red) roses gives three distinct phenotypes, so any Black rose that results must have genotype of 11-00-00-11.

In the case of ambiguous phenotypes, subsequent generations of breeding can be done to disambiguate the specific phenotypes.

Example Input Roses:

• 11-00-00-01
• 00-00-01-00
• 00-11-00-00

Target Phenotype:

• 11-11-11-00
• Could you add some examples of what output should look like? Some test cases showing input -> output would also be helpful. Finally, make sure to mention the winning criteria (eg. if it's Code Golf, you should explicitly mention that) – math junkie Apr 25 at 21:28

## Which anagram is the user trying to guess?

### Input

1. A list (in any form) of target words
2. A guess word

You can take these in any form (eg, an array in which the first element is the guess word).

### Output

• If the letters of the guess word occur (in any order) in exactly one of the target words, output that target word.
• Otherwise do something other than output letters. (Outputting nothing, or a number is fine. Throwing an error is fine. Infinite looping is not fine. :))

### Assumptions

• The members of the list, and the guess word, are each strings of 1-15 lowercase letters.
• Members of the list might be anagrams of each other. (In this case, no guess word will ever succeed.)

### Examples

• list: fish, dog, cat, horse, porcupine:
• guess: re -> (fail)
• guess: so -> horse
• guess: god -> dog
• guess: kitten -> (fail)

### Scoring and rules.

Code golf. Standard rules, no standard loopholes etc.

• "Don't assume that no two members of the list are anagrams of each other" The double negative is hard to read at first glance, consider changing it to "Members of the list may be anagrams of each other" – math junkie Apr 29 at 16:50
• – math junkie Apr 29 at 16:52
• @mathjunkie Thanks, nice one. – Steve Bennett Apr 29 at 23:37

### Premise

I've crafted this zero-player game in an attempt to create a problem simple to explain but that would require an intricate implementation.
Sadly in the making of it, I realized that annoying conditions are required for safety (avoid to get stuck in loops) and non-ambiguity.

Ask me justifications for any rule that seems too arbitrary. Unfortunately it turned out to be 50% design and 50% precautions.

# Turning Tiles game

The field of this game is a square toroidal grid (like that of Snake or Pacman) populated by dots. Each grid unit is one of the following:

• tile (there are $$\4\$$ type of tile, indicating directions e.g.: ^ > v < or 1 2 3 4)
• wormhole

The dot behaviour is very simple: it moves following the direction indicated by the tiles it walks on, and to wreak havoc after each step it rotates the left tile in a copycat fashion.
When two dots collide they will remain together forever and can be considered as one.
So the dots will either converge into one (wormholes facilitate this scenario) or remain stuck in a loop.

## Detailed explanation:

One iteration of the game consists of three phases:

• Move (M)
• Peek (P)
• Edit (E)

Phases are performed individually by each dot: next phase will begin only when every dot completed current phase.

At the beginning of iteration i there are ni distinct dots.
(when n>0) if ni < ni-1 then iteration i is a downgraded iteration.

Let x be a dot.

def tunnelling?:
- If x is on a tile do nothing.
- If x is on a wormhole it will immediately exit from the linked wormhole keeping the direction and tunnelling? is called.

def handle_overwrite_error:
- If multiple overwrite errors occurred in current iteration, x won't overwrite its starting tile.
- Else a wormhole will open in place of x's starting tile.

begin iteration

M:
The tile x is on becomes its starting tile.
x moves one unit in the direction indicated by its starting tile and tunnelling? is called.
The tile x is on becomes its landing tile.
___

P:
x peeks at the landing tile of its closest dot(s) and plans its editing.
If the overwiting direction can't be uniquely determined (*) an overwrite error will rise for x.
___

E:
If x raised an overwrite error, handle_overwrite_error is now called.
Else x overwrites its starting tile with the direction decided in P.
___

If a wormhole appeared under someone's feet, that dot disappear (exiting direction couldn't be decided).
(This rule guaratees that tunnelling? will always terminate.)

end iteration

Wormholes chain: since one single wormhole is allowed to open in each iteration, wormholes inherit their linkage order by the chronological order they popped-up. Last wormhole close the chain.

Metric: unsurprisingly taxicab metric applyied on a toroidal grid...

• But here can enter the picture a devilish modification. What if the wormholes play a role in the metric? So that let's say x and y are 2 unit apart, with a wormhole in between they would be 4 unit apart instead. Also to find the closest dot would be totally trickier, cause the paths through any nearby wormhole have to be tried.

(*): For the overwriting direction not to be decidible the presence of multiple dots sharing the propriety "x doesn't have any dot closer than me" is necessary but not sufficient. Also their landing tiles have not to be the same.

# What can be asked? (feedback)

Is this an interesting game?

Probably I've exaggerated it in the explanation but I cared to be as clear as possible and many requirements are conceivable to make it work.
Of course if that's too much I'd give up wormhole...

Rules in Shortest Game of Life inspires me

Of course the input would be the starting configuration, should wormholes be prohibited in input?

If simulation is not visually shown there would be an ITERATION_CAP
Fixed or passed in input as well?

Regarding output, the quirk of this game are the downgraded iterations. I thought that the sequence (or sum) of their indices can be returned along with last number of distinct dots...

This will be challenge, so the shortest code wins.
Default loopholes are forbidden.

• Can we require inputs to be padded for us? – Member for 3 months Apr 17 at 8:14
• Can we output via a digit array? – Member for 3 months Apr 17 at 8:14
• What do you mean by output via a digit array? Like [2,4] instead of 24? – Command Master Apr 17 at 8:36
• What do you mean by Are you sure you mean base 19, not base 10?? In base 10 16 isn't a digit, and [1, 16] isn't a number – Command Master Apr 17 at 8:38
• Why base 19? That seems pretty arbitrary – xnor Apr 17 at 8:40
• It's the smallest base for which the sum of any two digits in base 10 fit in – Command Master Apr 17 at 8:41
• Looks like a cool challenge :) I think a few more test cases would be useful. Some slightly larger test cases would also be great – math junkie Apr 26 at 19:46
• I doubt that there is any approach other than "take the decimal digits, sum the digits as vectors and convert from base 19" here. – my pronoun is monicareinstate May 1 at 2:43

## Modular distance code-golfintegercounting

You are given 3 non-negative integers: the domain d, the beginning index b, and the ending index e.

## What is a modular distance?

Assume d=5 here. First, generate a range from 0 to 5-1:

0 1 2 3 4


We start from the beginning index. Assuming that is 3:

0 1 2 3 4
^


We continually go right, circling every number we've passed, until we met the ending index e.

0 1 2 O O
^


If the pointer is at the right end, it wraps around to the left.

Assuming e=0:

O 1 2 O O
^


We filter out every item we've circled:

0 3 4


Then, find how many items there are in this list:

3


Subtract it by 1 and it's our result:

2


## Specification

• You can always assume that b<d and e<d.

## Test cases

6 2 5 -> 3
5 3 0 -> 2

• Do you mean to say "we filter out every item we haven't circled"? – Lyxal May 5 at 8:30
• Is the modular distance just $(e - b) \bmod d$ ? – dingledooper May 5 at 20:57

# Parse vietnamese infinite decimal notation

I wanted to express infinite decimals in text, but overlines are hard.

You need to take a decimal in vietnamese notation, and output the first 10 or more digits of the normal variant.

## The notation

The way it works is that you have 0.ab(cd) and it means 0.abcdcdcd.... Of course, you can have any amount of digits in each spot, even zero. You can also omit the infinite part to represent finite decimals.

## Notes

It's allowed to not accept 0.2 or 0.2() as input, and it's also allowed to output 0.2000000000 if you do accept them as input.

• Can we output the variant infinitely, instead of outputting the first 10 digits? – Member for 3 months May 6 at 6:52
• An existing keyboard-friendly notation is 0.ab(cd) (Wikipedia reference). – Bubbler May 6 at 6:57
• @Λ̸̸ Sure. I'll edit the question. – PkmnQ May 6 at 8:22
• So is the challenge just to split at the ( and then append the first part to the stuff in the brackets repeated 10 times? – math junkie May 6 at 16:21
• Is this a good time to post the question? – PkmnQ May 10 at 9:22

# Produce a range

Your task is to take a list of integers and find inputs to a Python range call to produce that list. That is, output three values (start, stop, step) so that range(start, stop, step) equals the given list.

You can assume that this is possible, which that consecutive numbers in the list all have the same nonzero difference. Be careful that your code works for negative step sizes, as well as for empty or singleton inputs.

How range works

Python's built-in range produces a list* of equally-spaced numbers. Called as range(start, stop, step), it counts from the start value in increments of step like

[start, start + step, start + 2 * step, ...]


This list continues as long as the value is below stop given positive step, or above stop given negative step. If the start value already fails this test, an empty list is produced. Note that the stop value itself is never included in the list, giving a half-open interval.

range(0, 5, 1)   = [0, 1, 2, 3, 4]
range(0, -5, -1) = [0, -1, -2, -3, -4]
range(0, 2, -1)  = []
range(0, -2, 1)  = []
range(3, 4, 10)  = [3, 7]
range(3, 4, 11)  = [3, 7]
range(3, 4, 12)  = [3, 7, 11]
range(1, -2, 0)  = [1]


*In Python 3, it actually makes a range object, but that doesn't matter here.

Test cases

Note that there can be multiple valid inputs. Different stop values can cut off the result at the same point when the step is not ±1. A singleton or empty list can be produced in many ways.

TODO

• Is this return {a[0], a[-1]+sign(a[1]-a[0]), a[1]-a[0]}? – my pronoun is monicareinstate May 7 at 15:43
• @mypronounismonicareinstate I think that works for inputs with 2+ elements, though the empty list and singleton list also need to be handled. Is this too simple for a challenge? – xnor May 7 at 19:32
• (I just noticed this might work in languages with modular indexing) This is probably not too simple, and I like the idea, but it seems like most of the complexity here comes from these special cases. – my pronoun is monicareinstate May 8 at 2:46

# Arithmetic Square code-golfgridarithmetic

Note: Credit goes to CCC 2019 S3 for the problem

You are given a $$\ 3 \times 3 \$$ grid which contains integers. Some of the $$\ 9 \$$ elements in the grid already have a value, and some of them remain unknown.

Your task is to fill in values for the unknown elements such that for each row, when read left-to-right, produces an arithmetic sequence, and that for each column, when read top-to-bottom, is also an arithmetic sequence.

Recall that an arithmetic sequence of length $$\ 3 \$$ is a sequence of integers in the form

$$a, a + d, a + 2d$$

for integer values of $$\ a \$$ and $$\ d \$$. Note that $$\ d \$$ may be any integer, including zero and negatives.

## Input Specification

• You may input the $$\ 3 \times 3 \$$ grid in any sensible format
• The unknown values may be represented by any character, so long that it is not a number (i.e. $$\ 0-9 \$$)

## Output Specification

• The output must be in the same format as the input, with the exception of unknown values becoming integers
• All rows and columns must form arithmetic sequences
• There is guaranteed to be at least one solution, and you may output any of them

## Test Cases

(This is the only solution)
8  9 10       8  9 10
16  X 20  ->  16 18 20
24  X 30      24 27 30

(This is one of many solutions)
14  X  X      14 20 26
X  X 18  ->  18 18 18
X 16  X      22 16 10

(This is the only solution)
X -1 -2       0 -1 -2
5  X  3  ->   5  4  3
X  X  X      10  9  8

(This is one of many solutions)
X  X  X       0  0  0
X  X  X  ->   0  0  0
X  X  X       0  0  0


This is , so the shortest code in bytes wins!

## Generate a "Poem" code-golfstring

Given a strictly positive integer, N, produce an output satisfying the following:

• Produce an array of length N.
• Every string (i.e. "word") in the array is of length N.
• Every letter in the word is unique.
• Every first letter of the words are unique between each other.
• The remaining items of each word are equal to each other.

## Example output

For an input of e.g. 3:

cba
dba
eba


## Specification

• Trailing whitespace is totally allowed.
• The "letters" don't have to be from the lowercase alphabet, as long as they aren't whitespace.
• The maximum N you need to support is 13, since there are 26 letters in the lowercase alphabet.
• The separator of your array can be anything, as long as you will never involve that character for every possible input from 1 to 13. You can also just output a literal array.
• is there a maximum N we need to support? – Lyxal May 12 at 0:56
• Yes, the maximum N here is 13. – Member for 3 months May 15 at 10:15

# Is this a Freeman Dyson Number?

Background

From this Popular Mechanics article

One day, in a gathering of top scientists, one of them wondered out loud whether there exists an integer that you could exactly double by moving its last digit to its front. For instance, 265 would satisfy this if 526 were its exact double – which it isn’t. After apparently just five seconds, Dyson responded, “Of course there is, but the smallest such number has 18 digits.”

Challenge Write a program that, when given a base ten number that is at least 18 digits long, moves the last digit to the front and checks if it is doubled as a result.

I/O
Input can be any 18 (or longer) digit integer. Any leading digit must be larger than zero.

Output
The original number with the Dyson transform (last digit moved to the front) and any truthy/falsey value (if that's a digit, it must have a delimiter).

Test Cases/Sample I/O

111111111111111111 -> 111111111111111111,false
100000000000000002 -> 210000000000000000 **F**
123456789123456789 -> [912345678912345678,0]
42105263157894736842 -> 24210526315789473684👎
808080808080808080808080808016 - 680808080808080808080808080801-NO
246802468024680246802468024680246802 -> false224680246802468024680246802468024680
105263157894736842 -> true,210526315789473684
315789473684210526 -> (T:5315789473684210526)
26315789473684210526315789473684210 -> 52631578947368421052631578947368421👍

etc...


, so shortest answer in bytes (by language) wins.

• I would specify that you are talking about decimal digits. – Jonathan Frech Mar 22 at 17:46
• @JonathanFrech, Do you mean base 10? – ouflak Mar 22 at 19:32
• I think one issue here is how to verify that the specific action of moving the digit from back-to-front, and then subsequently checking for doubling, actually happened. Not sure how to get around that. – ouflak Mar 22 at 20:10
• Yes, you should specify that this is in base 10. – S.S. Anne Mar 22 at 20:46
• @ouflak Yes, I mean base ten. One often hears for example "binary digits", so the term "digits" is in my opinion not clearly defined to mean base ten. – Jonathan Frech Mar 22 at 21:55
• @JonathanFrech, @ S.S. Anne, The reason why I haven't immediately made the change is because I hadn't considered the idea of different number bases, and I'm really liking the idea of a challenge that in fact does include either various number bases, or a specific challenge for binary and this separate challenge for base ten. Mulling it over now. This would mean I'd have to figure out some binary test cases.... – ouflak Mar 23 at 6:44
• In binary doubling a number is adding 0 to the end of it, so unless you allow leading 0s it's not possible, otherwise it's correct iff the number starts with a 0 – Command Master Mar 24 at 19:43
• @CommandMaster, Yes! For binary, you would have to allow, even implicitly, a leading zero. The most obvious example is '1', which is really '01', which when the '1' is moved to the front becomes '10'. Don't see how you can get around that. It would be a different challenge. The number base thing has got me thinking. – ouflak Mar 25 at 8:35
• Here are some suggestions: Make it a decision-problem (e.g. returning the Dyson transform and the Truthy/Falsey value is a bit unnecessary). Keep the sample IO consistent (I get that you want to show the variation in possible output formats, but it would be easier to verify cases if the format were consistent). – dingledooper May 12 at 19:55

## Posted

Tile the plane with squashed hexagons

There are $$\a\$$ honest man(always tell the truth), $$\b\$$ dishonest man(always tell lie), and $$\c\$$ random man(tell random Y/N). How many times at least should you ask one of them a yes/no question to guarantee you get knowledge of who they are? You may assume that it's possible.

Test cases:

(a,b,c) -> ans
(1,1,0) -> 1
(1,1,1) -> 3
(0,0,2) -> 0


Notes:

• I don't know if there's clever way, but anyway brute-force work
• Actually it's possible to identify them iff there are less than half of random answerer, or an edge case that all are random answerers. Only considering honest and random, if there are more honest than random, ask them same question and do a majority vote gets answer to the question. If there are same honest and random, and random tell as if they are honest and real honest are random, you can't tell the difference.
• I think the wording is a little confusing. Will there always be one of each? Will your program be given a list of a, b, and cs as input? Also, you may want to look at this question to check if it's similar to yours. – Redwolf Programs May 14 at 21:23
• @RedwolfPrograms Yes a,b,c are given, and possibly zero. Link don't match this problem well – l4m2 May 15 at 2:48
• Wouldn't it require at least 4 questions for the test case (1, 1, 1)? How to solve in 3? – user202729 May 16 at 3:46
• @user202729 brainden.com/forum/topic/… (not wiki answer as it assume answer from random is either true or false) – l4m2 May 16 at 3:47
• Oh wiki also has a standard solution – l4m2 May 16 at 3:53
• – user202729 May 16 at 4:48

## Compress a grandmaster chess position code-challengetest-battery

Background

Compress a position from a grandmaster chess game to as few bits as possible on average. A strong submission will probably use that these positions come from real games by top players, and so will make chess sense and strategic sense, rather than just being random legal chess positions. As illustration, a study found that grandmasters do well at memorizing positions from real games using "chunking" but with only perform at novice level memorizing random boards.

The is related to but different from Smallest chess board compression, which scores on the worst-case scenario, and Smallest chess game compression, which compresses full games. (Sandbox: Let me know if this is too similar)

You must write a compressor, which maps a chess position onto a sequence of bits, and a decompressor that returns its to the original position. You can vary the length of the bit sequence by position, and this will likely be important to getting a good score.

The position to compress will just be a the placement of pieces on the chess board. You do not to encode whose move it is, castling rights, or en-passant. It will be given in FEN string format with only the piece placement part, for example:

2krn2r/pppb4/4pq2/3pN2p/5P2/2PBP3/PP4P1/R2QK2R


Each letter corresponds to a piece (pawn="P", knight="N", bishop="B", rook="R", queen="Q", and king="K"). White's pieces use uppercase letters and Black's are lowercase. Slashes separate the descriptions of each of the rows from top to bottom, that is the 8 files doing from 8 (where black's pieces start) to down to 1. Numbers are used for blocks of that many empty spaces that are horizontally adjacent.

Scoring

You will be scored on the average length of your compressed bit sequence on 10,000 random game positions. They will chosen at random from games played by grandmasters, restricted to move 5 or later. [Will work out more details when generating this data.]

This Pastebin (TODO) contains 10,000 FEN strings to use as a training set that you can use to get a preliminary score. The final score will be based on a separate secret test set of 10,000 FEN strings.

Your code must correctly decode every game in the position. Be sure that it can handle all positions, such as ones with weird underpromotions, which might appear in the test set but not the training set. (Sandbox: How to handle submissions that break this? A default penalty score for games failed? Ask to resubmit?)

Your compression and decompression must complete within 5 minutes on all the games. (Sandbox: Allow to compress all games at once? Do one game at a time but store state to allow "learning"? Include a memory limit?)

The length of your code is immaterial to this challenge.

• How long (in number of positions) would a naive program that hardcodes all of the (recorded) existing grandmasters games be? (if that's not large enough, it would make the challenge trivial) – user202729 May 17 at 11:49
• @user202729 That's a good question, I definitely don't want code to be use that the test set comes from an actual database, so I'd either needed to make that non-viable or ban it. – xnor May 17 at 12:31
• Does the time requirement have to be as strict as 30 games per second? (a certain question of the part also mentions "every game in the position", I assume that's a mistake) (I have no idea how to prevent storing a database of grandmaster games though) – my pronoun is monicareinstate May 17 at 16:00
• @myp I think that this requirement means that it can compress each game in 5 minutes. – user202729 May 18 at 0:50
• @user202729 I had meant total for all the games, but I'll probably loosen it. – xnor May 18 at 2:19

## Permutation primes code-golfdecision-problempermutationsprime

A permutation prime is a prime such that at least one of its uniquified permutations (not equal to itself) of its digits is a prime.

Given a number, check if this number is a permutation prime.

## Reference program

Here is a reference program I made.

# The golfing skills are strong with this one code-golfstring

Consider the base string s = "The golfing skills are strong with this one", an adaptation of the quote "The force is strong with this one" by Darth Vader, an infamous character of the Star Wars saga (sandbox, am I correct?).

You have to output the string s with as many characters as there are bytes in your source code. If your code is longer than s, extend s by concatenating it repeatedly as many times as needed.

# Input

You may or may not take the string s as input for your program. (Sandbox, maybe it is more interesting to not allow the string as input?)

# Output

A string as specified in the Task.

• Many languages, 0 bytes. PHP and /// polyglot, 1 byte: T. If the code is too long, is the string really intended to be The golfing skills are strong with this oneThe golfing skills are strong with this oneThe golfing skills are strong with this one? – my pronoun is monicareinstate May 20 at 16:42
• @mypronounismonicareinstate do you see a problem with the string being like that? What would you suggest? Also, probably should not allow the string to be used as input and require a non-empty program – RGS May 20 at 16:46
• That is perfectly acceptable, it's just that the transitions aren't very smooth (oneThe). If you can take the string as input, solutions won't have to depend on this specific string, so it would probably be a bad idea. (I mean, a[:5] isn't a very interesting answer) – my pronoun is monicareinstate May 20 at 16:51
• @mypronounismonicareinstate I failed to understand what variation you think is a bad idea. Do you think it is a bad idea to accept it as input or a bad idea to not accept it as input? – RGS May 20 at 16:52
• I think it is a bad idea to accept it as input. – my pronoun is monicareinstate May 20 at 16:53

# Halting problem for simplified Brainfuck code-golfdecision-problem

Given a simplified Brainfuck program, you must determine whether it halts. Your program must always halt in finite time on valid inputs.

Simplified Brainfuck is a language that operates on a zero-initialized tape that is infinite in both directions. All cells contain integers from 0 to 255, and operations are performed modulo 256. There are the following instructions:

+ increment the current cell
- decrement the current cell
< move 1 cell to the left along the tape
> move 1 cell to the right along the tape
[ if the current cell is zero, skip past the next ]
] go to the previous [


Loops ([]) can't be nested.

This is tagged , so the shortest answer wins.

• Do you mean "Given a simplified Brainfuck program and an input of such program"? – Domenico Modica May 21 at 5:00
• @DomenicoModica No, this language has no IO. Do you think I should mention that explicitly? – my pronoun is monicareinstate May 21 at 5:02
• Oh, I don't know, I was too hasty ahahah... Anyway If the tape was finite surely it would be solvable – Domenico Modica May 21 at 5:07
• I think it is indeed solvable with doubly infinite tape, since the region that the pointer touches within an iteration of a loop is limited (which means we have finite number of states in that region). It's pretty hard to describe the algorithm though. – Bubbler May 21 at 5:56
• That is what I had in mind. Handling two loops in different directions is also non-trivial. – my pronoun is monicareinstate May 21 at 6:00
• I don't think handling multiple loops is that non-trivial. Consider first loop first, the answer is false if it is infinite loop, otherwise run it to the end and run all commands before the second loop. Then consider the second loop just like the first, etc. – Bubbler May 21 at 6:49
• Actually I think the challenge is not very interesting as[code-golf], because it's necessary to simulate the algorithm anyway and it can be proven (I think) that the number of steps the program takes (if it halts) is no more than $2^{2^{2^{2^n}}}$ (where n is the program length), so it will be no longer than an interpreter but takes impractically long to run. – user202729 May 22 at 8:48
• @user202729 Is there proof of an upper bound of time? I feel it's unsolvable – l4m2 May 27 at 1:38
• @l4m2 This is solvable because loops can't be nested. The body of each loops moves by a constant number of steps X, and if the program doesn't halt than it'll either repeat the same state twice (if X==0) or crosses the bound of the written tape part (because there's only a fixed number of written cells and then repeat states (there's only a finite number of cells touched by the loop body) – user202729 May 27 at 4:07
• What happens if the specified table doesn't exist? – Lyxal May 15 at 4:37
• The usual SQL statement is SELECT * FROM data, where * is the wildcard operator. Also, the set of parentheses after "WHERE" is not mandatory in usual SQL. I guess these changes make the challenge easier to parse. – Member for 3 months May 15 at 4:56
• @Λ̸̸ Yeah, it's to make it slightly easier. However, I could change it. Which I will! – bigyihsuan May 15 at 23:54
• @Lyxal undefined, the programs should assume that the table is in the database – bigyihsuan May 15 at 23:55
• Consider deleting this post, as the challenge is already on main – RGS May 20 at 16:50

Posted: Stepping Through Time

# Quickly calculate $$\ n! \bmod p \$$fastest-codefactorial

The idea is extremely simple: Given two positive integers $$\ n \$$ and $$\ p \$$, calculate the result of $$\ n! \bmod p \$$, where $$\ p \$$ is a prime.

## Scoring

Your score is the highest $$\ p \$$ you can achieve within $$\ 10 \$$ seconds, by running the program $$\ 10 \$$ separate times. More specifically, each run-through will contain two inputs $$\ n \$$ and $$\ p \$$. You are to solve $$\ n! \bmod p \$$, where $$\ n \$$ is a random number in the range $$\[1, p]\$$.

You must use this program to generate the $$\ 10 \$$ test cases. So for example, if $$\ p = 13 \$$, the test case would look like this:

n, p
9, 13
3, 13
10, 13
13, 13
7, 13
13, 13
8, 13
9, 13
6, 13
4, 13


## Rules

• Make sure that each test case is run separately, meaning you are not allowed to make use of previous test cases
• Official times will be tested on my machine; make sure to include specifcations on how to run it

This is , so the highest score wins!

## Sandbox

• Any loopholes that need to be addressed?
• Is there an easy, trivial solution to this?
• To force independent calculation you should invoke the program 10 separate times. Although it remains possible to store data in files or similar, it would be pretty obvious. – user202729 May 22 at 8:58
• As far as I know the best-known time complexity is asymptotically $\widetilde O (\sqrt p)$, although the implementation is rather tedious and uninteresting. – user202729 May 22 at 9:00
• Your example test case has p=10 which isn't prime – xnor May 22 at 10:31
• @xnor Fixed, thanks. – dingledooper May 22 at 15:53

# Shorten the numbers

These numbers are taking up far too many bytes on my computer. Create a function/program to shorten any number using only Alphanumeric characters as the output.

# Scoring

Scoring is based on optimized-output. Shortest number of characters produced for the following randomly generated numbers (plus one special number with repetition) wins. Add the number of output characters output for the 5 test numbers together for total score.

• 94949267912781
• 75477115147709
• 79547324913976
• 12345678998765
• 11111122222222

The score of the non-optimized numbers = 70. (14 * 5)

# Sandbox questions

• does scoring make sense?
• should I include a sample script, output, or both?
• should I be more clear the answers should work on any number? (ie. "replacing each test number with one character is disallowed")?
• Base conversion from base 10 to base-255? – Member for 3 months May 23 at 8:29
• As long as you're scoring on those five test numbers, the winning score is going to be the absolute smallest thing you haven't explicitly forbidden. Not allowing solutions to be tailored to those five is what we'd call a non-observable requirement, and considering how many different ways it could be approached I'm not sure how well a human could even really try to judge it. On the other hand, if you try to score it over the natural numbers, we just do base conversion. I feel like this can't work as an output optimization challenge. – Unrelated String May 23 at 10:07

Inspired by Wizard creating a jewelry.

Given an input list of positive integers, calculate the minimum cost of creating the list from the following operations:

1. Appending a positive integer costs the value of the integer.
2. Incrementing the entire list costs 2.
3. Exchanging two consecutive elements of the list costs 1.

Example: The list 1 4 9 16 25 could be constructed as follows:

• Append 1
• Append 8
• Append 17
• Increment
• Increment
• Increment
• Increment
• Increment
• Append 1
• Swap 22 with 1
• Swap 13 with 1
• Swap 6 with 1
• Increment
• Increment
• Increment
• Append 1
• Swap 25 with 1
• Swap 16 with 1
• Swap 9 with 1
• Swap 4 with 1

This costs 51, which is an improvement over simply appending the integers, as that is a cost of 54.

This is , so the shortest program or function that breaks no standard loopholes wins!

• Seems clear, but another test case or two might be helpful. – Dingus May 29 at 7:32

# Cheat activated

### Background

The game Grand Theft Auto: San Andreas went down to history also thanks to its wide selection of cheats. They're almost 90 and anyone who has ever touched this game, no doubt he tried them all!
One cheat is activated (on PC) typing in-game a secret keyword, and then boom, a jet pops out of thin air or perhaps all pedestrians look like Elvis Presley or some other rowdy effect...

They always come with this confirmation message:

Rockstar choosed to store them hashed, so due to collision, in addition to the intended ones there are many other strings that trigger every cheat.

Therefore I propose to solve this downside!

Write a full program that prints CHEAT ACTIVATED if and only if the last part of a string is a cheat code.

## Cheat codes

THUGSARMOURY
PROFESSIONALSKIT
NUTTERSTOYS
INEEDSOMEHELP
TURNUPTHEHEAT
TURNDOWNTHEHEAT
PLEASANTLYWARM
TOODAMNHOT
DULLDULLDAY
STAYINANDWATCHTV
CANTSEEWHEREIMGOING
TIMEJUSTFLIESBY
SPEEDITUP
SLOWITDOWN
ROUGHNEIGHBOURHOOD
STOPPICKINGONME
SURROUNDEDBYNUTTERS
TIMETOKICKASS
OLDSPEEDDEMON
DOUGHNUTHANDICAP
JUSTTRYANDSTOPME
WHERESTHEFUNERAL
CELEBRITYSTATUS
TRUEGRIME
ALLCARSGOBOOM
STICKLIKEGLUE
GOODBYECRUELWORLD
DONTTRYANDSTOPME
ALLDRIVERSARECRIMINALS
PINKISTHENEWCOOL
SOLONGASITSBLACK
FLYINGFISH
WHOATEALLTHEPIES
BUFFMEUP
LEANANDMEAN
BLUESUEDESHOES
ATTACKOFTHEVILLAGEPEOPLE
LIFESABEACH
ONLYHOMIESALLOWED
BETTERSTAYINDOORS
NINJATOWN
LOVECONQUERSALL
EVERYONEISPOOR
EVERYONEISRICH
CHITTYCHITTYBANGBANG
CJPHONEHOME
JUMPJET
IWANTTOHOVER
TOUCHMYCARYOUDIE
SPEEDFREAK
BUBBLECARS
NIGHTPROWLER
DONTBRINGONTHENIGHT
SCOTTISHSUMMER
SANDINMYEARS
KANGAROO
NOONECANHURTME
MANFROMATLANTIS
LETSGOBASEJUMPING
ROCKETMAN
BRINGITON
STINGLIKEABEE
IAMNEVERHUNGRY
STATEOFEMERGENCY
CRAZYTOWN
TAKEACHILLPILL
FULLCLIP
GHOSTTOWN
HICKSVILLE
WANNABEINMYGANG
NOONECANSTOPUS
ROCKETMAYHEM
WORSHIPME
ICANGOALLNIGHT
PROFESSIONALKILLER
NATURALTALENT
OHDUDE
FOURWHEELFUN
ITSALLBULL
FLYINGTOSTUNT
MONSTERMASH


## Input

• A string $$\s\$$ over the alphabet:
[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]

# Output

• Print CHEAT ACTIVATED if there exist a cheat code $$\c\$$ such that $$\c\$$ is a suffix of $$\s\$$
• Nothing otherwise

This is , so the shortest code wins.

• Do we have to output the specific Cheat activated string, or just a truthy/falsy value indicating whether or not a valid cheat code exists? (I also don't think $i$ is a good name for a string; is that intentional?) – my pronoun is monicareinstate May 21 at 4:27
• @my pronoun is monicareinstate Yes, that specific string, it's a little simulation. And yes, you're right $s$ is the canonical name, I choose "i" for input, but never mind – Domenico Modica May 21 at 4:39
• I think that restricting the output to Cheat activated is unnecessary since it doesn't really add anything to the challenge. Consider allowing just a truthy or falsey value as output. – math junkie May 21 at 19:01
• @math junkie I'm aware that in terms of logic it's useless. But that comes if only the "recognition part" is considered being the intended challenge. From my idea, generating Cheat activated it's also a part of it... I worded it badly in the task part – Domenico Modica May 21 at 20:08
• 18HOLES is in the cheat codes list, yet the input states that there will be no number. Is this intended? – dingledooper May 22 at 21:20
• @dingledooper No, my mistake, I thought I had removed it in the last edit – Domenico Modica May 22 at 23:07

# Convert an integer to Chinese numerals

Your task is to convert an integer from 1 to $$\10^{52}-1\$$ (inclusive).

The characters from 1 to 10 with their Unicode code points are:

一 1 U+4E00



Number greater that that are composed like this:

十一 11

...

...

...

...

...

...



This is where it gets interesting, because numbers bigger than 10,000 are groups in groups of four, expressed with 十, 百 and 千. These are the powers we're going to use in this challenge:

十 10 U+5341



Let's go through an example with 123456789123456789 as the input (other algorithms are possible)

• identify groups of four digits, starting from the right: 12,3456,7891,2345,6789
• convert each group: 十二 三千四百五十六 七千八百九十一 二千三百四十五 六千七百八十九
• insert the appropriate multipliers: 十二京三千四百五十六兆七千八百九十一億二千三百四十五万六千七百八十九

## Notes

• A leading ー MAY be dropped before 千 and 百 and MUST be dropped before 十.

## IO format

The input can be an integer in any reasonable format. You can use a string/sequence of characters or a number type, if your language supports it. 128-bit numbers are not large enough, by the way.

## Testcases

input output
1 一
2 二
3 三
4 四
5 五
6 六
7 七
8 八
9 九
10 十
15 十五
20 二十
31 三十一
100 百
123　百二十一
1000 千
8346 八千三百四十六
10000 一万
50010 五万十
100000 十万
123456789123456789　十二京三千四百五十六兆七千八百九十一億二千三百四十五万六千七百八十九
1234567891234567891234567891234567891234567891234567 一千二百三十四極五千六百七十八載九千百二十三正四千五百六十七澗八千九百十二溝三千四百五十六穣七千八百九十一禾予二千三百四十五垓六千七百八十九京一千二百三十四兆五千六百七十八億九千百二十三万四千五百六十七


Standard code-golf rules apply. The shortest code in bytes wins.

## References

• I assume this is meant to be code-golf? While the tag is technically enough, I think it is better to have a brief inclusion of that in the body of the challenge. – FryAmTheEggman May 29 at 18:44
• @FryAmTheEggman yes it should be codegolf. – corvus_192 May 29 at 19:41
• It'd be helpful if you include the code points for the Unicode characters. – Surculose Sputum May 29 at 21:13
• As someone who is actively learning Japanese, they're called Chinese numerals because they were taken from China's numeral system. Japanese numerals are a whole different, extremely complicated thing. – Ethan Slota May 29 at 21:51
• "A leading ー MAY be dropped before 千 and 百". They MUST be dropped in Sino-Korean numerals, tho. – Dannyu NDos Jun 1 at 4:07
• What about 恒河沙, 阿僧祇, 那由他, 不可思議, and 無量大數? – Dannyu NDos Jun 1 at 4:12
• Mathematica has IntererName[#, "Words", Language -> "Chinese"]&, but, unfortunately, it can't handle numbers this large :(. – my pronoun is monicareinstate Jun 2 at 11:55
• Can we take input in base 10000? (Usually done when doing big integer multiplication with int32 so seems somehow reasonable) – l4m2 Jun 19 at 4:26

# The smallest positive integer that cannot be printed in fewer than %NUMBER% bytes of %LANGUAGE% code-challenge

All numbers mentioned below are positive integers. All programs mentioned below output exactly 1 number (including functions that return it).

For every number, there must be at least one program in your language that outputs it. Besides, the problem of determining what number the program outputs must be undecidable without making the assumption that the program halts.

The challenge itself is to choose a number $$\N\$$ and find the smallest number $$\M\$$ that cannot be output by a program shorter than $$\N\$$ ordinary units of measurement used for your language (usually bytes). You have to prove your solution correct. A strong mathematical proof is not necessary, but it should be reasonably convincing for somebody knowledgeable in your programming language.

The answer with the largest $$\M\$$ wins.

# Sandbox stuff

• In this challenge, non-golfing languages seem to have a serious advantage. I think scoring by $$\M\$$ instead of $$\N\$$ is better at reducing the advantage of Lenguage-like languages to manageable levels and preventing ties; is that correct?
• Is the tag appropriate?
• Title suggestions?
• I feel like I misunderstand. Let's say print M (where M is a normal base 10 integer) is the only valid way to output integers in my language. I take $N=7$, then $M=1$. What's to stop me repeatedly increasing $N$ by 1 and adding a zero on to $M$ each time? – Dingus May 28 at 2:23
• @Dingus I used to have a complicated rule to prevent exactly this; I'll try to think of a simpler one. – my pronoun is monicareinstate May 28 at 2:35
• I'm worried that the proof will just be an exhaustive search for most language, as $M$ has to be the smallest number. Alternatively, we could make $M$ a lower bound of the smallest value, and score a solution based on both $M$ and $N$. Another way is to flip this challenge to find the largest printable number in $N$ bytes, but that has already been done here and here. – Surculose Sputum May 29 at 15:18
• @Dingus I think you will have to stop when you can't prove whether whatever precedes print M halts or doesn't halt. I still think this is too cheap a way to get a high-scoring answer, but I am not sure how to formalize things better. – my pronoun is monicareinstate Jun 2 at 16:01
• @mypronounismonicareinstate I think my question is probably not relevant. I overlooked a critical condition - 'the problem of determining what number the program outputs must be undecidable without making the assumption that the program halts'. – Dingus Jun 4 at 0:18
• I'm worried that some ridiculously large numbers will show up here. Also, as $N$ gets too large, maybe we will encounter problems like $M$ cannot be calculated assuming axioms of ZFC, what will happen then? – Trebor Jun 18 at 7:29
• @Trebor As far as I understand, each program either does output a number within finite time or doesn't output a number within finite time. If the program outputs a number, its result is known, and if it doesn't, the program is not valid because it doesn't output a number in finite time. Can you think of any particular way to obtain a ridiculously large number? – my pronoun is monicareinstate Jun 18 at 10:03
• A simple example is a program that enumerates all the valid proofs in ZFC and outputs the Godel encoding of the first proof it encounters of $A \wedge \neg A$. Since ZFC cannot prove its own consistency, it is not decidable in ZFC whether this program terminates. Worse still, if the program do terminate, ZFC cannot compute the return value either, because it is now inconsistent, rendering its deductions unreliable. – Trebor Jun 18 at 11:00
• @Trebor Halting and printing a single number is completely binary. Are you sure you are reading the challenge correctly? I'm asking not for the largest number that can be printed, but for the smallest number that can't be printed. – my pronoun is monicareinstate Jun 18 at 11:27
• @mypronounismonicareinstate Yes, that's why I'm "worried" instead of "sure". Also, these problems will not show up if we keep it small... – Trebor Jun 19 at 0:42