578
\$\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\$
3
  • 1
    \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$ Commented May 15, 2024 at 14:05
  • 2
    \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29, 2024 at 13:27
  • \$\begingroup\$ I have been once submitted a question to sandbox and downvoted to -1, but after submitting it anyway it has 8-9 score right now. \$\endgroup\$ Commented Dec 5, 2025 at 18:13

5006 Answers 5006

1
23 24
25
26 27
167
3
\$\begingroup\$

Quantise a list

In music production, quantisation is the process of "aligning" recorded notes to the beat, to remove the variability caused by imprecise human playing.

In this challenge, we will implement an abstract and approximate version of quantisation, representing notes as runs of positive integers, and using zeroes to represent gaps. The "beat" will be defined as every second note, starting with the first (even indices, 0-based).

Given a list of non-negative integers, insert or remove zeroes such that every run of non-zeroes begins on an even index (using 0-based indexing).

Runs of non-zeroes may not be split or joined together if they weren't already in the input. In other words, a zero cannot be inserted or removed if it only has non-zeroes next to it.

The minimal number of insertion/removal operations must be performed. If a removal is possible, it should be preferred over an insertion.

Test cases

todo

blah blah code golf rules

\$\endgroup\$
6
  • \$\begingroup\$ Removal of double negatives: "No runs of non-zeroes may be split..." -> "Runs of non-zeroes may not be split...", maybe also "...zero cannot be inserted or removed if it only has non-zeroes..." -> "...zero can only be inserted or removed if it has at least one zero..." \$\endgroup\$ Commented Aug 30, 2022 at 17:24
  • \$\begingroup\$ The latter conversion is incorrect, because [0, 3, 4] can become [3, 4] because the zero has an end-of-the-list next to it rather than a zero. I agree this could be clearer though \$\endgroup\$ Commented Aug 30, 2022 at 19:28
  • \$\begingroup\$ that's not supported by the current phrasing either: "a zero cannot be inserted or removed if it only has non-zeroes next to it". If that zero can be removed, you're saying it has something other than non-zeros next to it, which means you're saying that either "end-of-the-list"s or 3s are zero. Addendum: my head hurts \$\endgroup\$ Commented Aug 30, 2022 at 19:34
  • 1
    \$\begingroup\$ @thejonymyster My head hurts too and now you see why lol. The way I drafted this in my head is slightly different from how I wrote it down, which doesn't help \$\endgroup\$ Commented Aug 30, 2022 at 19:38
  • \$\begingroup\$ Maybe instead of splitting / joining runs, just say the number of runs of nonzeros cant change between input and output. That handles the 0s on the ends situations too and is probably simpler \$\endgroup\$ Commented Aug 30, 2022 at 19:41
  • \$\begingroup\$ I mean, the first sentence (before "in other words") explains it pretty well already. Maybe I should just remove the second rephrasing. \$\endgroup\$ Commented Aug 30, 2022 at 19:45
3
\$\begingroup\$

Zip two arrays

Given a list of arrays of the same dimension, zip them at the lowest level. That is, you should output an array of the same dimension, for which the value at each index is a list of the corresponding elements in the input arrays.

For example, for two 3x3 arrays

[[123]  [[abc]    [[[1a][2b][3c]]
 [456] , [def]  →  [[4d][5e][6f]]
 [789]]  [ghi]]    [[7g][8h][9i]]]

and for the three 4x4 arrays

[[19  47  4   69 ]  [[103 67  17  28 ]  [[7   9   48  204]
 [156 120 54  104]   [167 80  99  62 ]   [26  125 230 212]
 [30  70  212 96 ] , [102 165 246 192] , [61  118 137 101]
 [62  80  152 205]]  [118 193 222 65 ]]  [125 247 209 31 ]]
 ↓
[[[19  103 7  ] [47  67  9  ] [4   17  48 ] [69  28  204]]
 [[156 167 26 ] [120 80  125] [54  99  230] [104 62  212]]
 [[30  102 61 ] [70  165 118] [212 246 137] [96  192 101]]
 [[62  118 125] [80  193 247] [152 222 209] [205 65  31 ]]]

Test cases

todo

Sandbox notes

  • This feels like something that should've already been posted.
  • Name/wording suggestions?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ To me, it makes more sense to say "Zip arrays at the lowest level" or "Transpose array at the lowest level" or "Multi-dimensional transpose" instead of "Combine" \$\endgroup\$ Commented Sep 1, 2022 at 0:20
  • \$\begingroup\$ It is one special case of APL dyadic transpose (challenge), and precisely BQN transpose. \$\endgroup\$ Commented Sep 1, 2022 at 0:27
  • \$\begingroup\$ @Bubbler Indeed ;) \$\endgroup\$ Commented Sep 1, 2022 at 0:53
3
\$\begingroup\$

Solve a jigsaw puzzle

\$\endgroup\$
3
  • \$\begingroup\$ I am always in favour of loose I/O criteria, so I'd definitely include the first three dots and also leave up to answerers the value fir edges (not restricting to numbers, some may use NA or Inf, or even "a", but I'd keep it consistent). Anyway, I suggest placing the example between paragraphs 2 and 3 (so that I/O rules are after the example). Also, you may want to specify what to do with multiple solutions (if such inputs are possible). \$\endgroup\$ Commented Aug 1, 2022 at 18:30
  • \$\begingroup\$ I have I feeling that I saw a challenge like this before, but I cannot find it. So maybe there isn't one. \$\endgroup\$ Commented Aug 1, 2022 at 18:32
  • \$\begingroup\$ @pajonk I think this counts as a duplicate: codegolf.stackexchange.com/questions/48819/… \$\endgroup\$ Commented Aug 23, 2022 at 16:54
3
\$\begingroup\$

Compute the Fabius function

  • \$f(x)\$ always takes on rational values at dyadic rationals (i.e. \$\frac m{2^n}\$ with \$m,n\in\mathbb Z\$). It could also be interesting to restrict input to such values, and ask for a rational output.
\$\endgroup\$
6
  • \$\begingroup\$ Forgive my ignorance, but is it even possible to exactly determine the value of the function for any given input \$x\$? \$\endgroup\$ Commented Sep 5, 2022 at 23:03
  • \$\begingroup\$ @97.100.97.109 What do you mean by "exactly"? There do exist algorithms which can approximate the value of \$f\$ to arbitrary precision for any given input. For example, from math se \$\endgroup\$ Commented Sep 5, 2022 at 23:22
  • \$\begingroup\$ I suppose the answer to my question is "no" (when the input is not a dyadic rational). In that case, how do solvers decide the level of precision with which to calculate the answer? I think that limiting to dyadic rationals is a good idea because then there is an explicit formula to calculate the values. \$\endgroup\$ Commented Sep 5, 2022 at 23:38
  • \$\begingroup\$ @97.100.97.109 I don't think the absence of an explicit, non-limiting formula should be a factor in that decision. How would you "exactly" calculate \$\sin\$ for arbitrary inputs? \$\endgroup\$ Commented Sep 5, 2022 at 23:44
  • \$\begingroup\$ I think it can make two challenges actually: first with f on dyadic rationals asking for rational output (no floating point errors); second with f at any input with stated required precision (maybe limited to interval 0-1). \$\endgroup\$ Commented Sep 7, 2022 at 19:51
  • \$\begingroup\$ I'd prefer keeping the function to [0,1] where it is defined by the cumulative distribution. \$\endgroup\$ Commented Sep 10, 2022 at 22:08
3
\$\begingroup\$

Convert integer to IEEE 754 float

The task is simple, given a 32 bit integer, convert it to its floating point value as defined by the IEEE 754 (32-bit) standard.

IEEE 754

Here is a converter for your reference.

Here is how the format looks:

The standard is similar to scientific notation.

The sign bit determines whether the output is negative or positive. If the bit is set, the number is negative otherwise it is positive.

The exponent bit determines the exponent (base 2), it's value is offset by 127. Therefore the exponent is \$2^{n-127}\$ where n is the integer representation of the exponent bits.

The mantissa defines a floating point number in the range \$[1,2)\$. The way it represents the number is like binary, the most significant bit is \$\frac 1 2\$, the one to the right is \$\frac 1 4\$, the next one is \$\frac 1 8\$ and so on... A one by default is added to the value.

Now the final number is: $$\text{sign}\cdot 2^{\text{exponent}-127}\cdot \text{mantissa}$$

Test cases

1078523331 ->   3.1400001049041748046875
1076719780 ->   2.71000003814697265625
1036831949 ->   0.100000001490116119384765625
3264511895 -> -74.24919891357421875
1056964608 ->   0.5
3205496832 ->  -0.5625

For this challenge assume that cases like NaN and inf are not going to be the inputs, and subnormals need not be handled, and you may output 0 for the case where the number represented is -0.

This is code-golf, so the shortest answer in bytes wins.

\$\endgroup\$
5
  • \$\begingroup\$ Closely related. Kinda opposite task, but I think there are certainly overlapping techniques around reinterpreting a bit pattern from one type to another. \$\endgroup\$ Commented Sep 22, 2022 at 0:22
  • \$\begingroup\$ I don't quite understand what this challenge is asking for. Are we supposed to reinterpret the integer as a float? \$\endgroup\$ Commented Oct 2, 2022 at 21:51
  • \$\begingroup\$ @pigrammer yes. \$\endgroup\$ Commented Oct 3, 2022 at 3:42
  • \$\begingroup\$ @solid.py shouldn't all the digits be accurate, because there is no floating point conversion error when you are reinterpreting an integer as a float \$\endgroup\$ Commented Oct 9, 2022 at 10:33
  • \$\begingroup\$ @solid.py 1/2 + 1/4 + 1/8 + ... should be accurately stored, because, well it can be accurately represented by IEEE754, which is supported by most languages... \$\endgroup\$ Commented Oct 10, 2022 at 15:51
3
\$\begingroup\$

Hexadecimal -> Binary Art

\$\endgroup\$
8
  • \$\begingroup\$ Is 10000001 actually 81? A simple web search shows 81 is 1010001 \$\endgroup\$ Commented Sep 30, 2022 at 9:38
  • \$\begingroup\$ -1 because of that \$\endgroup\$ Commented Sep 30, 2022 at 9:39
  • \$\begingroup\$ @py3programmer Since hexadecimal is in base sixteen, hexadecimal 81 is 10000001. \$\endgroup\$ Commented Sep 30, 2022 at 14:27
  • \$\begingroup\$ @py3programmer no. Hexadecimal is base 16. I've edited the post so you can remove your downvote. \$\endgroup\$ Commented Sep 30, 2022 at 14:30
  • \$\begingroup\$ There's a different way to calculate binary numbers in base 16? I didn't know that. \$\endgroup\$ Commented Oct 1, 2022 at 2:46
  • 1
    \$\begingroup\$ @py3programmer 81 in base 16 isn't the same as 81 in base 10, the same way that, e.g. 10 in binary is not equal to 10 in decimal. 81 in base 16 is 8*16+1 = 129 in decimal, which is indeed 10000001 in binary. \$\endgroup\$ Commented Oct 2, 2022 at 18:59
  • \$\begingroup\$ Since 16 is a power of 2, you can also convert each character individually into binary then concatenate -- 8 -> 1000, 1 -> 0001, 81 -> 10000001. \$\endgroup\$ Commented Oct 2, 2022 at 19:18
  • \$\begingroup\$ Yeah, I get you. I was think more in Python terms, bin(81) instead of bin(0x81) \$\endgroup\$ Commented Oct 3, 2022 at 3:58
3
\$\begingroup\$

Find a word in the dictionary of all possible words

\$\endgroup\$
3
  • \$\begingroup\$ Can input use strings? (e.g. 123 and 231 for your example) \$\endgroup\$ Commented Oct 2, 2022 at 21:47
  • \$\begingroup\$ @pigrammer that's a default input method and thus should be fune \$\endgroup\$ Commented Oct 2, 2022 at 22:00
  • \$\begingroup\$ @solid.py that should be fine so long as tuples of arbitrary length can be handled \$\endgroup\$ Commented Oct 4, 2022 at 19:19
3
\$\begingroup\$

Generate QR code from string

I'm surprised to have not seen anyone doing this particular challenge yet.

The challenge is simple: Take input as a string, your task is to turn it into a QR code.

This challenege originally requires outputting to an image (or any graphical output), but to relax the restrictions down, you only need to output the result as a matrix (or a 2D array). A binary string (with splits between) is also acceptable.

And for sake of simplicity, you will only need to output a 25x25 QR code image (which is the most popular QR code size, I believe). For the input Version 2, the image should look like this:

Version 2 QR code on Wikipedia

You may not need to handle empty strings.

Standard loopholes are forbidden.

More resources

\$\endgroup\$
13
  • \$\begingroup\$ Can we output as a binary string \$\endgroup\$ Commented Oct 9, 2022 at 9:28
  • \$\begingroup\$ @py3programmer No, the output string must be full, correct image data. If you are using a binary string to later be used with metadata to output to a, say bitmap file, then yes, you can. \$\endgroup\$ Commented Oct 9, 2022 at 10:06
  • \$\begingroup\$ You may consider turning this into a binary-matrix challenge instead. It would be easier to test on TIO and the like. \$\endgroup\$ Commented Oct 9, 2022 at 21:02
  • \$\begingroup\$ Also, it would need to be significantly more specified. Which version of QR code? Which kind of data? With which error correction level? (Challenges are supposed to be self-contained. So, ideally, the full algorithm should be explained.) \$\endgroup\$ Commented Oct 9, 2022 at 21:05
  • \$\begingroup\$ @oeuf I meant a binary string that describes whether each pixel is lighted up or not. The binary string would describe the pixels from left to right. Is that valid? \$\endgroup\$ Commented Oct 10, 2022 at 3:50
  • \$\begingroup\$ @py3programmer Perhaps yes. I will take some time to think about this. \$\endgroup\$ Commented Oct 10, 2022 at 5:32
  • 1
    \$\begingroup\$ @Arnauld I have edited to relax the output restrictions down and specify more about the output. Thanks for suggestion! I am currently deciding on the error correction level \$\endgroup\$ Commented Oct 10, 2022 at 6:08
  • \$\begingroup\$ Don't we need 2 inputs? One for the version, and one for the string we need to encode the qr code with? \$\endgroup\$ Commented Oct 10, 2022 at 7:01
  • \$\begingroup\$ @py3programmer No, we only need one input for the string. \$\endgroup\$ Commented Oct 10, 2022 at 7:14
  • \$\begingroup\$ So you mean that using version 2, you'll encode the input as a QR code? \$\endgroup\$ Commented Oct 10, 2022 at 7:17
  • \$\begingroup\$ @py3programmer Yes. \$\endgroup\$ Commented Oct 10, 2022 at 7:18
  • \$\begingroup\$ Can one use built-in libraries that generate QR codes? I think that the real would be to compute the image/matrix \$\endgroup\$ Commented Oct 17, 2022 at 14:50
  • \$\begingroup\$ @matteo_c Builtins are allowed, but builtins that solves the entire problem are generally disencouraged. \$\endgroup\$ Commented Oct 18, 2022 at 4:50
3
\$\begingroup\$

Integer Bluffing (Still a draft)

It's an exciting night at the IGS casino, as a brand new table game is being revealed - Integer Bluffing. Bots from all over the network have come to have a chance at playing the inaugral game, and luckily for you, you just happen to have a seat at the table.

The Rules of Integer Bluffing

At the beginning of a game of Integer Bluffing, each player starts with 20 tokens. A round of Integer Bluffing consists of 4 phases: (i) the deal, (ii) declaring, (iii) reacting, (iv) the showdown

The Deal

Each round, 1 player is chosen to pay an ante, which increases during the game, into the pot. A random integer in the range [1, 8] is then "dealt" to each player. Players only know the true value of their own integer, and once an integer is given to a player, it can't be dealt to anyone else.

Declaring

Starting with the player after the player who paid the ante, each player has the choice to either: a) decline to play the round (fold) or b) put 1 token into the pot and declare what their integer is (play).

Here's the twist - if choosing to play, the player doesn't have to tell the truth about the value of their integer - they can lie and declare they have an integer they don't have. The player also sets a flag whether they say they are bluffing or not - this can also be lied about.

Consider the following game with players A, B, C and D:

Player Integer
A 4
B 2
C 7
D 3

Assuming Player A paid the ante for the round, player B goes first in the declaring round. Player B sees that they have a 2, which is highly unlikely to win against other integers, so they fold.

Player C sees that they have a 7, so they choose to play the round. Wanting to trick Players D and A into putting a token into the pot, C declares that they have 2, and states they are not bluffing.

Player D sees that Player C allegedly has 2 and that they aren't bluffing. Player D knows that 3 is higher than 2, but knows that Player A might have a higher integer. Therefore, Player D decides to declare 6, not bluffing, in the hopes that Player A folds.

TODO: Continue writing

\$\endgroup\$
2
  • \$\begingroup\$ "new table game"? Pfff, I've played this before :3 \$\endgroup\$ Commented Oct 14, 2022 at 13:28
  • \$\begingroup\$ You should state the number of players at the table (always exactly 4?), probably in the "The Rules of Integer Bluffing". I also think this sentence: "The player also sets a flag whether they say they are bluffing or not" should be reworded. I think "The player may also set a flag to say they are bluffing" works. \$\endgroup\$ Commented Oct 14, 2022 at 19:58
3
\$\begingroup\$

Triangular polkadot numbers

\$\endgroup\$
3
\$\begingroup\$

Tic, Tac, stub your Toe

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to Code Golf, and thanks for using the Sandbox! Currently, this is missing a winning criterion. If it's code-golf, you should probably specify. \$\endgroup\$ Commented Oct 26, 2022 at 4:12
  • 1
    \$\begingroup\$ I'd also recommend allowing looser I/O formats - see here. It's your challenge though, so if you really want to keep the strict formats, that's okay. \$\endgroup\$ Commented Oct 26, 2022 at 4:17
  • \$\begingroup\$ Don't know how to add tags to specify which type so right now it's just fastest possible solution wins. Also will update to remove number of testcases and commas from input. \$\endgroup\$ Commented Oct 26, 2022 at 14:14
3
\$\begingroup\$

Is this series of quotes valid python?

Python string parsing has quite a few edge cases. This is a string:

"a"

Putting 2 strings immediately after each other implicitly concatenates them, so this is also a string:

"a""a"

However, if you put 3 quotes in a row, it will create a "triple quoted string" which can only be ended by another triple quoted string. A triple quoted string can contain other quotes. These quotes will not end the string unless there are 3 of them. Thus this is valid:

"""a"a"""

Of course, you can combine these together, so this is a valid string:

"""a""""a"

And this:

"""""aaa"""""""""

A string is not valid if:

  1. Any a appears outside of a string literal (would get SyntaxError: invalid syntax in python) OR
  2. The end of the sequence is inside a string literal (would get SyntaxError: unterminated string literal (detected at line 1) in python)

Your task

Given a string containing 2 distinct characters, one representing a double quote and another representing any alphanumeric character, determine if it would be a valid python string, or invalid syntax.

You do not need to consider single quotes or how double and single quotes normally interact.

A array of booleans or a array of bytes would also be a valid input method.

This is , shortest answer wins.

Test Cases

Truthy Falsy
"a" (1-1) "a (1)
"a""a" (1-2-1) "a"a" (1-1-1)
"""a"a""" (3-1-3) ""a"a""" (2-1-3)
"""a""""a" (3-4-1) """a"""a" (3-3-1)
"""""aaa""""""""" (5-9) """""aaa"""""""" (5-8)
"""""""""""" (12) """"""aaa""""""""" (6-8)
"a""a""a""a" (1-2-2-2-1) """" (4)
"a""" (1-3)

eval or exec or ast.literal_eval would be valid answers, though I hope to see more creative python answers as well.

\$\endgroup\$
21
  • \$\begingroup\$ Well, well, well... exec can be used, so I'm claiming that. Ha! \$\endgroup\$ Commented Oct 26, 2022 at 12:02
  • 2
    \$\begingroup\$ Ok go for it. Not sure if I would count that as creative though \$\endgroup\$ Commented Oct 26, 2022 at 12:03
  • \$\begingroup\$ But the problem with this is, lambdas are not going to work in Python, and neither can normal functions. LHS = SyntaxError = RHS -> hence proved that eval and exec 4 byters are not valid. \$\endgroup\$ Commented Oct 26, 2022 at 12:06
  • \$\begingroup\$ And neither will normal inputs. Therefore, python would not work at all for this program, as input cannot only be provided. \$\endgroup\$ Commented Oct 26, 2022 at 12:07
  • \$\begingroup\$ Of course python works? You can take input as a string containing quotes \$\endgroup\$ Commented Oct 26, 2022 at 12:08
  • \$\begingroup\$ Though I assume it could be made to work in online interpreters like TIO and ATO, but not in IDLE style. \$\endgroup\$ Commented Oct 26, 2022 at 12:08
  • \$\begingroup\$ "string containing quotes": won't the string itself contain quotes? Like "a"a" when passed to an argument would be '"a"a"' \$\endgroup\$ Commented Oct 26, 2022 at 12:09
  • \$\begingroup\$ Notice the '? \$\endgroup\$ Commented Oct 26, 2022 at 12:10
  • \$\begingroup\$ The string will contain only double quotes. \$\endgroup\$ Commented Oct 26, 2022 at 12:11
  • \$\begingroup\$ Nod nod so when are you posting this? \$\endgroup\$ Commented Oct 26, 2022 at 12:15
  • \$\begingroup\$ When I get 3-4 votes \$\endgroup\$ Commented Oct 26, 2022 at 12:17
  • \$\begingroup\$ Hey why'd you claim exec? \$\endgroup\$ Commented Oct 27, 2022 at 6:42
  • \$\begingroup\$ Because it's boring. Note that duplicate answers are technically allowed but don't expect any votes \$\endgroup\$ Commented Oct 27, 2022 at 6:52
  • \$\begingroup\$ But it wasn't your idea to use it... I had to rack my brain for a minute to figure out an alternative approach :( \$\endgroup\$ Commented Oct 27, 2022 at 11:10
  • \$\begingroup\$ I consider it equivalent to eval, it's basically the same thing. \$\endgroup\$ Commented Oct 27, 2022 at 11:24
3
\$\begingroup\$

Does the sequence shut the box?

\$\endgroup\$
4
  • \$\begingroup\$ small nitpicks: "roles" should be "rolls", "d6 dice" is redundant and should probably just be "six sided dice", and [] input is an edge case, and i think we should probably be able to assume input wont be empty. \$\endgroup\$ Commented Oct 10, 2022 at 21:58
  • \$\begingroup\$ actual feedback: cool challenge idea :-) a worked out example of how a specific sequence could be used to shut the box would be very helpful in allowing everyone to understand the challenge more \$\endgroup\$ Commented Oct 10, 2022 at 21:58
  • \$\begingroup\$ Thanks for the feedback. I cleaned those things up and added the example. Personally I like the inclusion of the [] input as it adds more thinking to the golfing (can one save bytes by formulating the general case to include the edge case). But I admit it may be weird to say "not playing the game is not a winning sequence". \$\endgroup\$ Commented Oct 10, 2022 at 23:29
  • \$\begingroup\$ ultimately up to you :-) thanks for humoring me :P \$\endgroup\$ Commented Oct 11, 2022 at 2:03
3
\$\begingroup\$

50 digits of π in HQ0-9+-INCOMPUTABLE?

\$\endgroup\$
2
  • \$\begingroup\$ Sorry few questions: are those the only commands avaiable? How would I append to the buffer then if I didn't want to use q/Q? \$\endgroup\$ Commented Nov 11, 2022 at 0:18
  • \$\begingroup\$ @DialFrost 1) Yes. 2) It's your job to figure it out. \$\endgroup\$ Commented Nov 11, 2022 at 0:19
3
\$\begingroup\$

Totally random Catan number distributions

\$\endgroup\$
3
\$\begingroup\$

Base Neutral Numbering System

\$\endgroup\$
3
  • \$\begingroup\$ Can we output as a nested list? Like <<1> * <<1>>> = [[[1],[[1]]]] \$\endgroup\$ Commented Nov 22, 2022 at 20:40
  • \$\begingroup\$ Also, can we omit the *? Most of the test cases omit it, only the last two use it. \$\endgroup\$ Commented Nov 22, 2022 at 20:41
  • \$\begingroup\$ Omitting the * from the test cases was a mistake. I think [[[1],[[1]]]] already qualifies by my rules since I allow replacing <> with [] and * with , . \$\endgroup\$ Commented Nov 22, 2022 at 21:08
3
\$\begingroup\$

Turn two dice into one die

\$\endgroup\$
4
  • \$\begingroup\$ Is it guaranteed that target is divisible by die1 * die2? Seems all your test cases assume so \$\endgroup\$ Commented Dec 8, 2022 at 10:42
  • 1
    \$\begingroup\$ What if there are multiple possibilities? Or will the input configuration guarantee an unique solution? \$\endgroup\$ Commented Dec 8, 2022 at 11:16
  • \$\begingroup\$ @mousetail that issue is already addressed in the assumptions: "assume N is a divisor of A*B" \$\endgroup\$ Commented Dec 8, 2022 at 20:25
  • \$\begingroup\$ @pajonk if there are multiple solutions (such as making a one-sided), you only need to return one of them. I will clarify that in the post. I have not proven mathematically if there are unique solutions for the examples in the post, but I will postulate that they are (up to permutation) \$\endgroup\$ Commented Dec 8, 2022 at 20:27
3
\$\begingroup\$

KotH: Build an Organism

A while back, I made a thing that simulates a world, with a bunch of organisms with randomly chosen genes:

dieplife

These would code for things like how the organism would manage resources (such as sugar, water, and starch), whether it could photosynthesize, hunt, run away from enemies, or defend itself using tough materials like wood or stone spikes.

In this challenge, you'll design an organism which can effectively survive. This could be through strategies including:

  • Being an effective hunter, chasing down and killing prey
  • Being difficult to attack, such as by having tough armor and fleeing from stronger organisms
  • Growing and dividing too quickly for it to be possible that all organisms of your species are killed at the same time

I will update this post with a spec listing all available resources, materials, genetic traits, and actions later.

\$\endgroup\$
1
  • \$\begingroup\$ this seems fun. \$\endgroup\$ Commented Dec 23, 2022 at 20:18
3
\$\begingroup\$

Change the subject

Posted here

\$\endgroup\$
4
  • \$\begingroup\$ Nice challenge! Is it guaranteed that there will be an order in which each sentence connects to the next? \$\endgroup\$ Commented Jan 15, 2023 at 19:02
  • 1
    \$\begingroup\$ @TheThonnu Yes, I'll add that to the challenge rules \$\endgroup\$ Commented Jan 15, 2023 at 19:19
  • \$\begingroup\$ How are words defined in a sentence? Space separated or any non-letter/punctuation separated? \$\endgroup\$ Commented Jan 16, 2023 at 4:31
  • \$\begingroup\$ @lyxal, to not make things too complicated, they will just be space separated. But the first and last words of the sentence can be compared with the others as well, and the first word starts with a capital letter while the last word ends with a period. I'll clarify this in the challenge. \$\endgroup\$ Commented Jan 16, 2023 at 13:58
3
\$\begingroup\$

Simplify a Cycle

\$\endgroup\$
13
  • 2
    \$\begingroup\$ A worked out example would be great. I don't get why aren't all vertices from the input in the output. \$\endgroup\$ Commented Aug 19, 2022 at 8:16
  • \$\begingroup\$ Is this really "given a path that may include cycles, remove the cycles"? \$\endgroup\$ Commented Aug 19, 2022 at 8:42
  • 1
    \$\begingroup\$ @UnrelatedString no, it's "given a cycle between two vertices, return the shortest cycle" \$\endgroup\$ Commented Aug 19, 2022 at 8:43
  • 3
    \$\begingroup\$ The last test case seems to contradict that, since the shortest cycle between 1 and 7 seems like it should just be [1,2,7]. I guess what I'm getting at is there needs to be a clearer spec and/or worked through example :P \$\endgroup\$ Commented Aug 19, 2022 at 8:47
  • \$\begingroup\$ So is this a 1-D graph or what? Are you only giving us the X coordinates or what? Or am I just not understanding a thing? If we have the coordinates (both X and Y) is this basically removing adjacent coordinates that are colinear? \$\endgroup\$ Commented Aug 19, 2022 at 15:50
  • \$\begingroup\$ @Steffan these numbers arent coordinates; they're just the labels on the nodes of the graph. the input is a path that exists on the graph, meaning you can get from each node in the list to the next node in the list by following a single edge \$\endgroup\$ Commented Aug 22, 2022 at 2:35
  • \$\begingroup\$ Maybe an example program will help. \$\endgroup\$ Commented Aug 26, 2022 at 14:29
  • \$\begingroup\$ Questions for @lyxal . \$\endgroup\$ Commented Aug 26, 2022 at 14:39
  • \$\begingroup\$ Suppose his answers are what I expect, this should work. \$\endgroup\$ Commented Aug 26, 2022 at 14:40
  • \$\begingroup\$ It was at 4 char left. Sorry for another post. Why must [1,2,7,2,7,2,3,7] be [1,2,3,7] ([1,2,...,3,7]) and not [1,2,7] ([1,2,7,...])? \$\endgroup\$ Commented Aug 26, 2022 at 14:42
  • \$\begingroup\$ The mathematical definition deems that both are correct. You might want to clarify or add that to the test case. \$\endgroup\$ Commented Aug 26, 2022 at 14:42
  • \$\begingroup\$ E \$\endgroup\$ Commented Aug 26, 2022 at 14:44
  • \$\begingroup\$ ...dited to match the test cases. The last post was too long. \$\endgroup\$ Commented Aug 26, 2022 at 14:44
3
\$\begingroup\$

Change the Temperature of Swatchlings

Warning: Contains Deltarune Chapter 2 Spoilers

Summary

Your challenge today is to determine the minimum number of turns needed to change the temperatures of an arbitrary amount of Swatchlings to all be the same.

Context

In the second chapter of Deltarune, there are enemies you encounter that are called Swatchlings (suit-wearing butler-like characters that serve the main antagonist of the chapter). These enemies always appear in battle in groups with at least one outlier in terms of suit colorsource. Swatchlings are defeated by making all Swatchlings in the group have the same suit colour.

Each Swatchling's color can be changed in stages, either becoming warmer (redder) or colder (bluer). While there are only five colours in the actual game, for this challenge, there will be an infinite amount, represented by positive integers.

During each turn of a battle, there are 3 ways to change the temperature of a Swatchling: increasing/decreasing the temperature by 2 stages, increasing the temperature by 1 stage or decreasing the temperature by 1 stage. You may perform up to 3 of these actions per turn, and no action twice in a turn.

Task and Worked Example

Given a list of Swatchling temperatures, determine the minimal number of turns needed to change the temperatures of all Swatchlings to be the same. Note that

For example, given the following temperatures:

[1, 5, 5]

The optimal solution would be:

Turn 1:
Increase Swatchling #1 by 2 stages: [3, 5, 5]

Turn 2:
Increase Swatchling #1 by 2 stages: [5, 5, 5]

Meaning a minimum of 2 turns are needed to change the temperatures of all Swatchlings to be the same.

Another example is:

[1, 5, 3, 4, 4, 2, 1]

One optimal solution might be:

Turn 1:
Increase Swatchling #1 by 2 stages: [3, 5, 3, 4, 4, 2, 1]
Decrease Swatchling #4 by 1 stage: [3, 5, 3, 3, 4, 2, 1]
Increase Swatchling #6 by 1 stage: [3, 5, 3, 3, 4, 3, 1]

Turn 2:
Decrease Swatchling #2 by 2 stages: [3, 3, 3, 3, 4, 3, 1]
Decrease Swatchling #5 by 1 stage: [3, 3, 3, 3, 3, 3, 1]

Turn 3:
Increase Swatchling #7 by 2 stages: [3, 3, 3, 3, 3, 3, 3]

Meaning a minimum of 2 turns are needed to change the temperatures of all Swatchlings to be the same.

Rules

  • Input will be a list of positive integers representing the temperatures of each Swatchling. The list will contain at least one Swatchling.
  • Output will be an integer representing the minimum number of turns needed to change the temperatures of all Swatchlings to be the same.

Test Cases

[1, 5, 5] => 2
[1, 2, 5] => 1
[1, 5, 3, 4, 4, 2, 1] => 3
[1, 7] => 2
[1, 10, 3] => 4

As this is , the aim of the game is to get y'all's byte count as low as possible, just like the turn count to make all the Swatchlings the same temperature.

Sandbox Meta

  • Is the explanation clear enough?
\$\endgroup\$
5
  • \$\begingroup\$ For your first case, can't you decrease #3 by 2, decrease it by 1 again, and increase #1 by 1? \$\endgroup\$ Commented Jul 2, 2022 at 0:09
  • \$\begingroup\$ @emanresuA huh, so you can. Just tested it in deltarune lol \$\endgroup\$ Commented Jul 12, 2022 at 13:43
  • \$\begingroup\$ I'm assuming the line after the solution for [1, 5, 3, 4, 4, 2, 1] should say "Meaning a minimum of 3 turns are needed..." \$\endgroup\$ Commented Jul 15, 2022 at 19:01
  • \$\begingroup\$ Is [2,5,5] 1 or 2, or say is multiple operating on one item allowed in one turn? \$\endgroup\$ Commented Jan 22, 2023 at 7:44
  • \$\begingroup\$ [1, 10, 3] should be 3 if I understand it correctly. [1, 10, 3] => [3, 8, 4] => [5, 6, 4] => [5, 5, 5] \$\endgroup\$ Commented Jan 22, 2023 at 16:46
3
\$\begingroup\$

Definitions

A \$ \xi \$-word is defined as a string of letters such that every letter in the string appears an even number of times. For example, aeaeccaa is a \$ \xi \$-word.

The function \$ T \$, which operates on \$ \xi \$-words, is defined as follows:

  1. Replace the odd-positioned (first, third, etc.) occurrences of each letter with (. For the example above, this produces ((ae(c(a
  2. Replace all the remaining letters (i.e., those that were the even occurrences) with ). For our example, this produces (())()()

This will always produce a string with balanced brackets.

Task

Take, as input, a string \$ i \$, where every letter appears exactly twice (e.g. xffcxc). Note that this is a stricter condition than merely being a \$ \xi \$-word.

Return the lexicographically earliest \$ \xi \$-word, such that the input and output give the same value when \$ T \$ is applied to them.

Hint: a linear-time algorithm is possible.

Rules

  • You do not need to handle an empty input
  • Letters are ASCII lowercase (a to z)
  • You may choose to operate on integers instead of strings of letters. You can use any set of integers, as long as there are at least 26 of them.
  • You may use any standard I/O method
  • Standard loopholes are forbidden
  • This is , so the shortest code in bytes wins

Test cases

todo


Sandbox notes

At the moment, this challenge is very abstract, which I think means it will look seem quite boring (until you start to actually solve it, which I think is fun, although fairly simple). (What kind of a title is Lexicographically earliest \$ T \$-invariant \$ \xi \$-word?)

If you can think of a good domain to make it concrete, I think it would be much better. (Unfortunately I can't reveal the original context in which I encountered it). At the least I will probably replace the symbolic names with cute names before posting.

\$\endgroup\$
2
  • \$\begingroup\$ How do you pronounce that? \$\endgroup\$ Commented Jan 23, 2023 at 16:19
  • 1
    \$\begingroup\$ @Jacob According to Google Translate, it's pronounced "she". \$\endgroup\$ Commented Feb 9, 2023 at 18:15
3
\$\begingroup\$

Yakko's New World Order

\$\endgroup\$
5
  • 2
    \$\begingroup\$ I don't think allowing outputting the indices into the list should be allowed \$\endgroup\$ Commented Jan 24, 2023 at 21:11
  • \$\begingroup\$ @RydwolfPrograms Why not? \$\endgroup\$ Commented Jan 24, 2023 at 21:17
  • \$\begingroup\$ Everybody's just going to do that, and that rules out some interesting approaches involving the text itself (such as using some sort of custom digest as a sorting key). \$\endgroup\$ Commented Jan 24, 2023 at 21:18
  • \$\begingroup\$ Given a list of countries in alphabetical order -> are we always given the full list, or could it be a subset of this list? \$\endgroup\$ Commented Jan 29, 2023 at 20:23
  • \$\begingroup\$ @Arnauld You are always given the full list. (If you want, you can ignore the input completely.) \$\endgroup\$ Commented Jan 29, 2023 at 21:12
3
\$\begingroup\$

Sum of Consecutive Squares

\$\endgroup\$
3
\$\begingroup\$

Infinite Apple Dilemma

Posted here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Are the third and fourth test-cases correct? - I get different results. Maybe the 20 and 30 are swapped? \$\endgroup\$ Commented Feb 9, 2023 at 14:40
  • \$\begingroup\$ @pajonk right lol \$\endgroup\$ Commented Feb 9, 2023 at 14:52
  • \$\begingroup\$ Will all the steps result in integer apple numbers (step-by-step)? Currently it's not true for test cases 5 and 6. \$\endgroup\$ Commented Feb 9, 2023 at 16:58
  • \$\begingroup\$ @pajonk nope, ty \$\endgroup\$ Commented Feb 9, 2023 at 19:21
3
\$\begingroup\$

Base64 fixed point

It can be proven that there's exactly one string of infinite length that remain same after base64 encoding Vm0wd2QyUXlVWGxWV0d4V1YwZ...

Given \$n\$, output one of

  • the \$n\$-th character
  • the first \$n\$ characters
  • The whole string

\$\endgroup\$
8
  • \$\begingroup\$ I don't understand this at all \$\endgroup\$ Commented Jan 21, 2023 at 16:23
  • \$\begingroup\$ A strings that starts with the outputted string? Doesn't every string begin with itself? \$\endgroup\$ Commented Jan 21, 2023 at 16:33
  • \$\begingroup\$ @mousetail base64(x) starts with x \$\endgroup\$ Commented Jan 22, 2023 at 6:36
  • 1
    \$\begingroup\$ It is confusing that your link starts with V and the test cases start with m. Also, fastest-code requires specifying how exactly each submission will be scored codegolf.stackexchange.com/tags/fastest-code/info. \$\endgroup\$ Commented Jan 24, 2023 at 13:47
  • \$\begingroup\$ @pajonk The one starting with m is str.slice(\$3^0\$) \$\endgroup\$ Commented Jan 24, 2023 at 16:34
  • \$\begingroup\$ @pajonk Scoring thing isn't decided \$\endgroup\$ Commented Jan 24, 2023 at 16:35
  • \$\begingroup\$ I'm not sure this is exactly fastest code - "most computation in fixed time" rather than "fixed computation in least time". It should maybe be code-challenge restricted-time? \$\endgroup\$ Commented Jan 31, 2023 at 16:43
  • \$\begingroup\$ @pxeger Largest input successfully processed within a fixed time limit. \$\endgroup\$ Commented Jan 31, 2023 at 17:16
3
\$\begingroup\$

Rotate an Image

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Might want to clarify if exif-orientations are allowed \$\endgroup\$ Commented Feb 16, 2023 at 10:07
3
\$\begingroup\$

Reverse the polyglot, change the language.

\$\endgroup\$
3
\$\begingroup\$

Approximate a root of an odd degree polynomial

\$\endgroup\$
2
  • \$\begingroup\$ I've got a couple of answers so vote for to move to main page :p \$\endgroup\$ Commented Feb 18, 2023 at 19:32
  • \$\begingroup\$ The only note: usually \$a_i\$ means coefficient of polinomial \$\endgroup\$ Commented Feb 18, 2023 at 19:45
3
\$\begingroup\$

Whole Number Groups

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Where does 1/7 come from in the second example? \$\endgroup\$ Commented Feb 17, 2023 at 10:21
1
23 24
25
26 27
167

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.