569
\$\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

4562 Answers 4562

1
22 23
24
25 26
153
3
\$\begingroup\$

Find the winning Mormon Bridge card

Mormon Bridge (also called Oh Heck, similar to Oh H***) is a card game played (at least by me) with a standard Rook deck. A standard Rook deck includes cards 1-14 in 4 suits, which are black, red, green, and yellow, and a Rook card. Each round, a card is taken from the deck. It's suit is chosen as "trump." Then, players take turns playing cards. We'll call the suit of the first players card "sub-trump". If the Rook card is played, it wins. If trump was played, the highest trump card wins. Otherwise, the highest sub-trump card wins.

Your Goal

Your goal is to take input for:

  • Trump
  • Sub-trump
  • Cards played

and output the winning card. You may take input in any reasonable manner, swapping suit colors for numbers is fine, as is taking input for all cards played in order instead of separating the first card. , so shortest answer in bytes wins.

Test cases

(note that input can be taken in any reasonable format, these are written in a human-readable format.)

Trump: Red
Cards played: Red 4, Rook, Black 14, Yellow 7
Output: Rook

Trump: Green
Cards played: Red 14, Red 8, Green 2, Yellow 6
Output: Green 2

Trump: Yellow
Cards played: Red 5, Green 7, Red 12, Black 6
Output: Red 12

Meta

What tags should be on this? Are the rules clear enough?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think the rules are pretty clear. It would be great if you could add some examples of input => expected output \$\endgroup\$ Jun 7, 2022 at 21:14
  • 1
    \$\begingroup\$ @mathjunkie added test cases \$\endgroup\$
    – 00Her0
    Jun 8, 2022 at 1:05
3
\$\begingroup\$

Is it a valid list?

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Suggestion: allow input also with {} or (), maybe even allow separators to be spaces or semicolons. \$\endgroup\$
    – pajonk
    Jun 12, 2022 at 5:28
  • 1
    \$\begingroup\$ "Outputting by erroring/not erroring is not allowed" - I presume this is to prevent people from submitting solutions which are just eval. This tends not be a good approach, and I think solutions like eval are still interesting. Maybe instead you could ask that people post solutions which don't directly do any parsing into one Community Wiki answer, like is sometimes done for builtin answers to catalogue-style questions. [contd...] \$\endgroup\$
    – pxeger
    Jun 12, 2022 at 9:18
  • 1
    \$\begingroup\$ @pxeger Good idea :P \$\endgroup\$
    – emanresu A
    Jun 12, 2022 at 9:19
  • 1
    \$\begingroup\$ [...contd] But I think disallowing error output is not the right way to go about it, because (1) people will still post them, but wrapped in a try-catch or whatever, which is a no more interesting answer; and (2) people can write interesting answers which don't use eval, but which can be shorter using error output as a kind of "short-circuiting" output mechanism. \$\endgroup\$
    – pxeger
    Jun 12, 2022 at 9:20
  • \$\begingroup\$ Suggested falsey test-case: [[]][[]], which may erroneously be accepted by eval-like solutions \$\endgroup\$
    – pxeger
    Jun 12, 2022 at 12:22
  • \$\begingroup\$ @pxeger Added.. \$\endgroup\$
    – emanresu A
    Jun 12, 2022 at 19:46
3
\$\begingroup\$

backwardS_hybriD-snakE_kebaB-cameL_case

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

Fix my FizzBuzz

\$\endgroup\$
2
  • \$\begingroup\$ You need some more test cases, to cover: inputs that are already valid and don't need shuffling, inputs with only numbers, inputs with no numbers, inputs with FizzBuzz in them. \$\endgroup\$
    – pxeger
    Jun 26, 2022 at 16:40
  • \$\begingroup\$ @pxeger Done. (filler) \$\endgroup\$
    – emanresu A
    Jun 26, 2022 at 19:47
3
\$\begingroup\$

Simplify Rubik's Cube Moves

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

Infinite quote escaping sequence

Posted

\$\endgroup\$
15
  • \$\begingroup\$ "one of these sequences" - does this include the infinite string aa'a'a'...? Or do we have to output one of the numeric sequences? \$\endgroup\$
    – pxeger
    Jul 14, 2022 at 12:31
  • \$\begingroup\$ @pxeger one of the numeric sequences \$\endgroup\$ Jul 14, 2022 at 12:32
  • \$\begingroup\$ What does "connect the original string" mean? \$\endgroup\$
    – mousetail
    Jul 14, 2022 at 12:32
  • \$\begingroup\$ @mousetail I edited it - it should be concatenate \$\endgroup\$ Jul 14, 2022 at 12:33
  • \$\begingroup\$ I feel like the sentence is still confusing. I'm confused by the exact order. First the original string, then a "a", then the string surrounded by quotes right? \$\endgroup\$
    – mousetail
    Jul 14, 2022 at 12:35
  • \$\begingroup\$ @mousetail Yes. How should I phrase this? Is this better? \$\endgroup\$ Jul 14, 2022 at 12:36
  • \$\begingroup\$ Maybe include a example what it would look like after 1 or 2 iterations \$\endgroup\$
    – mousetail
    Jul 14, 2022 at 12:39
  • \$\begingroup\$ I don't understand the first step of the process. From the examples it just looks like you are doing the second step over and over. If I try to do it with the first step I just get an infinite sequence of 's. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 14, 2022 at 12:47
  • \$\begingroup\$ I rewrote the process as an algorithm in pseudocode. Is it clearer now? \$\endgroup\$ Jul 14, 2022 at 12:50
  • \$\begingroup\$ A worked out example of generating one of the iterations would be helpful. aa'a'a'aa''a''' is right about where you lose me, I'd like to see that one step-by-step \$\endgroup\$ Jul 14, 2022 at 12:55
  • \$\begingroup\$ It is now clearer, but I, at least, would prefer if you just described it in a normal way rather than using pseudocode. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 14, 2022 at 13:00
  • \$\begingroup\$ @WheatWizard I tried rewriting it. Is this clear? \$\endgroup\$ Jul 14, 2022 at 13:38
  • \$\begingroup\$ The commas helped a lot. I get it now :-) I still think a worked out example would be nice, but this is definitely easier to parse with the commas \$\endgroup\$ Jul 14, 2022 at 14:18
  • \$\begingroup\$ May I swap 0/1 for sequence 1? (Use 1 for non-quote, 0 for quote) \$\endgroup\$
    – tsh
    Jul 15, 2022 at 9:51
  • \$\begingroup\$ @tsh yes, I edited that in \$\endgroup\$ Jul 15, 2022 at 9:52
3
\$\begingroup\$

Shifted auto-sum

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

Runs of Ones (What Fun!)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Not sure if only on my browser: Width of ✓ and number are different. So last ✓ is under ] instead of 9. \$\endgroup\$
    – tsh
    Jul 26, 2022 at 5:55
  • \$\begingroup\$ Apparently, the monospace font doesn't include Unicode characters, oh well \$\endgroup\$ Jul 26, 2022 at 14:47
3
\$\begingroup\$

Remove redundant parenthesis

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Tags: balanced-string, string \$\endgroup\$
    – naffetS
    Jul 25, 2022 at 23:36
  • \$\begingroup\$ If there never will be an empty pair, you probably shouldn't give (abc((123))()) as an example. \$\endgroup\$ Aug 1, 2022 at 14:19
3
\$\begingroup\$

A better Hexagony template

\$\endgroup\$
4
  • \$\begingroup\$ 4000th answer to this question, hooray \$\endgroup\$ Aug 10, 2022 at 12:58
  • \$\begingroup\$ "For convenience, define \$a(0)=0\$ (for zero-sized grid)." \$a(0)=3\times0(0−1)+1=1\$ though. Does the \$n=1\$ output have to be *, or are we allowed to output . instead as well? In terms of output it doesn't really make sense, but for the formula it does (and it would save me 2 bytes in my prepared solution 😅). \$\endgroup\$ Aug 11, 2022 at 11:40
  • \$\begingroup\$ @Kevin I meant size 0 grid has zero spots and size 1 has one, but now that I think of it, I don't know if Hexagony interpreter special-cases empty code or it just treats it as size 1. Something to think about... \$\endgroup\$
    – Bubbler
    Aug 11, 2022 at 14:02
  • 1
    \$\begingroup\$ @KevinCruijssen I decided to allow both :) \$\endgroup\$
    – Bubbler
    Aug 11, 2022 at 22:56
3
\$\begingroup\$

CGCC Rocket Biking

\$\endgroup\$
5
  • \$\begingroup\$ Suggestion: Split it to two challenges (validating and generating instructions). \$\endgroup\$
    – pajonk
    Mar 27, 2022 at 18:00
  • \$\begingroup\$ Good challenge! Just one question: what does may not save the input while reading mean? Does "save" just mean saving to a file, or does it include variables too? In some languages, it would be impossible to do anything with input without saving it somewhere, even if not in an explicitly named variable. \$\endgroup\$ Mar 27, 2022 at 18:02
  • \$\begingroup\$ @pajonk That's a good idea, thanks! \$\endgroup\$ Mar 28, 2022 at 12:22
  • 1
    \$\begingroup\$ @SylvesterKruin I think the idea behind that could also be written as "The program may not work on more than one character of the input at any time.", i.e. reading the entire input bit-by-bit into a var and doing transformations on that isn't allowed. I used the wording from the file directly, which wasn't a good idea as it is rather lacking in other places too. \$\endgroup\$ Mar 28, 2022 at 12:23
  • 1
    \$\begingroup\$ this does seem like an interesting challenge! I do think the while thing about only reading the input once is A) confusing and mostly unnecessary, and B) kinda against the meta consensus against unobservable requirements. The code obviously takes a single text string in somehow, but what it does with that is not controllable. Also seconding the suggestion to split this into two challenges/get rid of one of them, as determining whether it is possible is a different matter from determining how to precisely stop at the end \$\endgroup\$
    – des54321
    Apr 3, 2022 at 1:08
3
\$\begingroup\$

Polyglot Quiz (Cops' thread) Polyglot Quiz (Robber's thread)

\$\endgroup\$
8
  • 3
    \$\begingroup\$ Not a comment on the challenge itself, but I like the four-state CnR system! \$\endgroup\$ Aug 8, 2022 at 11:21
  • \$\begingroup\$ Does the cop reveal which of the 4 programs satisfy which of the criteria 1-4? \$\endgroup\$
    – pajonk
    Aug 8, 2022 at 11:39
  • \$\begingroup\$ @pajonk Yes they should. I'll edit it to make it clear. \$\endgroup\$
    – Wheat Wizard Mod
    Aug 8, 2022 at 11:39
  • \$\begingroup\$ @UnrelatedString I have a feeling this is equivalent to "standard" CnR, where to become safe you need to reveal your language (or other features the challenge is about) - or are there some differences I missed? \$\endgroup\$
    – pajonk
    Aug 8, 2022 at 11:42
  • 2
    \$\begingroup\$ @pajonk In a normal CnR if a robber ever gets your answer you cannot score. However here your answer is cracked after 10 days you still get to score your answer. On a lot of CnR's people will delay the reveal to give robbers an extra chance, this ruleset allows you to do that without having to sacrifice your score. \$\endgroup\$
    – Wheat Wizard Mod
    Aug 8, 2022 at 11:45
  • \$\begingroup\$ @WheatWizard I get it now, thanks! This indeed makes more sense. \$\endgroup\$
    – pajonk
    Aug 8, 2022 at 12:16
  • \$\begingroup\$ Requiring that languages can run on FreeBSD seems unnecessarily restrictive to me, it being a pretty niche OS in the grand scheme of things. \$\endgroup\$
    – pxeger
    Aug 15, 2022 at 16:15
  • \$\begingroup\$ @pxeger The idea is that if it is Free, and runs on both linux and freeBSD it is very likely to run everywhere. And users should be able to sandbox either linux or freeBSD. It also doesn't seem like a very high bar to cross actually. If you can find a language that can't be run on freeBSD but has otherwise wide support that would make a compelling case. \$\endgroup\$
    – Wheat Wizard Mod
    Aug 15, 2022 at 17:52
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\$ 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\$
    – pxeger
    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\$ 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\$
    – pxeger
    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\$ 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\$
    – pxeger
    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\$
    – naffetS
    Sep 1, 2022 at 0:20
  • \$\begingroup\$ It is one special case of APL dyadic transpose (challenge), and precisely BQN transpose. \$\endgroup\$
    – Bubbler
    Sep 1, 2022 at 0:27
  • \$\begingroup\$ @Bubbler Indeed ;) \$\endgroup\$
    – att
    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\$
    – pajonk
    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\$
    – pajonk
    Aug 1, 2022 at 18:32
  • \$\begingroup\$ @pajonk I think this counts as a duplicate: codegolf.stackexchange.com/questions/48819/… \$\endgroup\$ 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\$ 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\$
    – att
    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\$ 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\$
    – att
    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\$
    – pajonk
    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\$
    – xnor
    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\$
    – Bubbler
    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\$
    – pigrammer
    Oct 2, 2022 at 21:51
  • \$\begingroup\$ @pigrammer yes. \$\endgroup\$
    – zoomlogo
    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\$
    – zoomlogo
    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\$
    – zoomlogo
    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\$ Sep 30, 2022 at 9:38
  • \$\begingroup\$ -1 because of that \$\endgroup\$ Sep 30, 2022 at 9:39
  • \$\begingroup\$ @py3programmer Since hexadecimal is in base sixteen, hexadecimal 81 is 10000001. \$\endgroup\$
    – Aiden4
    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\$
    – The Thonnu
    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\$ 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\$ 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\$ 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\$ 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\$
    – pigrammer
    Oct 2, 2022 at 21:47
  • \$\begingroup\$ @pigrammer that's a default input method and thus should be fune \$\endgroup\$
    – Aiden4
    Oct 2, 2022 at 22:00
  • \$\begingroup\$ @solid.py that should be fine so long as tuples of arbitrary length can be handled \$\endgroup\$
    – Aiden4
    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\$ 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\$
    – oeuf
    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\$
    – Arnauld
    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\$
    – Arnauld
    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\$ Oct 10, 2022 at 3:50
  • \$\begingroup\$ @py3programmer Perhaps yes. I will take some time to think about this. \$\endgroup\$
    – oeuf
    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\$
    – oeuf
    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\$ Oct 10, 2022 at 7:01
  • \$\begingroup\$ @py3programmer No, we only need one input for the string. \$\endgroup\$
    – oeuf
    Oct 10, 2022 at 7:14
  • \$\begingroup\$ So you mean that using version 2, you'll encode the input as a QR code? \$\endgroup\$ Oct 10, 2022 at 7:17
  • \$\begingroup\$ @py3programmer Yes. \$\endgroup\$
    – oeuf
    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\$
    – matteo_c
    Oct 17, 2022 at 14:50
  • \$\begingroup\$ @matteo_c Builtins are allowed, but builtins that solves the entire problem are generally disencouraged. \$\endgroup\$
    – oeuf
    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\$
    – DialFrost
    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\$ 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\$
    – naffetS
    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\$
    – naffetS
    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\$
    – JohnBGoode
    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\$
22
  • \$\begingroup\$ Well, well, well... exec can be used, so I'm claiming that. Ha! \$\endgroup\$ Oct 26, 2022 at 12:02
  • 2
    \$\begingroup\$ Ok go for it. Not sure if I would count that as creative though \$\endgroup\$
    – mousetail
    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\$ 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\$ Oct 26, 2022 at 12:07
  • \$\begingroup\$ Of course python works? You can take input as a string containing quotes \$\endgroup\$
    – mousetail
    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\$ 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\$ Oct 26, 2022 at 12:09
  • \$\begingroup\$ Notice the '? \$\endgroup\$ Oct 26, 2022 at 12:10
  • \$\begingroup\$ The string will contain only double quotes. \$\endgroup\$
    – mousetail
    Oct 26, 2022 at 12:11
  • \$\begingroup\$ Nod nod so when are you posting this? \$\endgroup\$ Oct 26, 2022 at 12:15
  • \$\begingroup\$ When I get 3-4 votes \$\endgroup\$
    – mousetail
    Oct 26, 2022 at 12:17
  • \$\begingroup\$ +1. You're 2 votes away :P \$\endgroup\$ Oct 26, 2022 at 12:19
  • \$\begingroup\$ Hey why'd you claim exec? \$\endgroup\$ 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\$
    – mousetail
    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\$ Oct 27, 2022 at 11:10
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\$ 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\$ 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\$ Oct 10, 2022 at 23:29
  • \$\begingroup\$ ultimately up to you :-) thanks for humoring me :P \$\endgroup\$ 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\$
    – DialFrost
    Nov 11, 2022 at 0:18
  • \$\begingroup\$ @DialFrost 1) Yes. 2) It's your job to figure it out. \$\endgroup\$
    – Bubbler
    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\$
    – naffetS
    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\$
    – naffetS
    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\$
    – mousetail
    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\$
    – mousetail
    Dec 8, 2022 at 10:42
  • 1
    \$\begingroup\$ What if there are multiple possibilities? Or will the input configuration guarantee an unique solution? \$\endgroup\$
    – pajonk
    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\$
    – rtrb
    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\$
    – rtrb
    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\$
    – math scat
    Dec 23, 2022 at 20:18
1
22 23
24
25 26
153

You must log in to answer this question.

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