557
\$\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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

4112 Answers 4112

1
5 6
7
8 9
138
5
\$\begingroup\$

Minimally destroy CGCC in Game of Life

\$\endgroup\$
8
  • \$\begingroup\$ Just to clarify, you get an integer \$n\$ as input and must kill all but \$n\$ cells from the initial state to produce the shortest lived automata? \$\endgroup\$
    – Beefster
    Mar 22, 2021 at 17:44
  • \$\begingroup\$ Are there performance requirements? This problem is in EXPTIME. \$\endgroup\$
    – Beefster
    Mar 22, 2021 at 17:45
  • \$\begingroup\$ @Beefster No time requirements. And no, you decide how many cells you want to make alive (call that \$n\$) and which cells they are. You then run the game with those cells and the initial CGCC being alive until it reaches a point where all cells on the board are dead. Lowest \$n\$ wins. \$\endgroup\$ Mar 22, 2021 at 17:47
  • \$\begingroup\$ Oh, I get it. You're supposed to add live cells around the initial CGCC so that the board eventually anihillates. The way you framed the challenge is a little confusing. You make it seem like you're supposed to remove cells from the initial configuration. \$\endgroup\$
    – Beefster
    Mar 22, 2021 at 18:02
  • \$\begingroup\$ @Beefster I've edited the wording slightly, does it make more sense? \$\endgroup\$ Mar 22, 2021 at 18:05
  • \$\begingroup\$ The wording is clearer now, but the issue is that "However, if we change the initial state to the following, by changing 13 cells, then, after 31 iterations, the board is empty" is sort of misleading because it prepares the reader to remove cells when you then say "And this is your task." I think it would be less confusing if you gave an example where adding cells to an initial state causes the pattern to eventually annihilate. \$\endgroup\$
    – Beefster
    Mar 22, 2021 at 19:20
  • \$\begingroup\$ @Beefster The issue with that is that I don't actually have an example that fits the current rules :/ \$\endgroup\$ Mar 22, 2021 at 19:38
  • \$\begingroup\$ You don't necessarily need to create an example that fits the rules. You could instead give an example of a simpler pattern that, when a few additional cells are made live, leads to eventual annihilation. So the overall flow of the challenge description would be something like this: simple pattern, simple pattern + live cells --> annihilation, CGCC pattern creates still life + oscillators, description of the task and scoring. \$\endgroup\$
    – Beefster
    Mar 22, 2021 at 20:02
5
\$\begingroup\$

Posted

\$\endgroup\$
1
  • \$\begingroup\$ Instead of saying that "Output is undefined if n<1, or if A is shorter than n" just specify that this won't be the case. \$\endgroup\$
    – Adám
    Mar 24, 2021 at 13:54
5
\$\begingroup\$

Two Diehards Make a Glider


POSTED

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Is the WIP for the title or the challenge? The challenge looks mostly ok, but I'd be worried about having many solutions with the form: as simple as possible for the gliders with a well-known diehard placed far away. For the title, something like "gliders as emergent properties" or something could also be catchy. \$\endgroup\$ Mar 24, 2021 at 22:01
5
\$\begingroup\$

I'm Jelly of Python (Cops)

I'm Jelly of Python (Robbers)

\$\endgroup\$
5
\$\begingroup\$

Decode Polybus Square/Tap Code/Prison Code

\$\endgroup\$
4
  • \$\begingroup\$ Nice challenge :) You need to add a scoring criterion (code-golf most likely), and you should provide a few input->output examples to help checking answers \$\endgroup\$
    – Leo
    Mar 22, 2021 at 23:03
  • \$\begingroup\$ Suggested testcases: 23 15 31 31 34 => HELLO, 24 25 31 32 => IJLM, 11 22 33 44 55 => AGNTZ. Add tags code-golf, decode and string. \$\endgroup\$
    – emanresu A
    Mar 23, 2021 at 8:11
  • \$\begingroup\$ Thanks for the feedback :) \$\endgroup\$ Mar 23, 2021 at 12:51
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted \$\endgroup\$ Mar 30, 2021 at 15:15
5
\$\begingroup\$

Plz Halp I Need $$$ Again

Bob’s startup is running out of money and desperately needs investors to keep it afloat. Although you have helped Bob find the maximum number of investors, Bob has quickly realized that more investors does not lead to more funds because different investors give different amounts of money. Each investor interested in Bob’s company wishes to schedule a meeting with a certain start and end time, and promises to invest a certain amount of money. However, some of the meetings times may conflict. What is the maximum amount of money he can get from his investors?

Input Format

Input is given as an array of tuples of integers (or the equivalent in your chosen language). Each tuple p represents one investor, where p[0] is the start time of the investor’s meeting, p[1] is the end time, and p[2] is the amount of money promised.

For example, in the test case [(0, 10, 30), (10, 20, 50)], there are two investors: one who wants to meet from time 0 to time 10 and offers $30, and one who wants to meet from time 10 to time 20 and offers $50.

Meetings will always have a positive duration, meeting times are always non-negative, and a meeting that ends at time k does not conflict with a meeting that starts at time k. You may assume that the input is nonempty, and you may use any reasonable I/O method for input.

Within reason, you may also take input in different formats (for example, as three lists, one which contains the start times, one with the end times, and one with the money offered).

Output

Your program should output an integer, the maximum quantity of money that Bob can make.

Test Cases

[(1, 100, 10), (1, 5, 3), (5, 10, 3), (10, 15, 3)] => 10
[(0, 30, 40), (20, 45, 30)] => 40
[(10, 40, 40), (60, 85, 60)] => 100
[(65, 100, 70), (10, 45, 80)] => 150
[(10, 15, 50), (50, 85, 10), (95, 110, 60)] => 120
[(100, 135, 80), (50, 70, 80), (80, 110, 30), (95, 100, 40)] => 200
[(65, 95, 70), (50, 75, 30), (35, 60, 80), (85, 115, 100)] => 180
[(30, 35, 80), (35, 65, 10), (75, 110, 40), (40, 45, 20)] => 140
[(80, 110, 50), (0, 5, 30), (95, 125, 50), (80, 85, 70)] => 150
[(25, 40, 10), (100, 115, 60), (15, 50, 90), (60, 95, 50)] => 200
[(100, 125, 50), (75, 80, 100), (30, 60, 20), (50, 65, 90)] => 240
[(15, 35, 80), (55, 70, 40), (30, 65, 90), (30, 55, 60)] => 120
[(15, 40, 50), (60, 95, 30), (35, 40, 70), (55, 60, 90)] => 190
[(40, 65, 80), (40, 75, 10), (5, 15, 80), (100, 115, 80), (15, 35, 100), (60, 95, 40)] => 340
[(5, 30, 60), (85, 105, 90), (35, 65, 80), (90, 115, 40), (85, 90, 80), (30, 60, 90)] => 270
[(55, 65, 30), (5, 15, 90), (50, 85, 100), (0, 15, 90), (65, 70, 70), (60, 70, 80), (35, 55, 20), (80, 105, 80)] => 290
[(0, 10, 90), (70, 85, 80), (45, 55, 20), (90, 105, 90), (55, 90, 50), (0, 25, 20), (85, 105, 30), (85, 90, 100)] => 380
[(10, 45, 40), (85, 115, 80), (85, 105, 30), (30, 50, 50), (20, 40, 80), (100, 115, 60), (100, 135, 70), (30, 35, 70), (35, 50, 30)] => 180
[(80, 105, 70), (60, 65, 50), (95, 105, 80), (55, 65, 100), (40, 75, 80), (95, 110, 70), (60, 70, 90), (65, 70, 50), (55, 85, 100)] => 230
[(80, 85, 70), (35, 40, 60), (60, 80, 80), (5, 20, 100), (30, 60, 100), (45, 50, 60), (45, 80, 60), (10, 20, 50), (50, 65, 60), (60, 85, 70)] => 370
[(50, 75, 100), (90, 115, 20), (50, 65, 10), (35, 50, 30), (90, 120, 90), (65, 90, 30), (20, 55, 40), (50, 75, 50), (75, 105, 10), (15, 35, 70)] => 290

Rules

  • Standard loopholes are prohibited.
  • Though not required, polynomial-time solutions are encouraged so that Bob does not have to wait forever for the result.
  • This is , so the shortest solution in each language wins.

Meta

  • Are there any errors with the computer-generated test cases? I've manually verified some of them but I may have overlooked something.
  • Is there any ambiguity in the problem statement?
  • Are there any other issues?
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Test cases seems be ordered by end times. I'd suggest mixing them up (so no answer accidentally uses the order) or specifying the order. Also, in the example in the input format, it's (10, 20, 50) but you say they want to meet 5 - 10. (And I prefer the Output section before the test cases, so people know what they need to do earlier.) \$\endgroup\$
    – xash
    Apr 28, 2021 at 12:51
  • \$\begingroup\$ Thanks, I have edited the challenge accordingly \$\endgroup\$
    – knosmos
    Apr 28, 2021 at 12:55
  • 1
    \$\begingroup\$ Is it possible to take input as three lists, for start times, end times, and prices? \$\endgroup\$
    – rak1507
    Apr 28, 2021 at 13:13
  • \$\begingroup\$ Sure - should I add test cases in that format? \$\endgroup\$
    – knosmos
    Apr 28, 2021 at 13:16
  • 2
    \$\begingroup\$ You don't need to add testcases in different formats, simply state in your post that different formats are acceptable (and perhaps mention some different formats like the \$3\$ lists @rak1507 mentions). \$\endgroup\$
    – Noodle9
    Apr 28, 2021 at 13:41
  • \$\begingroup\$ Link to the deleted main post, so that it's easy to find and edit when this challenge is good to go :) \$\endgroup\$ Apr 28, 2021 at 15:21
5
\$\begingroup\$

posted

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I think I saw l4m2's proposal which is essentially the same thing, but this one is arguably much better and clearly worded. Btw, the first example is just a special case of Chaitin's constant with power-of-0.5 weights. \$\endgroup\$
    – Bubbler
    May 12, 2021 at 14:16
  • \$\begingroup\$ I don't see how it's possible, if \$f(n)\$ is computable, isn't the limit of \$f(n)\$ computable by the definition of limit? \$\endgroup\$ May 12, 2021 at 17:31
  • \$\begingroup\$ @CommandMaster Actually no! This is just one of a million ways in which limits can be counter intuitive. For an example, imagine an \$f\$ where \$f(n)\$ just takes the first \$n\$ Turing machines and runs them for \$n\$ steps, if machine \$m\$ halts in the test run then you add \$2^{-m}\$ to a total (think about what this means in binary). This is obviously computable, we can simulate Turing machines for \$n\$ steps and add rational numbers. But the limit encodes the exact solution to the halting problem. This is actually the first example number there. \$\endgroup\$
    – Wheat Wizard Mod
    May 12, 2021 at 17:48
  • 1
    \$\begingroup\$ Does \$f(n)\$ have to be an exact rational (i.e. a pair (numerator, denominator)), or can it be represented as a floating point number? In other words, can we output \$f(n)\$ as a floating point number which will, necessarily, be inexact for large values of \$n\$, as long as the algorithm theoretically works if given arbitrary precision? \$\endgroup\$
    – Delfad0r
    May 12, 2021 at 20:30
  • \$\begingroup\$ @Delfad0r I'm not entitled to answer your question, but I don't think float or double are applicable here. Arbitrary-precision floating-point numbers are certainly applicable tho. \$\endgroup\$ May 12, 2021 at 20:44
  • \$\begingroup\$ @WheatWizard Thanks for the clarification! Does the first option include, say, a pair [numerator,denominator] (even though it's not a built-in rational type)? In this case, is the pair required to be reduced (i.e. gcd=1)? \$\endgroup\$
    – Delfad0r
    May 13, 2021 at 10:09
  • 1
    \$\begingroup\$ @Delfad0r I will add that as another form, and the second format shows a non-reduced fraction as an example so it would be all right for this format as well. \$\endgroup\$
    – Wheat Wizard Mod
    May 13, 2021 at 10:11
5
\$\begingroup\$

Drop some boxes

\$\endgroup\$
1
  • \$\begingroup\$ Assuming you live in a world with gravity \$\endgroup\$
    – mathcat
    Jun 20, 2021 at 10:07
5
\$\begingroup\$

Ouput Input... Forever

Problem

Given input chars, output them repeatedly forever.

Examples

abc       -> abcabcabcabcabcabcabcabcabc...
[1, 2, 3] -> [1, 2, 3][1, 2, 3][1, 2, 3]...
lo        -> lololololololololololololol...

Dedication: This is for all the tarpits out there!

Questions

  • Should a delimiter be allowed?
  • I was imagining that the input would be cycled through infinitely in order, like in the examples. Should we enforce that as a rule, though?
    • Or should the rules just be: Each char of input should eventually occur infinitely many times in output. (Informally stated, but can easily be made mathematically precise.)
  • Other thoughts!
\$\endgroup\$
4
  • \$\begingroup\$ If you go with "Each char of input should eventually occur infinitely many times in output", then you'd need to specify that no other characters should be outputted because otherwise you could just output all bytes in order, or output random bytes infinitely \$\endgroup\$
    – pxeger
    Aug 6, 2021 at 7:24
  • 1
    \$\begingroup\$ I think that vast majority of languages here will just use some version of x = input(); while(true) {print(x);}, so I doubt this will be especially interesting except for in a handful of languages \$\endgroup\$ Aug 6, 2021 at 13:49
  • \$\begingroup\$ Are you going to post this? :) \$\endgroup\$
    – emanresu A
    Aug 13, 2021 at 22:30
  • \$\begingroup\$ Are you going to post this? It's been a month.... \$\endgroup\$
    – emanresu A
    Sep 6, 2021 at 3:31
5
\$\begingroup\$

Create the shortest code snippet of the power functions 1 through 10 which can be compiled to assembly code and which contains the minimum number of imul assembly operations. For better comparison use https://godbolt.org/ and either GCC or LLVM.

Introduction

Did you know the fastest way to calculate x⁴ is not x*x*x*x, but y = x*x; y*y which saves one multiplication and is therefore faster. In mathematics and computer science this is called addition-chain exponentiation.

The minimum number of multiplications for powers of 1 through 10 are

x^1  -> 0
x^2  -> 1
x^3  -> 2
x^4  -> 2
x^5  -> 3
x^6  -> 3
x^7  -> 4
x^8  -> 3
x^9  -> 4
x^10 -> 4

Example

The assembly code looks as follows (C++ code below):

pow_1(int):
        mov     eax, edi
        ret
pow_2(int):
        mov     eax, edi
        imul    eax, edi
        ret
pow_3(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, edi
        ret
pow_4(int):
        imul    edi, edi
        mov     eax, edi
        imul    eax, edi
        ret
pow_5(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, eax
        imul    eax, edi
        ret
pow_6(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, edi
        imul    eax, eax
        ret
pow_7(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, edi
        imul    eax, eax
        imul    eax, edi
        ret
pow_8(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, eax
        imul    eax, eax
        ret
pow_9(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, eax
        imul    eax, eax
        imul    eax, edi
        ret
pow_10(int):
        mov     eax, edi
        imul    eax, edi
        imul    eax, eax
        imul    eax, edi
        imul    eax, eax
        ret

One naive solution written in C/C++ and compiled with X86-64 gcc 11.2 and -O3 optimization on https://godbolt.org/ could be (Notice that I didn't need to optimize the code myself, but the compiler picked it up automatically. Aren't compilers awesome?):


int pow_1(int num) {
    return num;
}

int pow_2(int num) {
    return num * num;
}

int pow_3(int num) {
    return num * num * num;
}

int pow_4(int num) {
    return num * num * num * num;
}

int pow_5(int num) {
    return num * num * num * num * num;
}

int pow_6(int num) {
    return num * num * num * num * num * num;
}

int pow_7(int num) {
    return num * num * num * num * num * num * num;
}

int pow_8(int num) {
    return num * num * num * num * num * num * num * num;
}

int pow_9(int num) {
    return num * num * num * num * num * num * num * num * num;
}

int pow_10(int num) {
    return num * num * num * num * num * num * num * num * num * num;
}

Of course you can also use other language like Rust to create the same assembly code:

pub fn pow_9(num: i32) -> i32 {
    num * num * num * num * num * num * num * num * num
}

(Note Rust has an additional mov, but the challenge only focuses on the amount of imul assembly instructions.)

example::pow_9:
        mov     eax, edi
        mov     ecx, edi
        imul    ecx, edi
        imul    ecx, ecx
        imul    eax, ecx
        imul    eax, ecx
        ret

Scoring

  • The string must be compilable to assembly instruction with a compiler like GCC or LLVM (Note they have backends for many languages). You are not allowed to create the assembly instructions directly. Please also provide compiler version and flags.
  • The whole string must be written in the same language (no writing C with another language)
  • Out of bounds issues must not be considered, the code should work for integers 0 through 3.
  • The generated assembly code can only contain the minimum number of imul needed for that power and mov and ret instructions
  • The 10 functions in the assembly instructions should be named as I named them (order does not matter)
  • Shortest string wins!

Good luck!

Discussion

I've mistakenly posted this as a question to the meta site, but wanted this was my intended destination. After a few migrations the current location is here. I've now reposted here trying to keep the style the same as I couldn't edit the post anymore.

Grain ghost has made two comments on how to improve the challenge:

  • "Creating the assembly instructions not via a compiler is not allowed" and "The generated assembly must be similar to the provided assembly" strike me as not particularly clear, objective or enforceable
  • Since we are dealing with assembly I would expect some discussion about precision and out of bounds issues

Thank you!

This is not a typical code golf challenge, but I'm very excited what kinds of meta programming techniques will show up.

\$\endgroup\$
10
  • \$\begingroup\$ @grain-ghost do I ping you this way? What I want to prohibit with the use of a compiler is that people simple create a program creating the assembly instruction string. The string must be compilable with GCC or LLVM. Similarity is hard, because compilers are weird (see my Rust example). May be say: The binary must contain the right number of imul instructions, at most two additional mov instruction and one ret instruction. Precision is no important with integer numbers as far I can think. Overflow is an issue, but I would simply neglect that case or restrict to numbers below or equal to 3. \$\endgroup\$
    – JulianWgs
    Nov 16, 2021 at 20:54
  • 1
    \$\begingroup\$ If nobody's said it so far, welcome to Code Golf! This looks like a great challenge. For out of bounds issues, there's usually one of two approaches challenges will take, either having a minimum input size that must be supported, or just ignoring out of bounds issues within reason. Those would probably both work here, so it's entirely up to you. I agree with the two bullet points Grain Ghost brought up, those could probably use some clarification. \$\endgroup\$ Nov 16, 2021 at 21:06
  • \$\begingroup\$ Thanks for welcoming me! :) I've updated the challenge. By restricting the amount of assembly instructions the submission must use imul (another feedback brought up to use for loops with addition) and guarantees similarity, because there is no other way to solve it. Another idea I had would be to only allow mov, ret and imul instructions. \$\endgroup\$
    – JulianWgs
    Nov 16, 2021 at 21:24
  • 1
    \$\begingroup\$ Oh, so you're aiming to restrict what instructions can be used? That makes sense, I hadn't understood the wording right. You can definitely just choose a specific list of instructions to allow, which I'd recommend doing instead of the current requirements which are a little bit vague. There's actually a tag for that sort of thing, atomic-code-golf. \$\endgroup\$ Nov 16, 2021 at 21:27
  • 1
    \$\begingroup\$ (Comment migrated from the original question.) In addition to what was already pointed out on the main site, another potential issue with this challenge is that it's entirely possible to do it without any imul, for instance with inefficient addition loops. \$\endgroup\$
    – Arnauld
    Nov 16, 2021 at 21:32
  • \$\begingroup\$ I've updated the challenge accordingly I think limiting to imul (minimum number), mov and ret ensures similarity. I would like to encourage entries from many languages. Can I pick a winner per language? \$\endgroup\$
    – JulianWgs
    Nov 16, 2021 at 22:04
  • \$\begingroup\$ We have a challenge on a similar topic Shortest Addtion Chain. This challenge looks different enough though. \$\endgroup\$
    – xnor
    Nov 17, 2021 at 2:00
  • 2
    \$\begingroup\$ I might not be the target audience as someone not into compiled languages, but the needing to go through a compiler strikes me as convoluted. What if we could just output the assembly, or some other representation of the sequence of operations? Needing to consider how a compiler would translate and optimize the operations seems finicky, but I guess maybe that's the whole point. \$\endgroup\$
    – xnor
    Nov 17, 2021 at 2:06
  • \$\begingroup\$ @xnor exactly the best solution will probably involve some kind of metaprogramming massaging the code so the compiler will optimize it. I've updated the challenge again with info about naming the functions. Can the challenge be posted now? :) \$\endgroup\$
    – JulianWgs
    Nov 17, 2021 at 7:00
  • 1
    \$\begingroup\$ @JulianWgs It's your decision, but the general recommendation is to leave posts in the Sandbox at least 72 hours to gather feedback. I'd err on the side of waiting for this challenge because it might benefit from being seen by more people with knowledge in this specific domain and many people don't look at the Sandbox that often. I'd also suggest confirming with existing commenters that your edits have addressed their comments. \$\endgroup\$
    – xnor
    Nov 17, 2021 at 7:06
5
\$\begingroup\$

Open or close?

Posted here.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ The calculator would be more useful if ) were followed by ) assuming another unbalanced ( remains. Example: "1*(2+(3*4)" -> ? \$\endgroup\$
    – aschepler
    Nov 15, 2021 at 23:24
  • \$\begingroup\$ @aschepler Good thing the calculator dev thought this through more than I did, because that's exactly what it does. I'll update the question, thanks! \$\endgroup\$
    – Jitse
    Nov 16, 2021 at 8:11
5
\$\begingroup\$

Convert prefix to infix

\$\endgroup\$
2
  • \$\begingroup\$ Dupe? \$\endgroup\$
    – Dingus
    Nov 18, 2021 at 23:09
  • \$\begingroup\$ @Dingus Yes, I'll just do prefix to infix instead :P \$\endgroup\$
    – emanresu A
    Nov 19, 2021 at 3:31
5
\$\begingroup\$

Minimum number of changed tiles to permit knight passage

Summary

Given a chess knight K that is only allowed to step on permitted tiles X, output the minimum number of . tiles that must be changed to an X tile in order to permit a passage to the destination D.

Specification

  • The chessboard is guaranteed to be larger than 3x3.
  • The chessboard is guaranteed to have one and only one D and K in it.
  • Sometimes, not using the existing X tiles can lead to a more minimal solution, so please take this in mind while solving this challenge. (e.g. the 2nd testcase)

Test cases

..D.
XXXX
....
...K

Output = 1 (sequence = (-2,+1), (+1,+2))

.D..
....
..XK
....

Output = 2: (sequence = (-2,+1), (-1,-2), (+2, +1), (-1, +2))

D.X
...
...
...
..K

Output = 1: (sequence: (-1, +2), (-1, +2))

DX.
...
...
...
..K

Output = 1: (sequence: (-1, +2), (-1, +2))

D.X.
....
.X.X
.K..

Output = 0: (sequence: (+2, +1), (-1, +2), (-1, -2), (-1, +2))

DXXX
XKXX
XXXX
XXXX

Output = 0: (sequence: (+1, -2), (+1, +2), (-2, +1), (-1, -2), (+2, +1), (-2, +1))

\$\endgroup\$
14
  • \$\begingroup\$ where is the D on the board and what is the W doing on the board \$\endgroup\$
    – DialFrost
    Jan 26 at 7:08
  • 1
    \$\begingroup\$ @DialFrost That's a typo. Fixed \$\endgroup\$
    – user110579
    Jan 26 at 7:10
  • \$\begingroup\$ i like this challenge otherwise! \$\endgroup\$
    – DialFrost
    Jan 26 at 7:15
  • \$\begingroup\$ @DialFrost Thank you! :) \$\endgroup\$
    – user110579
    Jan 26 at 7:22
  • \$\begingroup\$ May we assume that using existing X tiles leads to minimal solution or may there be "traps"? \$\endgroup\$
    – pajonk
    Jan 26 at 8:08
  • \$\begingroup\$ May you give an example of not using the X tiles leading to the minimal solution? \$\endgroup\$
    – user110579
    Jan 26 at 8:12
  • \$\begingroup\$ I mean e.g. DX./.../.../.../..K, where putting X in the middle is sufficient and you don't need to reach the existing X. \$\endgroup\$
    – pajonk
    Jan 26 at 8:12
  • 1
    \$\begingroup\$ @pajonk In this case, I think I'm trying to define a challenge that allows "traps" in the input. I'll clarify that in the challenge. \$\endgroup\$
    – user110579
    Jan 26 at 8:14
  • \$\begingroup\$ I've edited my example in the meantime to highlight its "trappy" nature. You may also want to add more test-cases (like with more Xs or where the ouput is 0). \$\endgroup\$
    – pajonk
    Jan 26 at 8:18
  • \$\begingroup\$ @pajonk I've added your edited testcase and some of your testcase suggestions. Thank you for your suggestions! \$\endgroup\$
    – user110579
    Jan 26 at 8:27
  • \$\begingroup\$ your first test case is wrong, you can do it in 1: (-2,+1), (+1,+2) \$\endgroup\$ Jan 26 at 14:06
  • \$\begingroup\$ @thejonymyster Fixed \$\endgroup\$
    – user110579
    Jan 27 at 4:57
  • \$\begingroup\$ suggested testcase: one where the straight path to the goal takes more X tile placements than following a longer route to the goal which already has many X tiles. Either way though, this is pretty much ready to post \$\endgroup\$ Jan 28 at 14:13
  • \$\begingroup\$ May I assume the board is less than (or equals to) 8x8? \$\endgroup\$
    – tsh
    Jan 29 at 8:15
5
\$\begingroup\$

Is it a fibonacci-like sequence?

\$\endgroup\$
2
5
\$\begingroup\$

Fibonacci triangle

\$\endgroup\$
8
  • \$\begingroup\$ this is more of a curve due to the incrementing length of numbers :P looks alright tho \$\endgroup\$
    – DialFrost
    Mar 2 at 3:47
  • \$\begingroup\$ @DialFrost Close enough, and I wasn't sure what else to call it :P \$\endgroup\$
    – emanresu A
    Mar 2 at 3:48
  • \$\begingroup\$ i think the test case for 20 is wrong, the first 1+1=2 and 1+2=3 dont align \$\endgroup\$
    – DialFrost
    Mar 2 at 3:48
  • \$\begingroup\$ @DialFrost Fixed, that's an error with my programming \$\endgroup\$
    – emanresu A
    Mar 2 at 3:51
  • \$\begingroup\$ suggestion for title qns: Fibonacci curve (cuz triangle has no application to this qns lol) \$\endgroup\$
    – DialFrost
    Mar 2 at 4:17
  • \$\begingroup\$ Is infinite output allowed, taking no input? (part of standard sequence rules) \$\endgroup\$
    – pxeger
    Mar 2 at 10:17
  • \$\begingroup\$ @pxeger Sure :P - no outputting the nth term though, as I feel that makes the challenge too easy. \$\endgroup\$
    – emanresu A
    Mar 2 at 19:03
  • 1
    \$\begingroup\$ @emanresuA Yes, I was thinking that as well. (although calculating the increasing string lengths might be complicated?) \$\endgroup\$
    – pxeger
    Mar 2 at 20:09
5
\$\begingroup\$

Gray code on N symbols

\$\endgroup\$
5
\$\begingroup\$

Resolve references in a chat discussion

\$\endgroup\$
5
\$\begingroup\$

Pairs of integers ordered by their exponentiation

\$\endgroup\$
5
\$\begingroup\$

Convert between graph representations.

\$\endgroup\$
2
  • \$\begingroup\$ Awesome challenge! It seems ready to me and juding by the upvotes (might wanna wait 1 or 2 more days) \$\endgroup\$
    – DialFrost
    Mar 21 at 11:00
  • \$\begingroup\$ @DialFrost already posted .... \$\endgroup\$
    – PyGamer0
    Mar 21 at 12:21
5
\$\begingroup\$

Satisfy as many people as possible

Posted here.

\$\endgroup\$
2
  • \$\begingroup\$ im confused but nice challenge! :D \$\endgroup\$
    – DialFrost
    Mar 14 at 2:50
  • \$\begingroup\$ Wow, good challenge! They should use this for making servant robots; they'd make everyone as happy as possible :-)! The only part I didn't understand was the math formula; but, since I don't even know what the giant E means, that's not surprising. And as for title suggestions, something a little more catchy would be nice. Maybe something along the lines of "How many people can you satisfy?" (that's just a suggestion; I'm not very good at creative writing) \$\endgroup\$ Mar 22 at 19:37
5
\$\begingroup\$

Unshuffle my poker chips

\$\endgroup\$
5
\$\begingroup\$

Storing a band matrix

\$\endgroup\$
2
  • \$\begingroup\$ Can you clarify in the definition that a band is symmetric (in terms of shape) about the main diagonal? Something like "the main diagonal and an equal number of adjacent diagonals on either side of it" \$\endgroup\$
    – att
    May 9 at 23:02
  • \$\begingroup\$ Wait never mind, somehow I missed the "in this challenge" further down \$\endgroup\$
    – att
    May 9 at 23:04
5
\$\begingroup\$

BitCycle Metagolf

\$\endgroup\$
2
  • \$\begingroup\$ Since undefined behavior can have an effect on how small you can make a BitCycle program, I'd say you should either pick a specific implementation and say all answers must work on that implementation, or say that answers are allowed to work on any existing implementation. \$\endgroup\$
    – DLosc
    May 14 at 17:47
  • \$\begingroup\$ @DLosc Okay, I will put in that it has to work on TIO. \$\endgroup\$
    – Aiden Chow
    May 14 at 18:13
5
\$\begingroup\$

Spend maximal money

\$\endgroup\$
20
  • \$\begingroup\$ For 10.00; [5,5,10] is [5,5] an ok output? What should be the output for 10.00; [1,2,5,5,7] (and why)? Suggestion: keep the challenge within positive integers. \$\endgroup\$
    – pajonk
    May 9 at 11:15
  • \$\begingroup\$ @pajonk I prioritized choosing items from left to right. \$\endgroup\$ May 9 at 22:22
  • \$\begingroup\$ You may want to alter the new examples to comply with your spec ("without equaling"). Also, does the order of the output matter ([12.99, 0.99] vs [0.99, 12.99])? I also suggest explicitly stating that \$l\$ is an ordered list. \$\endgroup\$
    – pajonk
    May 10 at 9:06
  • \$\begingroup\$ @pajonk YOU were the one how made me thought those were the correct answers, but ok. \$\endgroup\$ May 10 at 11:26
  • \$\begingroup\$ and no, it will not be an ordered list. the output also doesn't matter. \$\endgroup\$ May 10 at 19:03
  • \$\begingroup\$ If the input is not ordered, hot do we determine left-to-right? \$\endgroup\$
    – pajonk
    May 10 at 19:31
  • \$\begingroup\$ aw damn you have a valid point lemme fix that \$\endgroup\$ May 10 at 22:16
  • \$\begingroup\$ Your last example has an incorrect output. The answer should be [2.00, 7.00] \$\endgroup\$
    – jezza_99
    May 12 at 23:31
  • \$\begingroup\$ @jezza_99 fixed. \$\endgroup\$ May 13 at 0:03
  • \$\begingroup\$ You say that you want to prioritize choosing items from left to right. For the examples you have given, this only results in an ordered output, which you've said is not important. The actual possible solutions do not change. I recommend either adding an example to test this criteria or dropping it. A suitable example would be budget=10.00, prices=[1.00, 2.00, 3.00, 4.00, 8.00]. This should output [1.00, 8.00] even though [2.00, 3.00, 4.00] is also a potential solution \$\endgroup\$
    – jezza_99
    May 13 at 1:03
  • \$\begingroup\$ @jezza_99 i'm sorry but you've broken my brain. I'll just leave this here to rot \$\endgroup\$ May 13 at 19:06
  • \$\begingroup\$ @BowlingPizzaBall what is the point of the rule "Prioritize choosing items from left to right"? \$\endgroup\$
    – jezza_99
    May 13 at 22:59
  • \$\begingroup\$ @jezza_99 Guess you could say there is no point. I'll remove that rule \$\endgroup\$ May 13 at 23:11
  • \$\begingroup\$ @jezza_99 I thought this rule was to make the solution unique. Now (as in your example above) there may be multiple solutions. \$\endgroup\$
    – pajonk
    May 14 at 15:31
  • \$\begingroup\$ @jezza_99, yeah, prioritizing left to right means there is only 1 valid solution. \$\endgroup\$ May 14 at 16:47
5
\$\begingroup\$

Generate a Baudot punched tape segment

What is Baudot?

From Wikipedia

The Baudot code [boˈdo] is an early character encoding for telegraphy invented by Émile Baudot in the 1870s. It was the predecessor to the International Telegraph Alphabet No. 2 (ITA2), the most common teleprinter code in use until the advent of ASCII. Each character in the alphabet is represented by a series of five bits, sent over a communication channel such as a telegraph wire or a radio signal. The symbol rate measurement is known as baud, and is derived from the same name.

Task:

For this challenge, your task is to write a program or a function that takes a string as its input and generates ASCII art that looks like a roll of punched tape. For the purposes of this challenge, you should specifically use the following variant, as it just happened to be the first image I found :P

International Telegraph Alphabet 2 brightened

For example where input is "HELLO WORLD\r\n" (note that carriage return is optional)

 *    *      
  **  * **  *
.............
*    *  *    
    *  *   * 
* ***  *  *  
hello worldcl
           rf

Program Description:

  • The program/function takes the input and turns it into a sequence of Baudot words (sequences of five bits)
  • For each word, it makes a column of the first two bits, then a . then the remaining three bits
  • Optional trailing space / newline

Criteria:

  • Output may not be output as an array unless there is no other valid option in the language. Trailing spaces and newlines allowed.
  • Any acceptable input
  • Assume all input characters are valid Baudot characters
\$\endgroup\$
2
  • 2
    \$\begingroup\$ No need to specify standard loopholes and I/O, they apply by default. You also override standard I/O with your third rule, so not much of a point to linking to it. \$\endgroup\$ Jun 7 at 21:12
  • 1
    \$\begingroup\$ The Baudot code comes with the ability to switch between two modes (one for letters and one for figures). You'll have to clarify if we need to support that and how. \$\endgroup\$
    – Arnauld
    Jun 12 at 20:41
5
\$\begingroup\$

Decipher a squashed sequence

\$\endgroup\$
5
\$\begingroup\$

All\$^{\dagger}\$ 3-character expressions

\$^{\dagger}\$with some exceptions

In your golfing language of choice, given no input, output all valid 3-character expressions in that language, with the conditions described below.

An expression, for the purposes of this challenge, is a string of characters that can be evaluated to some result. An example of an expression in many languages is 1+2, which evaluates to 3. If evaluation causes an error/exception/crash (e.g. 1/0 in Python), then it should not be printed.

Expressions can also have side effects (modify the state of the program), e.g. y=2 in Ruby. These are allowed to be output but are not required. (In other words, you only need to print out referentially transparent expressions.) Similarly, any expressions that rely on the evaluation of previous expressions, e.g. a+2 (which requires that the value of a be set), are optional, unless they cause an error/crash, in which case they should not be output.

Some additional notes:

  • White space and comments do not count as part of an expression - e.g. 2 or 2#a in Python are one-character expressions, so they shouldn't be printed.

Any language that does not have the concept of expressions, or has no expressions that are 3 characters long meeting the above requirements, cannot be used for this challenge.

As per usual code golf, the shortest program (in bytes) wins.

Sandbox Questions

(This is my first challenge, so I don't really know what I'm doing, and feedback is greatly appreciated.)

I'm not sure how to deal with expressions that change the results of other expressions or change what counts as a valid expression, particularly in the case of side effects. For example, if in the language, evaluating any expressions causes an "answer" variable to be set, then all expressions have side effects and the challenge is moot.

I was considering having the condition for passing be "Your program satisfies the challenge if, after running, there are no other expressions you can evaluate.", but I'm unsure if that's a good requirement.

\$\endgroup\$
17
  • 1
    \$\begingroup\$ Nice challenge! However, bonus challenges are generally discouraged when writing challenges, so either remove the bonus, or make it another challenge. \$\endgroup\$
    – Seggan
    Jul 12 at 20:34
  • \$\begingroup\$ (See relevant meta post.) \$\endgroup\$
    – Steffan
    Jul 12 at 21:38
  • \$\begingroup\$ Might it be possible to generate programs instead of expressions for languages that don't have expressions? Also I think, that you can use code-generation tag. \$\endgroup\$
    – Jiří
    Jul 12 at 21:43
  • \$\begingroup\$ @Jiří I think that is a meaningfully different request from generating all expressions -- it could probably be a separate challenge. \$\endgroup\$ Jul 12 at 22:15
  • \$\begingroup\$ @thejonymyster It doesn't lead to any footnote -- it's just indicating that there are some exceptions to the word "all" (the same way that "with an asterisk" means "some exceptions apply"). It's probably unnecessarily confusing though -- I'll change it. \$\endgroup\$ Jul 12 at 22:18
  • \$\begingroup\$ I'm still concerned about how exactly to define "having side effects" -- does anyone have a better idea of how to deal with that? \$\endgroup\$ Jul 12 at 22:21
  • 2
    \$\begingroup\$ Does having side effects also include printing or reading input? Also I have found following Wikipedia page which talks about expressions. Which led me to Wikipedia page about Referential transparency which had following sentence which might be the thing you are looking for: An expression is called referentially transparent if it can be replaced with its corresponding value (and vice-versa) without changing the program's behavior. \$\endgroup\$
    – Jiří
    Jul 12 at 23:00
  • 1
    \$\begingroup\$ The thing is, some languages don't have something called an "expression", like golfing languages (and others). In that case, do we just output valid programs? \$\endgroup\$
    – Steffan
    Jul 13 at 2:04
  • \$\begingroup\$ @Steffan I mentioned that in the description: "Any language that does not have the concept of expressions, or has no expressions that are 3 characters long meeting the above requirements, cannot be used for this challenge." \$\endgroup\$ Jul 15 at 18:30
  • \$\begingroup\$ What is the definition of "expression" in regards of comments? Is it allowed to output strings that include comments? (e.g. 3#2 in python) \$\endgroup\$
    – Steffan
    Jul 15 at 18:39
  • \$\begingroup\$ @Steffan Hm, I'd say that's a 1-character expression with a comment, so by the rules above it shouldn't be printed. But that's not a strong conviction on my part. \$\endgroup\$ Jul 15 at 18:58
  • \$\begingroup\$ Also, is it allowed to print things with whitespace, e.g. " " or " 2"? \$\endgroup\$
    – Steffan
    Jul 15 at 19:08
  • \$\begingroup\$ Also, can random warnings be spouted to stderr? \$\endgroup\$
    – Steffan
    Jul 15 at 19:11
  • \$\begingroup\$ @Steffan Thank you for asking these questions :) I'd also say that white space isn't part of the expression, except in obvious cases - e.g. the expression representing the empty string " " -- so it shouldn't be allowed. For the second point: I think I'll say that expressions generating errors that don't stop execution of the program are allowed, so yes. Those expressions probably shouldn't be required to output though (?) \$\endgroup\$ Jul 15 at 19:25
  • \$\begingroup\$ For the warnings, I can actually disable them with a flag (like -W0 in ruby), so it's fine either way. So as far as spaces, " 2" isn't allowed, I guess. And - 2 isn't allowed either, I guess? Welp, this is going to add some bytes lol \$\endgroup\$
    – Steffan
    Jul 15 at 19:47
5
\$\begingroup\$

Have you heard of tralindromes?

\$\endgroup\$
5
\$\begingroup\$

Divisor of a string

\$\endgroup\$
4
  • 2
    \$\begingroup\$ May we assume the input string has positive length? \$\endgroup\$
    – pajonk
    Aug 10 at 8:31
  • 1
    \$\begingroup\$ @pajonk yes, you can \$\endgroup\$
    – badatgolf
    Aug 10 at 9:31
  • 4
    \$\begingroup\$ You may also want to specify what to expect within the string (letters, whitespace, special characters?) - I suggest only lowercase letters. \$\endgroup\$
    – pajonk
    Aug 10 at 11:25
  • 1
    \$\begingroup\$ Can the output have duplicates? Can it be in any order? \$\endgroup\$
    – Steffan
    Aug 10 at 21:30
5
\$\begingroup\$

Radiation Hardening Koth

\$\endgroup\$
5
  • \$\begingroup\$ Why not the mean? \$\endgroup\$
    – Seggan
    Aug 9 at 18:53
  • 1
    \$\begingroup\$ You could get really luckly sometimes and get paired against "almost dead" programs giving you a very high score with no real effort. Or get really unlucky and the first program in the first round guesses the single essential character in your source code. I think the median will compensate for this randomness and give a better idea of the general performance of a program. \$\endgroup\$
    – mousetail
    Aug 9 at 19:25
  • \$\begingroup\$ Ah, okay then. Got it. \$\endgroup\$
    – Seggan
    Aug 9 at 19:43
  • \$\begingroup\$ I would say multi-language koth's land up bad cuz (length) 100 is a little too much already for python but 100 is like a no-go for c++ (i guess) \$\endgroup\$ Aug 10 at 12:26
  • 2
    \$\begingroup\$ The 255 byte limit is not intended for it to be a challenge to fit your code in that space, that's pretty doable in most any language. The idea is you can't stuff your code with a gigabytes of comments to simply reduce the chance of a important character being deleted. \$\endgroup\$
    – mousetail
    Aug 10 at 12:32
1
5 6
7
8 9
138

You must log in to answer this question.

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