571
\$\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\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4706 Answers 4706

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

Convert angle to clock time

\$\endgroup\$
5
  • \$\begingroup\$ I strongly discourage strict output format restriction. Also, you may want to specify that only integer angles will be inputted (if that's the case). \$\endgroup\$
    – pajonk
    Commented Apr 14, 2022 at 12:18
  • \$\begingroup\$ @pajonk Is it okay now? \$\endgroup\$
    – Yousername
    Commented Apr 14, 2022 at 12:30
  • \$\begingroup\$ As long as identifiable as clock times by humans is also a list of hours and minutes and other reasonable formats - I'm fine with that :-) \$\endgroup\$
    – pajonk
    Commented Apr 14, 2022 at 12:38
  • \$\begingroup\$ Outputting 0:00 instead of 12:00 is invalid, right? \$\endgroup\$
    – naffetS
    Commented Apr 17, 2022 at 23:34
  • \$\begingroup\$ @Steffan Yes. The 12-hour time convention should be used. \$\endgroup\$
    – Yousername
    Commented Apr 18, 2022 at 0:01
3
\$\begingroup\$

How normal is this group?

Let \$(G, *)\$ be some group. That is, for all \$x, y, z \in G\$, the following axioms hold:

  • \$x * y \in G\$
  • \$x * (y * z) = (x * y) * z\$
  • There exists some \$e \in G\$ such that \$x * e = e * x = x\$
  • There exists some \$x^{-1} \in G\$ such that \$x * x^{-1} = x^{-1} * x = e\$

For some group \$(G, *)\$, we define a subgroup of this as a group \$(H, *)\$ for some subset \$H \subseteq G\$. The trivial subgroups of a group \$(G, *)\$ are when \$H = \{e\}\$ (the identity element of \$G\$) and when \$H = G\$.

For the sake of convenience, we will denote \$x * y\$ as \$xy\$. Let \$N\$ be a subgroup of \$G\$. We say that \$N\$ is normal if, for all \$g \in G\$ and \$x \in N\$, \$gxg^{-1} \in N\$. For any group, the trivial subgroups are normal, and so any group has at least 2 normal subgroups.

For example, let \$G = \{0,1,2,3\}\$ and \$x * y = x + y \bmod 4\$. The subgroups of \$G\$ are \$\{0\}\$, \$\{0, 2\}\$ and \$\{0,1,2,3\}\$, all of which are normal. Therefore, \$(G, *)\$ has 3 normal subgroups.


Given a finite group, output a positive integer \$n \ge 2\$ counting the number of normal subgroups of the input. You may take a group as input in any reasonable manner, including but not limited to:

  • The set \$G\$ (as a set, list, etc.) along with a black-box function \$* : G \times G \to G\$
  • A square matrix representing the Cayley table of the group. You may choose whether to take \$G\$ as a separate input
  • A collection of triples \$(a, b, c)\$ where \$a, b, c \in G\$ and \$c = a * b\$ (the order of such a triple is irrelevant, but must be consistent for all triples)
  • etc.

This is a challenge, so the shortest code in bytes in each language wins.


Test cases

G
∗ : G×G → G
output

{0,1,2,3}
a*b = a+b mod 4
3
\$\endgroup\$
0
3
\$\begingroup\$

Who needs 8 bits for one character?

\$\endgroup\$
5
  • \$\begingroup\$ I'm a little confused by the test cases in this challenge. Based on your description of how to get the solution, I wrote an (ungolfed) Python program that does that (as far as I know). However, my results differ greatly from yours, specifically in using "the fox" as input. For that string, you get [170, 76, 19, ...], but my code gets [172, 239, 134, ...]. I'll put a TIO link in another comment, if you want to try it out. I do note that your first index (the index for a under "How, though?") starts at one, not zero. Could you help me understand this difference in results? Thanks! \$\endgroup\$ Commented May 6, 2022 at 17:31
  • \$\begingroup\$ Try it online! Other than that problem, this sounds like a good challenge! +1 \$\endgroup\$ Commented May 6, 2022 at 17:31
  • \$\begingroup\$ @SylvesterKruin It is one indexed because otherwise, 000 may get lost in leading zeros. Your Python code has a couple problems. One is that it does not pad leading zeros to the binary of each character. Another is that your code has a bug where it does not output the last byte (because of Python exclusive ranges). Also, the last byte should pad zeros at the end, which it does not do. \$\endgroup\$
    – naffetS
    Commented May 6, 2022 at 17:54
  • \$\begingroup\$ Here is your code fixed: Try it online! \$\endgroup\$
    – naffetS
    Commented May 6, 2022 at 17:54
  • \$\begingroup\$ Ah, it didn't pad leading zeroes... that's what it was. I intentionally left out the last <8 bytes for reasons of simplicity. Thanks for the feedback! I'm looking forward to when this challenge is posted on the main site! \$\endgroup\$ Commented May 6, 2022 at 18:07
3
\$\begingroup\$

Derivative of a product

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is the input always at least 2 characters long? \$\endgroup\$
    – pxeger
    Commented May 2, 2022 at 13:31
  • \$\begingroup\$ @pxeger Yes. (filler) \$\endgroup\$
    – emanresu A
    Commented May 4, 2022 at 9:42
3
\$\begingroup\$

King of the Cards

\$\endgroup\$
1
  • \$\begingroup\$ This seems like it won't be particularly strategic \$\endgroup\$ Commented May 9, 2022 at 18:01
3
\$\begingroup\$
\$\endgroup\$
0
3
\$\begingroup\$

Whyte Notation Translator

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I think the scoring is sufficiently punishing to answers missing any cases that none will be able to make use of that in interesting ways. \$\endgroup\$ Commented May 16, 2022 at 19:25
  • \$\begingroup\$ @RadvylfPrograms That's true, i guess i could change that to a multiplication instead. How about S = codesizefunc1 * (1+u) + codesizefunc2 * (1+v) ? Or maybe using the square root on u and v ? \$\endgroup\$ Commented May 16, 2022 at 19:27
  • \$\begingroup\$ Those might work too, but then you run into the risk of people optimizing the combination of code size and cases handled, and getting something boring like x=>"AA20". I think it'd be better to just use the sum of the code sizes as the score. Since it seems like parsing the os into indices into a list is probably going to be how most solutions work, and that's the interesting part of the challenge (since the outputs can't really be compressed), you might even consider allowing a third program that provides the list of names, that's weighted to count for less. \$\endgroup\$ Commented May 16, 2022 at 19:39
  • \$\begingroup\$ @RadvylfPrograms What would be the purpose of the third program and the reduced weight of it ? \$\endgroup\$ Commented May 18, 2022 at 10:27
  • \$\begingroup\$ Since there's no interesting way to compress the list of names \$\endgroup\$ Commented May 18, 2022 at 13:28
  • 1
    \$\begingroup\$ Prairie and Adriatic are both mapped to oOOOo. \$\endgroup\$
    – Arnauld
    Commented May 28, 2022 at 20:34
  • \$\begingroup\$ @Arnauld You're right, it's corrected and posted \$\endgroup\$ Commented May 29, 2022 at 17:13
3
\$\begingroup\$

Tell me how many there are, in Polish

Today, you're going to be writing Polish. No, not Polish notation—Polish, the actual language spoken in Poland.

Given a number and a noun, output a Polish sentence telling me that there are that many of that thing, using the appropriate template below.

The input consists of an integer in the range from 0 to 200, and a string of 1 to 10 lowercase ASCII letters (called the "noun"). You may accept these inputs in any reasonable format.

The output must consist of one of the below output templates, where the number in the template (if any) has been replaced with the input integer, and the word kot in the template has been replaced with the input noun.

Output templates

If the input number is 0, then use the output template

Nie ma żadnych kotów.

If the input number is 1, then use the output template

Jest 1 kot.

If the input number ends with 2, 3, or 4, but does not end with 12, 13, or 14, then use the output template

Są 4 koty.

In any other case, use the output template

Jest 8 kotów.

Note that the special characters used in these templates are:

  • ż (in "żadnych") – U+017C Latin small letter Z with dot above
  • ó (in the suffix "-ów") – U+00F3 Latin small letter O with acute
  • ą (in "Są") – U+0105 Latin small letter A with ogonek

You may output these characters in any reasonably common character encoding (including HTML entities), and you may use combining characters instead of precomposed characters (or even a mixture of the two).

Test cases

0 pomidor -> Nie ma żadnych pomidorów.
1 kwiat -> Jest 1 kwiat.
2 dom -> Są 2 domy.
5 wilk -> Jest 5 wilków.
13 komputer -> Jest 13 komputerów.
24 but -> Są 24 buty.
101 kurczak -> Jest 101 kurczaków.

Do plurals in Polish really work that way?

No, the way it actually works is much more complicated.

This is , so the shortest program in each language wins.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Suggested test-cases with 3-digit numbers ending with 02-04, 12-14, x2-x4 (with x>1) and outside those ranges (>101). \$\endgroup\$
    – pajonk
    Commented Jun 3, 2022 at 8:11
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\$ Commented Jun 7, 2022 at 21:14
  • 1
    \$\begingroup\$ @mathjunkie added test cases \$\endgroup\$
    – 00Her0
    Commented 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
    Commented 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
    Commented Jun 12, 2022 at 9:18
  • 1
    \$\begingroup\$ @pxeger Good idea :P \$\endgroup\$
    – emanresu A
    Commented 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
    Commented Jun 12, 2022 at 9:20
  • \$\begingroup\$ Suggested falsey test-case: [[]][[]], which may erroneously be accepted by eval-like solutions \$\endgroup\$
    – pxeger
    Commented Jun 12, 2022 at 12:22
  • \$\begingroup\$ @pxeger Added.. \$\endgroup\$
    – emanresu A
    Commented 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
    Commented Jun 26, 2022 at 16:40
  • \$\begingroup\$ @pxeger Done. (filler) \$\endgroup\$
    – emanresu A
    Commented 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
    Commented Jul 14, 2022 at 12:31
  • \$\begingroup\$ @pxeger one of the numeric sequences \$\endgroup\$ Commented Jul 14, 2022 at 12:32
  • \$\begingroup\$ What does "connect the original string" mean? \$\endgroup\$
    – mousetail
    Commented Jul 14, 2022 at 12:32
  • \$\begingroup\$ @mousetail I edited it - it should be concatenate \$\endgroup\$ Commented 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
    Commented Jul 14, 2022 at 12:35
  • \$\begingroup\$ @mousetail Yes. How should I phrase this? Is this better? \$\endgroup\$ Commented Jul 14, 2022 at 12:36
  • \$\begingroup\$ Maybe include a example what it would look like after 1 or 2 iterations \$\endgroup\$
    – mousetail
    Commented 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
    Commented Jul 14, 2022 at 12:47
  • \$\begingroup\$ I rewrote the process as an algorithm in pseudocode. Is it clearer now? \$\endgroup\$ Commented 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\$ Commented 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
    Commented Jul 14, 2022 at 13:00
  • \$\begingroup\$ @WheatWizard I tried rewriting it. Is this clear? \$\endgroup\$ Commented 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\$ Commented 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
    Commented Jul 15, 2022 at 9:51
  • \$\begingroup\$ @tsh yes, I edited that in \$\endgroup\$ Commented 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
    Commented Jul 26, 2022 at 5:55
  • \$\begingroup\$ Apparently, the monospace font doesn't include Unicode characters, oh well \$\endgroup\$ Commented Jul 26, 2022 at 14:47
3
\$\begingroup\$

Remove redundant parenthesis

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Tags: balanced-string, string \$\endgroup\$
    – naffetS
    Commented 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\$ Commented Aug 1, 2022 at 14:19
3
\$\begingroup\$

A better Hexagony template

\$\endgroup\$
4
  • \$\begingroup\$ 4000th answer to this question, hooray \$\endgroup\$ Commented 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\$ Commented 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
    Commented Aug 11, 2022 at 14:02
  • 1
    \$\begingroup\$ @KevinCruijssen I decided to allow both :) \$\endgroup\$
    – Bubbler
    Commented 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
    Commented 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\$ Commented Mar 27, 2022 at 18:02
  • \$\begingroup\$ @pajonk That's a good idea, thanks! \$\endgroup\$ Commented 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\$ Commented 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
    Commented 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\$ Commented 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
    Commented Aug 8, 2022 at 11:39
  • \$\begingroup\$ @pajonk Yes they should. I'll edit it to make it clear. \$\endgroup\$
    – Wheat Wizard Mod
    Commented 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
    Commented 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
    Commented Aug 8, 2022 at 11:45
  • \$\begingroup\$ @WheatWizard I get it now, thanks! This indeed makes more sense. \$\endgroup\$
    – pajonk
    Commented 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
    Commented 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
    Commented 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\$ 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\$
    – pxeger
    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\$
    – pxeger
    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\$
    – pxeger
    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\$
    – naffetS
    Commented Sep 1, 2022 at 0:20
  • \$\begingroup\$ It is one special case of APL dyadic transpose (challenge), and precisely BQN transpose. \$\endgroup\$
    – Bubbler
    Commented Sep 1, 2022 at 0:27
  • \$\begingroup\$ @Bubbler Indeed ;) \$\endgroup\$
    – att
    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\$
    – pajonk
    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\$
    – pajonk
    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\$
    – att
    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\$
    – att
    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\$
    – pajonk
    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\$
    – xnor
    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\$
    – Bubbler
    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\$
    – pigrammer
    Commented Oct 2, 2022 at 21:51
  • \$\begingroup\$ @pigrammer yes. \$\endgroup\$
    – zoomlogo
    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\$
    – zoomlogo
    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\$
    – zoomlogo
    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\$
    – Aiden4
    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\$
    – The Thonnu
    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\$
    – pigrammer
    Commented Oct 2, 2022 at 21:47
  • \$\begingroup\$ @pigrammer that's a default input method and thus should be fune \$\endgroup\$
    – Aiden4
    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\$
    – Aiden4
    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\$
    – oeuf
    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\$
    – Arnauld
    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\$
    – Arnauld
    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\$
    – oeuf
    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\$
    – oeuf
    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\$
    – oeuf
    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\$
    – oeuf
    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\$
    – matteo_c
    Commented Oct 17, 2022 at 14:50
  • \$\begingroup\$ @matteo_c Builtins are allowed, but builtins that solves the entire problem are generally disencouraged. \$\endgroup\$
    – oeuf
    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\$
    – DialFrost
    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\$
1
22 23
24
25 26
157

You must log in to answer this question.

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