560
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

\$\endgroup\$
0

4329 Answers 4329

1
10 11
12
13 14
145
4
\$\begingroup\$

Demonstrate some advanced abstract algebra

\$\endgroup\$
10
  • \$\begingroup\$ I think we should be able to define the types and values of S, rather than necessarily using integers. In that case, - and + would not (necessarily) be actual arithmetic negation and addition, so maybe they would have to be renamed to use other symbols (or just use function syntax f(a,b)?) \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:50
  • \$\begingroup\$ And do all 9 functions have to operate on the same set S? I think it could be more interesting if they didn't have to, but it might result in cheating/loopholes. Also, what does "uniquely exhibits" mean exactly? Demonstrates exactly one of the 9 properties? \$\endgroup\$
    – pxeger
    May 31, 2021 at 8:52
  • \$\begingroup\$ In fact, I think people will just submit "addition, addition, multiplication, subtraction" for the first 4 at least, and I suspect they will almost always be the shortest option in most languages so it might not be very interesting as it is \$\endgroup\$
    – pxeger
    May 31, 2021 at 9:04
  • \$\begingroup\$ Writing one program is hard enough. Writing 9 seems like a lot to ask. I think you could make a stripped down challenge using just commutativity and associativity. I barely known any abstract algebra. I think these varieties are called magmas? \$\endgroup\$
    – qwr
    Jun 2, 2021 at 14:54
  • \$\begingroup\$ Is this even possible with the surjectivity condition? You should provide an example of each program. \$\endgroup\$
    – qwr
    Jun 2, 2021 at 14:57
  • \$\begingroup\$ @qwr I don't have examples for each program, and even if I did, I wouldn't include them as that would just lead to people porting them into their own languages. Yes, I believe magma is the correct term for \$*\$ here. I'm not sure if this is possible, but I'd be surprised if it isn't. I've allowed for an answer to be a proof of impossibility however, on that off-chance. \$\endgroup\$ Jun 2, 2021 at 15:04
  • \$\begingroup\$ Well it's more than a magma since you added more two more operators right \$\endgroup\$
    – qwr
    Jun 2, 2021 at 15:18
  • \$\begingroup\$ @qwr No, I believe a magma is just a pair, the binary operator and the set its closed on, no matter the additional operators defined on that set \$\endgroup\$ Jun 2, 2021 at 15:31
  • \$\begingroup\$ This is a really cool problem. It is hard so I wouldn't be again having a separate "easy" version with just the main three: commutative/associative/distributive. Uniquely exhibiting those is already a nontrivial and neat challenge. I don't know if others would vote a dupe, but I'd def be in favor of having both. As is, I don't think the harder version will have a lot activity. But I do think an easier one would! \$\endgroup\$
    – AviFS
    Jun 13, 2021 at 1:18
  • \$\begingroup\$ @AviFS I do actually have an easier version Sandboxed, where I think they're clearly separate enough to not be dupes. \$\endgroup\$ Jun 13, 2021 at 1:42
4
\$\begingroup\$

Minimal distinct character quine

\$\endgroup\$
3
  • \$\begingroup\$ This seems well specificed \$\endgroup\$ Jun 16, 2021 at 10:04
  • \$\begingroup\$ distinct means different? \$\endgroup\$
    – math scat
    Jun 19, 2021 at 10:01
  • \$\begingroup\$ @math Yes (filler) \$\endgroup\$
    – emanresu A
    Jun 19, 2021 at 10:30
4
\$\begingroup\$

Full name quine

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice question but seems hard \$\endgroup\$
    – math scat
    Jun 25, 2021 at 18:11
  • 1
    \$\begingroup\$ i assume custom SBCS languages will have to output the full names of their characters when represented in unicode? Or should they output the name of the visual representation? \$\endgroup\$
    – Razetime
    Jun 28, 2021 at 6:20
  • \$\begingroup\$ Full names represented in unicode. \$\endgroup\$
    – emanresu A
    Jun 28, 2021 at 8:29
4
\$\begingroup\$

r my Vyxal

\$\endgroup\$
6
  • \$\begingroup\$ Needs more test-cases. Also, in the explanation you use spaces as though they're ignored, but that isn't mentioned in the description of the task itself. I'd suggest just saying that "all other characters" will be limited to ASCII letters only, for example?. \$\endgroup\$
    – pxeger
    Jul 4, 2021 at 7:47
  • \$\begingroup\$ @pxeger In Vyxal, spaces are NOPs used to seperate stuff. In the subset I'm using, spaces are a function like everything else. I'll make that clearer, and add more testcases. \$\endgroup\$
    – emanresu A
    Jul 4, 2021 at 8:15
  • \$\begingroup\$ But I'm suggesting limiting the definition of what are functions to ASCII letters only to provide more golfing opportunities without having to handle edge cases that might occur because of spaces \$\endgroup\$
    – pxeger
    Jul 4, 2021 at 8:54
  • \$\begingroup\$ @pxeger Ok. (filler) \$\endgroup\$
    – emanresu A
    Jul 4, 2021 at 8:55
  • \$\begingroup\$ It says that we can assume there will always be two values to pop, but one of the testcases is simply “1”. Is that something that we will have to account for? \$\endgroup\$ Jul 4, 2021 at 15:09
  • \$\begingroup\$ @AaronMiller What I meant is, wherever there's a function, there will be two. I'll add that. \$\endgroup\$
    – emanresu A
    Jul 4, 2021 at 19:58
4
\$\begingroup\$

Fastest untyped lambda calculus evaluator

Challenge

What it says on the tin. Mainly because googling "fastest untyped lambda calculus" gives almost zero meaningful results.

Each submission is expected to take a lambda term from STDIN and print its normal form to STDOUT. The lambda term is represented using de Bruijn indexes, and we will use prefix notation for this challenge. Since a de Bruijn index may have multiple digits, each token will be separated by a single space. The input will have no surrounding whitespace, but you may output any amount of whitespace before and after the formatted lambda term.

LambdaChar = "\"             // single backslash
DeBruijnIndex = [1-9][0-9]*  // a positive integer
ApplyChar = "@"
Term = DeBruijnIndex | LambdaChar " " Term | ApplyChar " " Term " " Term

For example, \ \ @ 1 @ 2 1 represents lambda x. lambda y. y (x y).

The evaluation semantics to implement is normal order beta-reduction (no eta-reduction).

The test cases will be hand-crafted so that it takes significantly more time to evaluate the expression than to parse the input and format the output. Also, they will involve various kinds of Church- and Scott-encoded terms, so optimizing for any specifically encoded data (hopefully) has less effect than optimizing for general improvement. It is guaranteed that the test cases have a normal form and do not contain free variables.

Good starting points include this PEPM '17 paper and my Haskell implementation which was modified from the paper's algorithm to actually return the normal form. Other notable keywords: graph reduction, supercombinators, G-machine, TIGRE, STG (spineless tagless G-machine). Note that, if your submission has separate compilation and execution phases, both phases count towards the total execution time (which may negatively impact your score).

The submissions will be scored within WSL (Ubuntu 20.04) on my Windows 10 PC, which has Intel Core i7-6700 CPU (3.40GHz) and 8GB of RAM. The score is the sum of the timings measured for all the test cases. Lowest score wins.


Meta

  • Todo: write example and actual test cases.
  • Should I include a description about how the "normal order beta reduction" works for de Bruijn indexes?
\$\endgroup\$
2
  • \$\begingroup\$ are you planning to actually test with >9 levels of lambda nesting? \$\endgroup\$
    – ngn
    May 26, 2021 at 2:48
  • \$\begingroup\$ @ngn Depends on what I come up with. \$\endgroup\$
    – Bubbler
    May 26, 2021 at 3:04
4
\$\begingroup\$

Extremely small data compressor

In 2014 Jarek Duda at Purdue University wrote a paper containing several ideas for encoding computer data, entitled “Asymmetric numeral systems: entropy coding combining speed of Huffman coding with compression rate of arithmetic coding". The paper is available at Cornell University Library’s ArXiv project: https://arxiv.org/abs/1311.2540

One of the many fascinating things about this paper is that it begins by describing an extremely simple data compression algorithm, using the concept of the "Uniform asymmetric binary systems (uABS)". In fact, it is so simple, that you can implement it in only a few lines of code.

Basically it attempts to interpret a sequence of input symbols as a single Integer, and as each symbol comes in the Integer can be appended with new information. The trick is that the Integer is represented not using a place-value binary number system, but an alternative system. This representation is designed so that sequences of symbols which occur with higher probability will be represented by a smaller amount of space within the Integer's encoding.

Challenge

You will implement the simple uABS compression algorithm, so that given a sequence of 0s and 1s, your program will compress them into a (usually) smaller sequence of 0s and 1s.

Pseudocode

The algorithm in psuedocode is as follows:

  • Begin with an Integer X, and set it to 1. This will be the main Integer that we append during the algorithm.
  • The input data is a sequence of symbols, each 0 or 1, called Input
  • Find the probability P that any given symbol in Input is 1, (the number of 1s divided by the total number of symbols)
  • For each symbol S in Input, set X to the output of the function Encode(x,s,p)
  • After processing all the input symbols, output the final integer X. -- This encoded integer will hopefully have less bits than the input

The Encode function itself can be described as follows:

$$ Encode(x,s,p)= \left\{ \begin{array}{11} \mbox{if } s = 0 & \big\lceil\frac{x+1}{1-p}\big\rceil-1 \\ \mbox{if } s = 1 & \big\lfloor\frac{x}{p}\big\rfloor \end{array} \right. $$

Where

$$ \begin{array}{11} s \text{ is a symbol, either 0 or 1} \\ x \text{ is the Integer} \\ p \text{ is the probability that any symbol in the Input data is 1 } \\ \lceil \rceil \text{ is the mathematical ceiling function } \\ \lfloor \rfloor \text{ is the mathematical floor function } \end{array} $$

Notes

  • The input is a sequence of symbols, each symbol being 0 or 1, in any method that is available in your chosen language. Examples include a sequence of ascii characters '0' '1', an array of integers, etc.

  • The output will be a sequence of symbols in the same format as the input sequence. The output sequence represents the compressed version of the input data.

  • Empty input data has undefined behavior.

  • Input data containing only 0s has undefined behavior.

  • Sometimes the encoded Integer might have more bits than the input, not less. This typically happens when the number of 1s and 0s is relatively even. Data with an unbalanced number of 0s and 1s results in better compression.

  • You may assume that the size of Integer will be your language's largest integer type. The test cases outside this range can be ignored for your language.

  • Note that if you are trying to test this by 'decoding' or 'decompressing' the compressed data, and compare it to the original, one would have to store additional information, such as the length of input and probability P, but for simplicity this has been left out of the challenge.

Example Input and Output

Short examples:

Input             Output    
10                101
10010100000       1011101001
1111              1
11111111111       1
10000000          11011
10011111010101    10110000100101    

Longer examples:

Input  11111110110111110111111111011111
Output 11111000011110110

Input  000000000001000000010000000000001100000000001
Output 1110000101100111000011111

Input  000000000001000000010000000000001100000000001000000000000000000000000000000000000000000000000000000000000000001
Output 1010100110111110010111011110110101010

Scoring

  • The program with the fewest number of characters wins.
\$\endgroup\$
9
  • \$\begingroup\$ 1. IMO the pseudocode could be made clearer by firstly explaining what "machine integer" means (does it mean "unbounded integer" aka "big integer"?) and secondly golfing it a bit: using a "foreach" loop notation for S and eliminating the variable X'. 2. I think it would be helpful to be explicit about how p should be derived from the input. I presume that it means looping over the input twice, once to count and once to compress. 3. IMO restricting the input format to strings of ASCII 0 and 1 detracts from the core challenge. Why not allow arrays/lists of integers? \$\endgroup\$ Jul 7, 2018 at 12:13
  • \$\begingroup\$ Thanks, i have revised. \$\endgroup\$
    – don bright
    Jul 7, 2018 at 14:08
  • \$\begingroup\$ I really like this one. Something quasi-practical, and yet simple and small enough to be fun. Just to be clear, the output is the binary representation fo the integer X, without any leading zeros, correct? \$\endgroup\$
    – Sundar R
    Jul 8, 2018 at 19:02
  • \$\begingroup\$ Also, you mention "input size of at least 128 symbols", but it might be more important to specify output size limit, since many languages have hard bounds on maximum integer size. Since output size varies for the same input length, it might have to be something like "you may assume that the number of symbols in the output is less than or equal to the number of bits in your language's largest integer type". (The last test case would then be optional in languages that can handle only up to 32 bit integers). \$\endgroup\$
    – Sundar R
    Jul 8, 2018 at 19:12
  • \$\begingroup\$ yes the output is the binary representation of the final integer X, i believe the leading zeros is correct. do you think 32 bit is the good limit or 64, since modern machines tend to be 64 bit? thanks \$\endgroup\$
    – don bright
    Jul 8, 2018 at 20:05
  • \$\begingroup\$ 32 is probably a reasonable limit, one that most languages can handle without need for external libraries. \$\endgroup\$
    – Sundar R
    Jul 14, 2018 at 14:22
  • \$\begingroup\$ @sunar thanks, i have updated. \$\endgroup\$
    – don bright
    Dec 29, 2018 at 14:21
  • \$\begingroup\$ I assume the intent is for P to be calculated as # of '1' in the input / # of symbols in the input? That seems like it would match the definition given, but it would be helpful if it's described explicitly. \$\endgroup\$ Jan 3, 2019 at 22:24
  • \$\begingroup\$ Done, thanks.... \$\endgroup\$
    – don bright
    Jan 3, 2019 at 23:32
4
\$\begingroup\$

Converting Pinyin to Zhuyin or vice versa

Challenge

Pinyin and Zhuyin are systems that are used to help people pronounce characters in Mandarin Chinese. Write a function/program that converts Pinyin to Zhuyin or vice versa (clarify which one you are doing) according to the tables below. You are not required to deal with tones or incorrect inputs (including edge cases such as ḿ(呣), ǹg(嗯), and ê̄(诶/誒)).

Pinyin to Zhuyin

Pinyin Zhuyin
b
p
m
f
d
t
n (at the beginning)
l
g (at the beginning)
k
h (at the beginning)
j
q
x
zh (except in zhi)
zhi
ch (except in chi)
chi
sh (except in shi)
shi
r (at the beginning)
ri
z (except in zh, zi)
zi
c (except in ch, ci)
ci
s (except in sh, si)
si
a (at the end)
o (except in ao, ou, ong)
e (except in ei, en, eng, er, ie, ue, üe, ye)
e (only in ie, ue, üe, ye)
i (except in ai, ei, ui, iu, iong, yi, zhi, chi, shi, ri, zi, ci, si)
y (except in yong, yi)
yi
u (except in ou, iu, wu, ue and except after j, q, x, y)
w (except in wu)
wu
o (only in ong except in iong, yong)
u (right after j, q, x)
ü
yu
io
yo (only in yong)
ai
ei
i (only in ui)
ao
ou
u (only in iu)
an (except in ang)
ang
en (except in eng)
n (only in in, un except in ing)
eng
ng (only in ing, ong)
er

Zhuyin to Pinyin

Zhuyin Pinyin
b
p
m
f
d
t
n
l
g
k
h
j
q
x
ㄓ (by itself) zhi
ㄓ (not by itself) zh
ㄔ (by itself) chi
ㄔ (not by itself) ch
ㄕ (by itself) shi
ㄕ (not by itself) sh
ㄖ (by itself) ri
ㄖ (not by itself) r
ㄗ (by itself) zi
ㄗ (not by itself) z
ㄘ (by itself) ci
ㄘ (not by itself) c
ㄙ (by itself) si
ㄙ (not by itself) s
a
o
e
e
ㄧ (at the beginning, not by itself, and not before ㄣ, ㄥ) y
ㄧ (after ㄐ, ㄑ, ㄒ) i
ㄧ (by itself or before ㄣ, ㄥ and at the beginning) yi
ㄨ (not at the beginning) u
ㄨ (at the beginning except by itself) w
ㄨ (by itself) wu
ㄨ (before ㄥ and not at the beginning) o
ㄩ (after ㄐ, ㄑ, ㄒ) u
ㄩ (after ㄋ, ㄌ) ü
ㄩ (by itself or before ㄝ, ㄢ, ㄣ and at the beginning) yu
ㄩ (not at the beginning and before ㄥ) io
ㄩ (at the beginning and before ㄥ) yo
ai
ㄟ (not after ㄨ unless ㄨ is at the beginning) ei
ㄟ (after ㄨ unless ㄨ is at the beginning) i
ao
ㄡ (not after ㄧ unless ㄧ is at the beginning) ou
ㄡ (after ㄧ unless ㄧ is at the beginning) u
an
ang
ㄣ (not after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) en
ㄣ (after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) n
ㄥ (not after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) eng
ㄥ (after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) ng
er

This is code-golf, so the answer with the least bytes wins.

Test Cases

Pinyin Zhuyin
chuang ㄔㄨㄤ
xue ㄒㄩㄝ
diu ㄉㄧㄡ
juan ㄐㄩㄢ
ri
song ㄙㄨㄥ
ㄌㄩ
qiong ㄑㄩㄥ
zhen ㄓㄣ
huo ㄏㄨㄛ
ying ㄧㄥ

Additional test cases and information

\$\endgroup\$
7
  • \$\begingroup\$ Am I required to support single characters or a word / sentence? Also, there are some edge cases as I know, for example, ḿ(呣), ǹg(嗯), ê̄(诶/誒). Would these be excluded from testcases? May I assume no erhua (儿化/兒化) would be applied? \$\endgroup\$
    – tsh
    Oct 12, 2021 at 6:44
  • \$\begingroup\$ There are far more rules than testcases. I would suggest to add more testcases as many rules are not ever touched by any testcases here. \$\endgroup\$
    – tsh
    Oct 12, 2021 at 6:54
  • \$\begingroup\$ @tsh Single characters. The edge cases would not be required to check for as inputs. No erhua. I will try to add some more testcases to cover the other rules. \$\endgroup\$
    – Yousername
    Oct 12, 2021 at 11:19
  • \$\begingroup\$ Suggest a whole list, it's likely just 300+ possible inputs \$\endgroup\$
    – l4m2
    Oct 12, 2021 at 18:13
  • 1
    \$\begingroup\$ The number of rules makes this an intimidating task to write and golf. Consider limited to a simpler subset of rules or situations. \$\endgroup\$
    – xnor
    Oct 13, 2021 at 7:12
  • \$\begingroup\$ @xnor It's not actually as many rules as it looks like. A simple regex can be used for most of them. \$\endgroup\$
    – Yousername
    Oct 13, 2021 at 21:41
  • \$\begingroup\$ This is probably a lot harder to reason about for people not already familiar with mandarin and pinyin. \$\endgroup\$
    – qwr
    Jul 10, 2022 at 0:40
4
\$\begingroup\$

Play RPS with 3 bits of memory

This is a rough draft for now, the specifics, presentation and title will probably be adjusted

In this game you will be building bots to play rock paper scissors against each other. Of course rock paper scissors is not a very interesting game, just pick one of the three randomly. Can't get better than that?

The first thing here is that, we will play a slight variation on the game which introduces a small amount of strategy.

But more importantly in this version we will be designing very simple bots. Your bot will not be able to pick things randomly, nor will it be able to simulate complex strategies, because your bots will have 3 bits of working memory.

The game

Before we get into exactly how the bots will be made and what exactly it means to have only 3 bits of memory lets cover the game.

For each pair of bots we will play 48 rounds of RPS. In each round both bots will select a choice of Rock, Paper or Scissors. Rock beats scissors, paper beats rock and Scissors beats paper, if the two chose the same move they tie.

When you win you will receive points based on your play. If you win with scissors you get 1 point, if you win with paper you get 3 points, and if you win with rock you get 6 points. If you tie or lose you get 0 points.

Each bot will play every other bot and the bots will be scored on the number of points gained in total.

The bots

Your bot will have 3 bits of working memory, that means at any given time it will have stored a number between 0 and 7. To decide what to play it will know two things

  1. What it has in memory
  2. The last move it's opponent made

Given those it should spit out

  1. What move it wants to make
  2. 3-bits to write into memory

This is so simple you don't actually need to write "code" to represent your bot. Your bot is really just a \$8\times 3\$ lookup table, plus a single move which it will make as it's first move. (We can assume that the starting memory is 0 without loss of generality)

And in fact you will submit your bots in this format as it makes it easy to verify your bot works and doesn't cheat.


Sandbox

I like this challenge because it is

  1. Completely deterministic who wins, to the point where you can, for small bot pool work out with pen and paper the scores.
  2. It is basically language agnostic. No need to bother with JS.
  3. There's basically no way to cheat. It's going to be really hard to exploit a vulnerability in the handler when you can't run arbitrary code.

I am a little concerned though that there might not be a whole lot to do? I'm not sure how much better one bot really can be than others. Obviously you can always take 1 bot and design a bot which plays perfectly against it. But I'm not totally sure how much a carefully arranged bot is going to do better than ones that are just a pile of random connections.

Turning the memory size up could improve this but the larger you make it the more complex each bot gets, and I think the fun is really in being able to hand tune your bot.

However I don't know what I can do to find out other than just post this.

\$\endgroup\$
6
  • \$\begingroup\$ Seems bruteforceable \$\endgroup\$
    – pxeger
    Oct 17, 2021 at 18:40
  • 4
    \$\begingroup\$ This is a unique challenge, and I think you could post it. If it doesn't work out, then we'll all know not to do it again (or an improved version could be posted later). If it does work, CGCC'll have a new kind of challenge, which would be great. \$\endgroup\$
    – user
    Oct 17, 2021 at 18:57
  • \$\begingroup\$ @pxeger There are 1333735776850284124449081472843776 machines possible. Brute forcing that would probably mean playing every machine against every other machine. It may be solvable, but I don't think it is feasible to brute force it. \$\endgroup\$
    – Wheat Wizard Mod
    Oct 17, 2021 at 21:15
  • 1
    \$\begingroup\$ I'd prefer to have rigid I/O (fixed I/O method and format) for KotH purposes. Or you could just say "write down the 8x3+1 possible outputs in a specific format". The barrier to post some bot looks pretty low, so I'd expect a large number of answers in the worst(?) case which would require some kind of automated controller. \$\endgroup\$
    – Bubbler
    Oct 18, 2021 at 1:13
  • \$\begingroup\$ @WheatWitch ah, I misread the challenge \$\endgroup\$
    – pxeger
    Oct 18, 2021 at 6:59
  • 1
    \$\begingroup\$ @bubbler oh I absolutely will write a controller once the rules are nailed down a bit. Just because you can score this by hand does not mean it would not be very tedious \$\endgroup\$
    – Wheat Wizard Mod
    Oct 18, 2021 at 7:40
4
\$\begingroup\$

Remove submatrices

\$\endgroup\$
4
\$\begingroup\$

Solve the halting problem for ^/a*b*/b*a*/[ab]*$ in ///

///, a.k.a. Slashes is an esoteric programming language with simple two operations. One is to output its source to remove from it. The other is to substitute itself. The language is proven to be Turing-complete, so some programs such as /ab/bbaa/aab won't halt while some such as /ab/bbaa/ab will.

At first I questioned if halting problem for ^/[ab]*/[ab]*/[ab]*$ is solvable, but I learned unlikely.

So I am simplying to ^/a*b*/b*a*/[ab]*$.

Problem

Given a slashes program that matches ^/a*b*/b*a*/[ab]*$ in POSIX BRE (i.e. below), determine whether the program halts or not.

Format of program, if you are not familiar with POSIX BRE

program = "/" first "/" second "/" third
first = "" | first "a" | first first.b
first.b = "" | first.b "b"
second = "" | second "b" | second second.a
second.a = "" | second.a "a"
third = "" | third "a" | third "b"

Constrains

In this problem every program's length is up to 153.

Detailed rules

  • Can be either a full program or a function.
  • Standard i/o apply.
    • Examples of input format
      • a string of program
      • three strings p,q,r when the program is /p/q/r
      • integers p,q,r,s and a string t when the program is /a\{p\}b\{q\}/b\{r\}a\{s\}/t
      • entirely as an integer (think of it by yourself)
    • Examples of output format
  • Standard loopholes apply.
  • This is ; shortest code wins.

Examples

Testcase generator 1

My noncompetive solution

///: no
/a//: yes
/ab/bba/aab: yes
/ab/bba/aaab: yes
/ab/bba/aabb: no

Meta

  • Were similar things ever done before?
  • I am not even sure if this problem is solvable.
  • Just thought there are answers if I clarify maximum length of input.
  • Should I change the problem's genre to ? Would making a maximum length of the program be boring?
\$\endgroup\$
2
  • 1
    \$\begingroup\$ /// is turing-complete, so this is not possible \$\endgroup\$
    – pxeger
    Apr 25, 2021 at 12:33
  • \$\begingroup\$ Should we simplify it more? \$\endgroup\$
    – user100411
    Apr 25, 2021 at 20:23
4
\$\begingroup\$

Implement a BrainFlump interpreter

BrainFlump is the latest alternate memory model brainfuck-esque turing tarpit.

It operates on a memory model we call a "Dump", which is simply an un-ordered collection of integers, with a pointer indicating the current item to operate on. As it is "unordered", when moving to the next item, one is simply chosen at random (chosen uniformly between the items that are not the currently selected item) and the operation pointer is moved to that item.

Commands

+   #Increment the item at the pointer
-   #Decrement the item at the pointer
:   #Add a 0 to the dump, and move the pointer to it
;   #Move the pointer to a random item that is not the pointer's current position
(   #Skip to the matching ) if the item at the pointer is 0
)   #Skip to the matching ( if the item at the pointer is not 0
,   #Read a single character from STDIN and push its ascii value to the dump
    #This also moves the pointer to the new item
.   #Print the current item at the pointer modulo 127 as an ASCII character

Other notes

  • When the ; command is used if the dump contains only 1 item, a new 0 is pushed to the dump, and the pointer is moved to it
  • The . command does not pop the item from the dump
  • When the , command is used if STDIN has been exhausted, a new 0 is pushed to the dump, and the pointer is moved to it
  • Any item in the dump who's value is 0 is not considered to exist, unless it is the item at the pointer, therefore to "pop" an item from the dump, you simply set its value to 0
  • Nested loops are supported
  • The random number generator used for the interpreter does not have to be cryptographically secure, but must chose with uniformity.
  • BrainFlump does not support floating point numbers or negative integers. Attempting to decrement a number below 0 has no effect.
  • The maximum value of an item in the dump is 255

Examples/Testcases

brainf**k emulation

++++++(;++++++++;-);.

This should output 0

Explanation

++++++        #Increment the first item to 6
(             #While the item under the pointer is not 0
    ;         #Move to another item in the dump
              #    Note the first time this loop runs,
              #    this will insert a new item
    ++++++++  #Increment the new item by 8
    ;         #Switch to another item in the dump
              #    Note there are only 2 items currently,
              #    So this will switch to the only other
              #    item, the one we initially incremented to 6
    -         #Decrement the item
)             #Repeat the loop if the item is not 0
;             #Switch to the other item
              #    Note this switches the pointer back to
              #    The item we have been incrementing by
              #    8 each loop
.             #Output as ASCII character

This is effectively a 6*8 operation, followed by an output, and is nearly identical to brainf**k's ++++++[>++++++++<-]>. program, which also outputs 0.

Note, however, that brainf**k-esque dump manipulation is only deterministically possible if there are never more than 2 items in the dump.

Random output

+:++:+++:++++:+++++:;.

This will actually always output an unprintable character, however which character is output will be random each time, selected from: SOH, STX, EST, EOT, ENQ, ie ASCII characters 1-5. In a correctly implemented interpreter, this output should be uniformly random between the 5 possibilities.

Explanation

+      #Increment first item to 1
:      #Add new item and move to it
++     #Increment new item to 2
:      #Add new item and move to it
+++    #Increment new item to 3
:      #Add new item and move to it
++++   #Increment new item to 4
:      #Add new item and move to it
+++++  #Increment new item to 5
:      #Add new item and move to it
       #    Note this last item is added because ; will
       #    always switch to an item that is *not* the
       #    currently selected item
;      #Switch randomly to an item in the dump
.      #Output as ASCII character

To give a little more info on this, by the time the ; command is reached, the dump should look like this:

1 2 3 4 5 0
          ^

As ; always switches to a different item, the result will be the pointer at one of the non-zero items.

cat

,(.,)

Nice and simple, and identical to brainf**k's cat program.

For scoring purposes, you should use this gist as input when testing.

When will it end?

++++(,:+++++;++(;++++++;--):++++;---)

This program doesn't output anything, but runs for a non-deterministic amount of time.

Explanation

++++             #Increment first item to 4
(                #Start loop
    ,            #Read char from STDIN to new item in dump
    :+++++       #Push 5 to dump
    ;++          #Switch to random item in dump and add 2
    (            #Start loop
        ;++++++  #Switch to random item in dump and add 6
        ;--      #Switch to random item in dump and subtract 2
    )            #End loop
    :++++        #Push 4 to dump
    ;---         #Switch to random item in dump and subtract 3
)

This one is a little tricky, as ; will never switch to a 0 (Remember items with a value of 0 are considered to not exist)

The inner loop will only exit if ;-- switches to a number <= 2

The outer loop will only exit if ;--- switches to a number <= 3

Due to the inherent randomness of the language, this should always terminate... eventually.

For scoring purposes, you should use the exact string Hello, World! as input when testing.

Scoring

This is meaning the interpreter that on average runs the fastest, wins!

Scoring will be determined by running each of the 4 test-cases above 100 times, and determining an average runtime (due to the inherent randomness of the language, a high number of runs should be made to minimise anomalous results).

Then once you have an average for each testcase, sum the 4 times, and that is your final score. Lower is better

\$\endgroup\$
1
  • \$\begingroup\$ I feel like a lot of time will come from the RNG, so better solutions might sacrifice some "randomness" for speed - You might want to standardise "randomness" \$\endgroup\$
    – emanresu A
    Dec 22, 2021 at 3:42
4
\$\begingroup\$

Converge to a number

\$\endgroup\$
4
\$\begingroup\$

Schrödinger's cat program

\$\endgroup\$
1
  • \$\begingroup\$ This is probably good to post now, and it looks like a good challenge! \$\endgroup\$
    – emanresu A
    Dec 27, 2021 at 5:59
4
\$\begingroup\$

Incrementally Increment Identical Integers

\$\endgroup\$
2
  • \$\begingroup\$ Total rewording suggestion for everything up until before "To demonstrate": Given a non-empty non-descending list of any integers, increment each number by how many identical elements occur to its left. \$\endgroup\$
    – Adám
    Jan 1, 2022 at 18:16
  • 2
    \$\begingroup\$ @Adám For what it's worth, I find that less understandable than the current description. It's probably a difference of APL mindset vs. Python mindset. \$\endgroup\$
    – DLosc
    Jan 1, 2022 at 18:18
4
\$\begingroup\$

Egyptian fraction representations of 1

\$\endgroup\$
4
\$\begingroup\$

Remove odd indices and double the even indices

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The test cases are now consistent with the example explanation, but not with the "remove odd, double even" description. You could fix this by either changing this to "remove even, double odd", or switching to 0-indexing \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 12:40
4
\$\begingroup\$
\$\endgroup\$
3
  • \$\begingroup\$ It'd be nice to link the ITTM paper. Also, showing an example ITTM and explaining its halting time (like your ⍵×⍵ 2-state ITTM) would be helpful. \$\endgroup\$
    – user41805
    May 7, 2021 at 12:39
  • \$\begingroup\$ @user41805 I'm currently working on an explanation for my 2-state ITTM champion. But the animations are a bit time consuming. I meant to link some ITTM papers, so I will add those links when I finish the edit I am working on. Thanks. \$\endgroup\$
    – Wheat Wizard Mod
    May 7, 2021 at 12:42
  • \$\begingroup\$ Related: codegolf.stackexchange.com/q/36747/45613 and codegolf.stackexchange.com/questions/18028/… (This doesn't seem to be a duplicate) \$\endgroup\$
    – Beefster
    May 18, 2021 at 16:25
4
\$\begingroup\$

Score a Scrabble Play

\$\endgroup\$
5
  • 2
    \$\begingroup\$ I think removing the letter points mapping from the challenge as you suggest is a good idea. Otherwise a lot of the byte count will be taken up just in storing the map, with less of the answer being the interesting part, which is the scoring algorithm. Honestly it might even be worth assuming all letters score 1, because the interesting computational problem is really just detecting what the words formed in the grid are. \$\endgroup\$
    – pxeger
    Jan 24, 2022 at 20:53
  • 1
    \$\begingroup\$ @pxeger I think I would like to keep the specific point values, so that the challenge still involves the words themselves somehow. Otherwise it would suffice just to find the distances between relevant tiles and certain empty squares as well as losing some (important, in my opinion) flavor. \$\endgroup\$ Jan 24, 2022 at 21:01
  • \$\begingroup\$ That's a good point; I hadn't considered that the letters themselves would no longer matter in that case. I'd still recommend going for the version with points mapping as input. \$\endgroup\$
    – pxeger
    Jan 24, 2022 at 21:03
  • \$\begingroup\$ Where do we get the word dictionary? \$\endgroup\$
    – Ginger
    Jan 24, 2022 at 21:08
  • \$\begingroup\$ @GingerIndustries There is no need for a word dictionary. As I wrote in my post, answers do not need to consider the legality of the play. \$\endgroup\$ Jan 24, 2022 at 21:11
4
\$\begingroup\$

Find the index of the matching parentheses for each character

\$\endgroup\$
1
  • \$\begingroup\$ please check if i have explained properly as some may not understand \$\endgroup\$
    – DialFrost
    Feb 2, 2022 at 9:20
4
\$\begingroup\$

Find my Māori pronouns

\$\endgroup\$
0
4
\$\begingroup\$

Print 2^n graph in ASCII

Your challenge is to output this infinite graph:


o
o
oo
oo
oo
oo
ooo
ooo
ooo
ooo
ooo
ooo
ooo
ooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
oooo
ooooo
ooooo
ooooo
ooooo
ooooo
ooooo
...

with the xth line having floor(log_2(x)) os (or other characters). Tag: code-golf, ascii-art, kolmogorov-complexity.

\$\endgroup\$
3
  • \$\begingroup\$ wow this looks interesting tbh, is there supposed to be a \n at the start of the sequence? \$\endgroup\$
    – DialFrost
    Feb 12, 2022 at 13:48
  • 2
    \$\begingroup\$ @DialFrost Yeah, because floor(log_2(1)) = 0. \$\endgroup\$ Feb 12, 2022 at 15:05
  • \$\begingroup\$ nice, but is there a reason you chose o? \$\endgroup\$
    – math scat
    Feb 20, 2022 at 10:55
4
\$\begingroup\$

Is it a tower permutation?

\$\endgroup\$
2
  • \$\begingroup\$ Maybe add a link to your previous tower challenge? \$\endgroup\$
    – pxeger
    Feb 20, 2022 at 14:06
  • 1
    \$\begingroup\$ @pxeger I'll add a comment once I post this \$\endgroup\$
    – AnttiP
    Feb 20, 2022 at 14:07
4
\$\begingroup\$

Gambling with an Alien

Find the challenge here!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to code golf and thanks for using Sandbox! Are wee allowed to implement less restrictive output requirement, i.e. using our default decision-problem rules (tag wiki)? - I suggest it over using two fixed strings (that not all languages can handle). \$\endgroup\$
    – pajonk
    Feb 28, 2022 at 19:43
  • \$\begingroup\$ @pajonk That seems like a good change! I'll implement it. \$\endgroup\$
    – Groger
    Feb 28, 2022 at 19:45
4
\$\begingroup\$

Crate art stacking

\$\endgroup\$
4
  • \$\begingroup\$ Is trailing whitespace allowed? \$\endgroup\$
    – pajonk
    Mar 2, 2022 at 7:11
  • 1
    \$\begingroup\$ This one is much better than the Stack Em one. \$\endgroup\$
    – ophact
    Mar 2, 2022 at 8:40
  • \$\begingroup\$ @pajonk do you think its better to allow or not allow? \$\endgroup\$
    – DialFrost
    Mar 3, 2022 at 2:57
  • 1
    \$\begingroup\$ I think I usually see allowing trailing whitespace in such challenges. Also, I'm always on the side of loosening I/O requirements. \$\endgroup\$
    – pajonk
    Mar 3, 2022 at 7:28
4
\$\begingroup\$

Repeat List Until Longer

\$\endgroup\$
4
  • \$\begingroup\$ I think the output for the last example should be [2,3,5,2,3,5,2,3,5]? \$\endgroup\$
    – Dingus
    Mar 9, 2022 at 0:26
  • \$\begingroup\$ Ah yes, that was my muscle memory being a little off. Thanks. \$\endgroup\$
    – Seggan
    Mar 9, 2022 at 0:27
  • \$\begingroup\$ Suggestion: instead of second list as input take only its length. \$\endgroup\$
    – pajonk
    Mar 9, 2022 at 13:13
  • \$\begingroup\$ This problem is component of a solution for another problem. I prefer it like this. \$\endgroup\$
    – Seggan
    Mar 9, 2022 at 15:26
4
\$\begingroup\$

The Missing Match

\$\endgroup\$
5
  • \$\begingroup\$ The task becomes clear by the end but I think some reorganisation of the text would help. In the second sentence you say 'The braces are all balanced', but further down we find out that this isn't actually true: 'inside the string there is a single unbalanced brace'. I'd suggest these two bits of information should be closer together. \$\endgroup\$
    – Dingus
    Mar 13, 2022 at 2:26
  • \$\begingroup\$ @Dingus thanks for the feedback. I updated the answer; would you care to take a look? \$\endgroup\$
    – code
    Mar 13, 2022 at 3:25
  • \$\begingroup\$ Looks good to me, but one other thing - I'd suggest brackets is a more appropriate word than braces here. \$\endgroup\$
    – Dingus
    Mar 13, 2022 at 6:29
  • \$\begingroup\$ @Dingus sure, thanks! Do you suggest I post it anytime soon or wait another day or so? \$\endgroup\$
    – code
    Mar 13, 2022 at 6:54
  • \$\begingroup\$ The general recommendation is to leave it in the Sandbox a few days at least, just to maximise the number of eyes that see it before it goes on main. \$\endgroup\$
    – Dingus
    Mar 13, 2022 at 9:25
4
\$\begingroup\$

Can you decrypt me?

Cops

Cops, post obfuscated code that hides a number \$n\$ inside its code. If \$n\$ condchars are changed, the program outputs \$n\$. Otherwise, it outputs a different number. Both programs may not error.

Robbers

Find the chars to change and what they should change into.

Example

print(2)

N is 1.


Robbers' post:

print(1)

Scoring

Cops, the user with the most uncracked posts wins. Robbers, the user with the most cracks wins.

\$\endgroup\$
7
  • \$\begingroup\$ How could you stop robbers writes a code that try to apply cops code on every possible inputs until find out one matching output? \$\endgroup\$
    – tsh
    Mar 16, 2022 at 11:22
  • \$\begingroup\$ @tsh uh, can you clarify? \$\endgroup\$
    – Alan Bagel
    Mar 16, 2022 at 11:51
  • \$\begingroup\$ Does this mean robber just need to write a program that for (i in AllPossibleInputs) if (CopsCode(i) == CopsOutput) return i? \$\endgroup\$
    – tsh
    Mar 16, 2022 at 12:28
  • 1
    \$\begingroup\$ @tsh, is it possible to enforce "don't do that?" \$\endgroup\$
    – Alan Bagel
    Mar 16, 2022 at 13:11
  • \$\begingroup\$ This is a good format for a CnR, but you need to specify scoring criteria. For the cops, "shortest code" (code-golf) is probably good enough. For robbers, something like "most cracked answer". You should probably add a rule to allow uncracked cops' answers to become "safe" after a certain amount of time (probably around 1-2 weeks) \$\endgroup\$
    – pxeger
    Apr 12, 2022 at 9:01
  • \$\begingroup\$ @pxeger does it need more clarifying and details? (other then scoring criteria) \$\endgroup\$
    – Alan Bagel
    Apr 12, 2022 at 14:10
  • \$\begingroup\$ No, if you add those things, it will be ok \$\endgroup\$
    – pxeger
    Apr 12, 2022 at 14:47
4
\$\begingroup\$

What does the text talk about?

note that the machine-learning tag will be new

META: this is far from being done. I also understand that this challenge depends heavily on manual opinion about the "type" of a piece of text. Hence, if you take issue with that, I would appreciate your giving a comment that suggests ways to fix that issue, rather than an unjustified downvote related to that issue.

Additionally, this might be a duplicate. I would appreciate your pointing this out before I compile the list of texts, if possible. However, if you identify a duplicate after I start compiling the list of texts, that is also fine.

Some parts use the future tense to talk about what I will do. Obviously I will have done them by the time I post the challenge.

The sections in italic could be taken as being ambiguous.

The links to the training, validation and test sets are not available yet. And of course, I don't yet have labels on my side.


This is a project that I once attempted to do, having learned machine learning. I run a forum app, and I was thinking of incorporating my new machine learning knowledge into that app by creating a model that could detect topics related to a given topic. After having worked on it for a few days, I hadn't made much progress, so I abandoned it. I hereby challenge you to make a similar model, ideally with machine learning, but that is not required. Your model will classify the topic of a piece of text. Such a model could then be used to find text related to a given piece of text by finding texts with a similar topic. You can choose to write your model without machine learning.

This is thus essentially a machine learning challenge. (or ideally, it will be. You may choose to write your solution without machine learning, but I am mainly looking forward to seeing machine learning solutions.) I will provide a large set of "articles", divided into a training set, a validation set, and a test set, with a 60-30-10 split. I expect there to be about 500 articles in all.

The articles in the training and validation sets are labeled with their topics: for instance, history, geography, mathematics, programming, etc. The test set, importantly, does not have public-facing labels, but I have labels on my side.

The training set is available here.

The validation set is available here.

The test set is available here.

Challenge

Write a classifier that attempts to classify the topic of a piece of text. The possible topics are:

(coming soon)

You can choose any of (coming soon) distinct values to represent the topic.

It should be able to produce an output that is one, and only one, of the chosen distinct values given any input string.

You have access to the train set to teach your classifier to recognize the topics (if you are using machine learning). The validation set can be used to compare different approaches.

Your submission will be scored based on how well it does on the test set. I will write the test set articles in such a way that they are not ambiguous (500 years ago, a mathematician discovered a method to calculate integrals is ambiguous as the sentence could be about mathematics or history, but Learn about the way people lived 1000 years ago is only about history). Your score is the number of articles it can correctly classify out of the test set. The higher the number of articles your submission can correctly classify, the better the score is. Thus the winner of this challenge is the submission that classifies the most articles correctly.

Importantly, this is not . I expect this to be a challenge that demands significant time and effort to produce a solution that scores highly, so you may post a link to a GitHub repository hosting the solution if required.

You are encouraged to either provide a way to easily run your solution, or provide the list of outputs that your code produces when given the test set articles. Even better, you could post a Jupyter notebook (if you are answering with a supported language) containing your solution, complete with test set outputs.

Important: please do not post a solution that is optimized only for the test set. It should work reasonably well in general.

Just so that you can get an idea of the topics:

Article: The dinosaurs went extinct 66 million years ago due to an asteroid impact.
Topic: history

Article: Time complexity is a measure of the complexity of an algorithm. For instance, the operation of adding two integers is usually taken to have a complexity of O(1). The operation of summing a list given as input has a complexity of O(n) where n is the size of the input.
Topic: programming

Article: Partial derivatives are derivatives taken with respect to one variable.
Topic: mathematics

Article: Planes are for going on holiday, especially island getaways.
Topic: holiday

Article: Carrot Cake Potato Mushroom
Topic: food
\$\endgroup\$
1
  • \$\begingroup\$ [joke] mathematica probably has a builtin for this \$\endgroup\$
    – des54321
    May 2, 2022 at 18:54
4
\$\begingroup\$

Matrix Meets ASCII Art

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Is the input guaranteed to contain at least one 1? How should we handle all-0 rows? (will it ever be a case?) Are the 1s going to be always neighbours? I suggest adding some more examples/test-cases. \$\endgroup\$
    – pajonk
    May 9, 2022 at 11:05
4
\$\begingroup\$

Haplololololololology!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Suggested test case: aaaabaaaab -> aaaab, as a simple example of matching the longest sequences not producing the shortest result (which would be abab) \$\endgroup\$ May 4, 2022 at 1:22
  • 2
    \$\begingroup\$ Thanks, added... \$\endgroup\$ May 4, 2022 at 1:27
  • 2
    \$\begingroup\$ What about something like filed edit? \$\endgroup\$
    – emanresu A
    May 4, 2022 at 5:45
  • 2
    \$\begingroup\$ It would yield filedit - or were you suggesting I add it to the test cases? \$\endgroup\$ May 4, 2022 at 5:51
  • 1
    \$\begingroup\$ Isn't mississippi -> missippi? \$\endgroup\$
    – pajonk
    May 4, 2022 at 12:55
  • \$\begingroup\$ Awesome, thank you! \$\endgroup\$ May 5, 2022 at 1:40
  • \$\begingroup\$ Edited down to a stub now that it's been posted to save space. \$\endgroup\$
    – naffetS
    May 13, 2022 at 4:04
1
10 11
12
13 14
145

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .