577
\$\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\$ Commented May 29 at 13:27

4831 Answers 4831

1
83 84
85
86 87
162
1
\$\begingroup\$

Calculate Pi unto a Point using the Nilakantha series

\$\endgroup\$
2
  • \$\begingroup\$ What should be the desired precision - are floating-point errors ok? Suggested tag: sequence (+adopting output rules from there). Suggestion: merge odd and even cases to one using \$(-1)^n\$ for \$n>1\$. Please make the test-cases copy-friendly (see codegolf.meta.stackexchange.com/a/8101/55372). \$\endgroup\$
    – pajonk
    Commented Sep 13, 2022 at 11:41
  • \$\begingroup\$ There you go. I've added all of that. \$\endgroup\$ Commented Sep 13, 2022 at 12:48
1
\$\begingroup\$

Title

God Save the Queen (or King)!

Input

A calendar year from 927 to the present year. For example 2022.

Output

You can use any three distinguishable outputs. As an example,

“K” (short for King)

or

“Q” (short for Queen)

depending on which was right in England in that year. If there was both a King and Queen in that year you can output either.

If there was no King or Queen for the whole of that year, your code must output something that is not one of those two messages.

Dates

Kings: 937-1553, 1603-1649, 1660-1702, 1714-1837, 1901-1952, 2022

Queens: 1553-1603, 1689-1694, 1702-1714, 1837-1901, 1952-2022

\$\endgroup\$
7
  • \$\begingroup\$ An interesting idea: instead of forcing it to be on January 1, allow years with multiple monarchs to choose one arbitrarily? Could add some depth to the compression strategies. \$\endgroup\$ Commented Sep 17, 2022 at 5:23
  • \$\begingroup\$ @UnrelatedString Good idea \$\endgroup\$
    – user108721
    Commented Sep 17, 2022 at 5:28
  • 1
    \$\begingroup\$ Two downvotes?? Please explain \$\endgroup\$
    – user108721
    Commented Sep 17, 2022 at 5:30
  • \$\begingroup\$ The fixed output strings are a common thing to avoid. I think they'd be better off as any two outputs of the golfer's choice, with everything else corresponding to neither king nor queen. \$\endgroup\$
    – xnor
    Commented Sep 17, 2022 at 7:57
  • \$\begingroup\$ @xnor that's a shame as the messages are what make the challenge more fun. \$\endgroup\$
    – user108721
    Commented Sep 17, 2022 at 9:20
  • \$\begingroup\$ I really don't see how "K" or "Q" (which is what the output requires now) makes the challenge more fun. \$\endgroup\$
    – user
    Commented Sep 17, 2022 at 16:37
  • \$\begingroup\$ @user it was previously "God Save the King" but I changed it on xnor's advice. \$\endgroup\$
    – user108721
    Commented Sep 17, 2022 at 16:40
1
\$\begingroup\$

Is there a area that can see the entire perimeter of a polygon

Oh no, your despotic regime has too many political prisoners and not enough guards! Time for drastic measures: Only build prisons that require only a single guard. But there are many prison design and little time. How to check?

The challenge

Given a polygon, as a list of points, determine if there is a area (where the guard can stand) that can see the entire perimeter of the polygon.

Any convex shape trivially qualifies:

pentagon

Some concave shapes qualify too:

concave shape

But not all:

concave shape where there is no place for a guard

Algorithm hint

The area where a guard can stand is the intersection of the areas on the inside of the tangent of every edge.

Test Cases

Image Points Outcome
TBD
\$\endgroup\$
1
\$\begingroup\$

Calculating Pi using the Gregory-Leibniz series unto a point

\$\endgroup\$
2
  • \$\begingroup\$ Why can't we treat \$\pi_n\$ as a sequence? Also, some test-cases would be nice. \$\endgroup\$
    – pajonk
    Commented Sep 17, 2022 at 19:27
  • \$\begingroup\$ I think this might be too similar to your earlier challenge on Nilakantha series. For instance, loopy walt's answer is already summing up the Gregory-Leibniz series then correcting it by \$\pm 1/n \$ at the end. \$\endgroup\$
    – xnor
    Commented Sep 17, 2022 at 20:35
1
\$\begingroup\$

Construct Digit From Digits

In the game All Ten, each day you are given four single-digit positive integers, and have to use all four of those numbers once each to construct the values 1 through 10 using the following operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Concatenation, i.e. joining two numbers together; for example, \$1 \text{ concat } 23 = 123\$. (You can only apply this operation if both of the numbers are integers and the number on the right is non-negative.)

So, for example, given numbers \$[4,4,8,9]\$, to make \$4\$ you could do \$((4 \text{ concat } 4) - 8 ) / 9\$. which equals \$(44 - 8)/9 = 36 / 9 = 4\$.

You're allowed to compose these operations however you want, in whatever order, including concatenation (e.g. you can do \$16 - ((2-1) \text{ concat } 3) = 16 + (-1 \text{ concat } 3) = 16 - 13 = 3\$.)

The challenge:

Your function is given two inputs: \$I\$, which is a list of four single digit positive integers (i.e. in the range \$1,2,\ldots,9\$) which are not necessarily unique, and \$n\$, which is also a single digit positive integer.

Your function should return a way of using all four numbers in \$I\$ to construct \$n\$ using the rules above.

Output Format

You can provide the output in any meaningful way, including:

  • A string (or list of numbers/characters) representing the expression which evaluates to \$n\$, using any symbols besides \$1,2,\ldots,9\$ to represent the operations / parentheses necessary
    • e.g. "((4c4)-8)/9"
    • You're also allowed to represent concatenation with the empty string (i.e. no operator at all) -- e.g. "((44)-8)/9"
    • You can leave out parentheses if you specify the order of operations -- e.g. you say that concatenation has highest priority, then return "(44-8)/9"
  • A tree or nested list with where each leaf represents a number in \$I\$ and the parents represent the various operations

You may assume there is at least one solution; if there's more than one solution, you may output any of them.

Test cases

[To do -- I need to enumerate all of the possible ways to construct a given value for this to be useful.]

Questions

This is a really bad title, but it's hard to describe succintly. There's also a lot of text here, but I don't know how to shorten it.

\$\endgroup\$
8
  • \$\begingroup\$ May the output be in Reverse Polish notation, removing the need for parenthesis completely? Or does that bend the 'provide output in any meaningful way' too much? \$\endgroup\$ Commented Sep 27, 2022 at 12:07
  • \$\begingroup\$ Also, is the division regular division or integer division? If the first, is something like ((1/5)concat 5)*8 = 2 valid (where 1 /5 -> 0.2 concat 5 -> 0.25 *8 -> 2)? And how to deal with floating point inaccuracies in that case? \$\endgroup\$ Commented Sep 27, 2022 at 12:13
  • \$\begingroup\$ Closely related - partial duplicate Difference is that that challenge asks to use the digits 0 through 9, instead of an input-list of 4 digits. And this challenge allows concatenation, whereas the other answer allowed exponentiation. But my 05AB1E answer would be nearly the same. \$\endgroup\$ Commented Sep 27, 2022 at 12:26
  • \$\begingroup\$ @KevinCruijssen (1) I think that Polish notation should be allowed. (2) It's supposed to be regular divison, though the expression you gave isn't valid because you aren't allowed to concatenate non-integers. I don't understand the second part -- the solver needs to handle floating point inaccuracies so they give the correct answer. (3) I don't know how close two challenges need to be before they are counted as distinct -- do you think this is still worth posting? It seems like the answer is no... \$\endgroup\$ Commented Sep 27, 2022 at 15:00
  • \$\begingroup\$ @97.100.97.109 In the original game, concatenation is only allowed on the original integers; i.e. you cannot do (2 - 1) concat 3. Is that not the case here? \$\endgroup\$
    – pigrammer
    Commented Sep 27, 2022 at 16:36
  • \$\begingroup\$ @pigrammer You can if you do, e.g. (2-1)=, which saves a 1 to your "workspace", which means you can then do 1 concat 3. \$\endgroup\$ Commented Sep 27, 2022 at 17:35
  • \$\begingroup\$ @97.100.97.109 No, it gives an error "Combo buttons cannot be used in two-digit numbers" \$\endgroup\$
    – pigrammer
    Commented Sep 27, 2022 at 17:36
  • \$\begingroup\$ @prigrammer Whoops, I was wrong. I think I'll still allow it since it makes the application marginally simpler. \$\endgroup\$ Commented Sep 27, 2022 at 18:47
1
\$\begingroup\$

Create a nibble shorthand

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is it strict graphical-output or we may return a collection of symbols (read: ascii-art) to represent a nibble? Also, is scaling allowed (I mean, like mirrored r is smaller version of the image for the reverse of r)? \$\endgroup\$
    – pajonk
    Commented Sep 25, 2022 at 18:47
  • \$\begingroup\$ @pajonk It's graphical output. Scaling is not allowed. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Sep 25, 2022 at 18:53
1
\$\begingroup\$

Longest alternating subsequence

\$\endgroup\$
2
  • \$\begingroup\$ If our language uses an SBCS, can we use UTF-8 if it helps with the score? \$\endgroup\$
    – naffetS
    Commented Sep 29, 2022 at 0:22
  • \$\begingroup\$ @Steffan You can choose the encoding in your favor if your language supports multiple encodings. \$\endgroup\$
    – Bubbler
    Commented Sep 29, 2022 at 0:32
1
\$\begingroup\$

Partition square into squares

Given integers \$n\$, \$m\$ and \$k\$, randomly output a list of \$k\$ numbers between \$1\$ and \$m\$ (inclusive) such that the sum of the squares of the numbers in the list is equal to \$n\$ squared. In other words, find a way to randomly split \$n^{2}\$ into \$k\$ squares between \$1\$ and \$m^{2}\$.

If there is no solution (which may happen if \$k = 2\$), you may exit from your program or return an error.

The program should take less than 40 seconds for inputs with \$k, n, m\$ less than 10000.

Scoring

This is , so the smallest score in bytes wins.

Input

Three numbers \$n\$, \$m\$, and \$k\$.

Output

A random list of \$k\$ numbers between \$1\$ and \$m\$, such that the sum of the squares of them is equal to \$n^{2}\$. All possible lists that satisfy the conditions should be equally likely.

Test cases

Input (n, m, k)      Possible output
114, 100, 6          [13, 1, 25, 76, 44, 67]
114, 100, 6          [64, 58, 20, 32, 64, 4]
57, 40, 7            [2, 32, 18, 26, 26, 17, 16]
7, 10000, 2          [error]
7, 7, 3              [2,3,6], [2,6,3], [3,2,6], [3,6,2], [6,2,3], [6,3,2]
\$\endgroup\$
2
  • \$\begingroup\$ The time limit isn't bad, but it sure will make low efficiency languages unable to answer. Also, output all the possible result is better than randomly choose one, random is sometime unavailable and is hard to define, while adding no challenge to the original question. Nice question overall \$\endgroup\$
    – okie
    Commented Oct 7, 2022 at 4:56
  • \$\begingroup\$ Hello, and welcome to the Code Golf SE! \$\endgroup\$ Commented Oct 7, 2022 at 18:53
1
\$\begingroup\$

Prime number checksum

Posted here

\$\endgroup\$
1
\$\begingroup\$

Alphabet checksum

\$\endgroup\$
7
  • \$\begingroup\$ This question may be tricky with our current default I/O rules, i.e. allowing I/O as char codes. Such I/O trivialises the problem (as it's just sum the input and take mod 26). OTOH, disallowing this explicitly may be disadvantageous to some languages that cannot process strings natively. \$\endgroup\$
    – pajonk
    Commented Oct 20, 2022 at 18:19
  • \$\begingroup\$ @pajonk - I'm going to say that the input must be a string. Otherwise, the challenge is way too easy. \$\endgroup\$
    – The Thonnu
    Commented Oct 20, 2022 at 18:34
  • \$\begingroup\$ Can we switch to uppercase if we want? \$\endgroup\$
    – Adám
    Commented Oct 22, 2022 at 23:03
  • \$\begingroup\$ @Adám - I'll say no for that one. It needs to be lowercase. If you want, you can just convert it to uppercase at the start of your program. \$\endgroup\$
    – The Thonnu
    Commented Oct 23, 2022 at 6:11
  • \$\begingroup\$ Also, I forgot to link it but I've already posted the challenge on the main site. \$\endgroup\$
    – The Thonnu
    Commented Oct 23, 2022 at 6:13
  • \$\begingroup\$ Can we use 1-based alphanumeric mapping? With a = 1, b = 2, c = 3 ... z = 26 instead of a = 0, b = 1, c = 2 ... z = 25? Obviously, this changes the outputs... \$\endgroup\$
    – acvill
    Commented Oct 24, 2022 at 20:13
  • \$\begingroup\$ @acvill - no. It must be 0-based. Also, the challenge has already been posted on the main site. \$\endgroup\$
    – The Thonnu
    Commented Oct 25, 2022 at 7:10
1
\$\begingroup\$

Render an Ideographic Description Sequence

There are 12 characters in Unicode that can be used to describe any CJK character, which are often made up of reoccurring parts ("radicals") composed in different ways.

For example, U+86D9 蛙 can be described as U+2FF0 U+866B U+572D ⿰虫圭.

Your task is to take such an Ideographic Description Sequence as input and produce an image of the resulting character as an output. You can assume the input conforms to the following grammar, which is taken from the Unicode standard, which explains this topic very well:

IDS := Ideographic | Radical | CJK_Stroke | Private Use | U+FF1F
    | IDS_BinaryOperator IDS IDS
    | IDS_TrinaryOperator IDS IDS IDS
CJK_Stroke := U+31C0 | U+31C1 | ... | U+31E3
IDS_BinaryOperator := U+2FF0 | U+2FF1 | U+2FF4 | ... | U+2FFA | U+2FFB
IDS_TrinaryOperator := U+2FF2 | U+2FF3

This is a kind of prefix notation (polish notation).

Ideographic and Radical are defined in PropList.txt:

2E80..2E99    ; Radical # So  [26] CJK RADICAL REPEAT..CJK RADICAL RAP
2E9B..2EF3    ; Radical # So  [89] CJK RADICAL CHOKE..CJK RADICAL C-SIMPLIFIED TURTLE
2F00..2FD5    ; Radical # So [214] KANGXI RADICAL ONE..KANGXI RADICAL FLUTE

3006          ; Ideographic # Lo       IDEOGRAPHIC CLOSING MARK
3007          ; Ideographic # Nl       IDEOGRAPHIC NUMBER ZERO
3021..3029    ; Ideographic # Nl   [9] HANGZHOU NUMERAL ONE..HANGZHOU NUMERAL NINE
3038..303A    ; Ideographic # Nl   [3] HANGZHOU NUMERAL TEN..HANGZHOU NUMERAL THIRTY
3400..4DBF    ; Ideographic # Lo [6592] CJK UNIFIED IDEOGRAPH-3400..CJK UNIFIED IDEOGRAPH-4DBF
4E00..9FFF    ; Ideographic # Lo [20992] CJK UNIFIED IDEOGRAPH-4E00..CJK UNIFIED IDEOGRAPH-9FFF
F900..FA6D    ; Ideographic # Lo [366] CJK COMPATIBILITY IDEOGRAPH-F900..CJK COMPATIBILITY IDEOGRAPH-FA6D
FA70..FAD9    ; Ideographic # Lo [106] CJK COMPATIBILITY IDEOGRAPH-FA70..CJK COMPATIBILITY IDEOGRAPH-FAD9
16FE4         ; Ideographic # Mn       KHITAN SMALL SCRIPT FILLER
17000..187F7  ; Ideographic # Lo [6136] TANGUT IDEOGRAPH-17000..TANGUT IDEOGRAPH-187F7
18800..18CD5  ; Ideographic # Lo [1238] TANGUT COMPONENT-001..KHITAN SMALL SCRIPT CHARACTER-18CD5
18D00..18D08  ; Ideographic # Lo   [9] TANGUT IDEOGRAPH-18D00..TANGUT IDEOGRAPH-18D08
1B170..1B2FB  ; Ideographic # Lo [396] NUSHU CHARACTER-1B170..NUSHU CHARACTER-1B2FB
20000..2A6DF  ; Ideographic # Lo [42720] CJK UNIFIED IDEOGRAPH-20000..CJK UNIFIED IDEOGRAPH-2A6DF
2A700..2B739  ; Ideographic # Lo [4154] CJK UNIFIED IDEOGRAPH-2A700..CJK UNIFIED IDEOGRAPH-2B739
2B740..2B81D  ; Ideographic # Lo [222] CJK UNIFIED IDEOGRAPH-2B740..CJK UNIFIED IDEOGRAPH-2B81D
2B820..2CEA1  ; Ideographic # Lo [5762] CJK UNIFIED IDEOGRAPH-2B820..CJK UNIFIED IDEOGRAPH-2CEA1
2CEB0..2EBE0  ; Ideographic # Lo [7473] CJK UNIFIED IDEOGRAPH-2CEB0..CJK UNIFIED IDEOGRAPH-2EBE0
2F800..2FA1D  ; Ideographic # Lo [542] CJK COMPATIBILITY IDEOGRAPH-2F800..CJK COMPATIBILITY IDEOGRAPH-2FA1D
30000..3134A  ; Ideographic # Lo [4939] CJK UNIFIED IDEOGRAPH-30000..CJK UNIFIED IDEOGRAPH-3134A
31350..323AF  ; Ideographic # Lo [4192] CJK UNIFIED IDEOGRAPH-31350..CJK UNIFIED IDEOGRAPH-323AF

Rules

Keep in mind that output has to be an image, not a unicode character, as per the default loophole, but I recommend a text rendering engine to render each radical.

You can assume the input won't contain private use characters.

Use the following definitions of the Ideographic Description Characters. The percentages are not defined in unicode, but made up for this challenge. Each component should be squashed to the required shape, so that each intermediate result is a square. The output should also be a square image. See also: https://en.wikipedia.org/wiki/Chinese_character_description_languages#Ideographic_Description_Sequences

Code point Character Meaning
U+2FF0 divide horizontally in halves
U+2FF1 divide vertically in halves
U+2FF2 divide horizontally in thirds
U+2FF3 divide vertically in thirds
U+2FF4 enclose; the lengths should be 20%, 60%, 20%
U+2FF5 surround from top; the inner has 60% the width and 80% of the height
U+2FF6 surround from below; the inner has 60% the width and 80% of the height
U+2FF7 surround from left; the inner has 80% the width and 60% of the height
U+2FF8 surround from top-left; the inner has 80% the width and height
U+2FF9 surround from top-right; the inner has 80% the width and height
U+2FFA surround from top-right; the inner has 80% the width and height
U+2FFB overlay with transparency

Examples

Input Output
⿰虫圭
⿲彳圭亍
⿵几皇
⿻工从
⿴囗⿰⿱鹵凼⿰丨㇌ 2
⿱井蛙 1
⿱井⿰虫圭 1
⿱井⿰虫⿱土土 1
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Is it too long? \$\endgroup\$
    – corvus_192
    Commented Oct 25, 2022 at 20:00
  • 1
    \$\begingroup\$ Downvoter, could you please explain why? \$\endgroup\$
    – corvus_192
    Commented Oct 26, 2022 at 11:46
  • \$\begingroup\$ why not restrict output to graphical ones only for simplicity? \$\endgroup\$ Commented Oct 27, 2022 at 11:55
  • 1
    \$\begingroup\$ @鳴神裁四点一号 I'm not sure I understand what you mean. This is graphical-output, so the output must be an image or image file. \$\endgroup\$
    – corvus_192
    Commented Oct 27, 2022 at 12:37
1
\$\begingroup\$

Increment, decrement, undo, peek

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Nice challenge! I was thinking maybe add the tags: function and number \$\endgroup\$
    – The Thonnu
    Commented Oct 25, 2022 at 16:21
  • \$\begingroup\$ I think this is a very interesting challenge, but the definitions for the four functions are very difficult to understand as they're currently written. I haven't figured out a really good way to phrase them, but at the very least I think replacing "has the value" with something like "contains the value". When I read "Increment has the value of the function that created it plus 1" it took me a long time to figure out that it didn't mean incr == 1. \$\endgroup\$ Commented Oct 25, 2022 at 16:47
  • \$\begingroup\$ What should eval(undo)() return in your example? Maybe this is undefined and we don't need to handle such cases? Do we need to keep track of all operations for undo or there's a limit? \$\endgroup\$
    – pajonk
    Commented Oct 27, 2022 at 7:13
  • \$\begingroup\$ @pajonk Good questions, thanks. I suppose that behavior should just be undefined. Re: Limit I think the only limit should be the limitations of your system/language. \$\endgroup\$
    – Jordan
    Commented Oct 27, 2022 at 12:00
1
\$\begingroup\$

Length of Binary as Base 10 [OEIS A242347]

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Can we use default sequence rules and output infinitely, or output the first \$n\$ terms? \$\endgroup\$
    – naffetS
    Commented Oct 26, 2022 at 4:13
  • \$\begingroup\$ I'll edit it to output the first n terms \$\endgroup\$
    – pacman256
    Commented Oct 26, 2022 at 13:00
  • \$\begingroup\$ I second @Sʨɠɠan's suggestion to allow standard sequence rules. Also, your wording now is misleading - A242347 isn't the number of digits in the first n terms of A008559 (it's the number of digits of the nth term). I suggest changing the tile to reflect the challenge by adding "Length of" and updating the OEIS number accordingly. Another thing, good practice is to give meaningful labels to hyperlinks - I suggest changing "here" to "A008559" and "this sequence" to "sequence A242347". \$\endgroup\$
    – pajonk
    Commented Oct 27, 2022 at 7:06
  • \$\begingroup\$ @pajonk will do \$\endgroup\$
    – pacman256
    Commented Oct 27, 2022 at 12:59
  • \$\begingroup\$ Your test cases don't match the specs currently (only one number instead of first n terms). Also, the \$a(1)=2\$ in the Input section is confusing. \$\endgroup\$
    – pajonk
    Commented Oct 27, 2022 at 15:37
  • \$\begingroup\$ fixed those issues \$\endgroup\$
    – pacman256
    Commented Oct 27, 2022 at 16:14
1
\$\begingroup\$

Power sequence differences

\$\endgroup\$
6
  • \$\begingroup\$ Any reason for the first 5 terms portion in the challenge description? I see in the rules you allow the default [sequence] rules, so it can be the \$n^{th}\$, first \$n\$, or infinite sequence, instead of specifically the first \$5\$, right? \$\endgroup\$ Commented Oct 27, 2022 at 12:29
  • 1
    \$\begingroup\$ @KevinCruijssen I will edit the challenge to allow anything that includes the 5th term. This includes the first 5 terms, just the 5th term, or the infinite sequence. \$\endgroup\$
    – The Thonnu
    Commented Oct 27, 2022 at 12:32
  • \$\begingroup\$ These finite differences have a closed form, which I'm not sure is your intention? No matter what you choose you should define the domains of \$ x \$ and \$ d \$. \$\endgroup\$ Commented Oct 27, 2022 at 18:52
  • \$\begingroup\$ @FryAmTheEggman I don't get what you mean by that. Could you explain further? \$\endgroup\$
    – The Thonnu
    Commented Oct 28, 2022 at 9:03
  • \$\begingroup\$ For the first part of my comment, I wanted to let you know that the 5th term of the \$d\$th difference sequence of \$n^{x}\$ was \$ \sum_{i=0}^{d} \binom{d}{i} (4+d-i)^{x} (-1)^{x} \$. I think a lot of answers would probably use that rather than manually computing difference sequences, which I wasn't sure was what you wanted. There isn't anything wrong with it, unless you don't like it. The other part is that you don't specify that \$ x \$ and \$ d \$ are positive integers and \$ d < x \$. You can choose other domains, but those are true of your test cases. \$\endgroup\$ Commented Oct 28, 2022 at 14:56
  • \$\begingroup\$ @FryAmTheEggman - for the first bit, I don't really mind if people use a formula for it. For the second bit, yes that is the domain I wanted. I'll edit that in now. \$\endgroup\$
    – The Thonnu
    Commented Oct 28, 2022 at 15:36
1
\$\begingroup\$

Longest Total Distance Cyclic Quine Chain

Write a program of upto 100 bytes that outputs another program that outputs another program etc. until after a finite number of iterations outputting the original program again.

Each program in the cycle must have a length less than or equal to 100 bytes.

Your score is the sum of the Levenshtein distance between each program and it's output. I hope this leads to answers that do something more creative than change a single digit each time.

Maximum possible score is: $$256^{101}$$

\$\endgroup\$
14
  • \$\begingroup\$ finite? As in, how many iterations exactly? \$\endgroup\$ Commented Nov 1, 2022 at 7:47
  • \$\begingroup\$ Like after 10, 20, or 100? \$\endgroup\$ Commented Nov 1, 2022 at 7:47
  • \$\begingroup\$ The goal is to get the highest finite number of iterations \$\endgroup\$ Commented Nov 1, 2022 at 7:48
  • \$\begingroup\$ I imagine scores will be around 10^100 \$\endgroup\$ Commented Nov 1, 2022 at 7:49
  • \$\begingroup\$ I see. And why upto 100 bytes? I imagine some really verbose language like Taxi wouldn't be able to answer this. \$\endgroup\$ Commented Nov 1, 2022 at 7:50
  • 2
    \$\begingroup\$ Related: Cyclic levenquine \$\endgroup\$
    – Bubbler
    Commented Nov 1, 2022 at 7:52
  • \$\begingroup\$ I need to set a limit or you could easily get arbitrarily high scores. Shorter languages can easily get scores that are so high as to be uncomputable even for short lengths. I hope with this length languages like python can participate but golfing languages can still genuinely compete against each-other, since their difference in score is hopefully representable. \$\endgroup\$ Commented Nov 1, 2022 at 7:52
  • \$\begingroup\$ And I don't really understand ` that outputs another program `. Are we supposed to output the source code of another program, that when executed output's the source code of yet another one? \$\endgroup\$ Commented Nov 1, 2022 at 7:54
  • \$\begingroup\$ @Bubbler It's different since you are trying to get the highest distance possible instead of a distance of exactly 1 \$\endgroup\$ Commented Nov 1, 2022 at 7:54
  • \$\begingroup\$ @py3_and_c_programmer yes, it's a quine like \$\endgroup\$ Commented Nov 1, 2022 at 7:55
  • 1
    \$\begingroup\$ @py3_and_c_programmer Not being answerable in some languages is totally OK. @ mousetail: Yes, I'm aware of the differences. \$\endgroup\$
    – Bubbler
    Commented Nov 1, 2022 at 7:55
  • \$\begingroup\$ Would some test cases in a particular... No, never mind. \$\endgroup\$ Commented Nov 1, 2022 at 7:58
  • 1
    \$\begingroup\$ 1) I think you should clarify that it is NOT "longest chain, ties broken by highest distance sum". I guess my initial misconception is due to the title. Maybe "Most distant cyclic quine chain"? 2) The theoretical maximum score is (sum of lengths of all possible programs of 100 bytes or shorter) * 2, which is a bit lower than 256^101. \$\endgroup\$
    – Bubbler
    Commented Nov 1, 2022 at 8:00
  • \$\begingroup\$ Suggested tag: busy-beaver \$\endgroup\$
    – alephalpha
    Commented Nov 1, 2022 at 11:13
1
\$\begingroup\$

Perfect Nontransitive Sets

\$\endgroup\$
7
  • \$\begingroup\$ "in comparing two tuples the one that has more elements greater than the other is greater" - how do we compare each element to the other tuple? Maybe you mean that we should compare elements to the respective element in the other tuple (i.e. zip with <) and then the lesser tuple is the one with more truthy results? Or maybe you mean we compare an element to each of the three in the other tuple? Maybe a worked example would help. \$\endgroup\$ Commented Nov 3, 2022 at 16:50
  • \$\begingroup\$ @JonathanAllan Shoot, I was afraid the wording there was confusing. Yes, it's essentially zip with <, hopefully the the edits clear up my intent. \$\endgroup\$ Commented Nov 3, 2022 at 18:01
  • \$\begingroup\$ It seems that {(n-i, 0, i) for i in range(n)} will satisfy the property (since no pair of elements contain one that is less than the other). \$\endgroup\$ Commented Nov 3, 2022 at 18:15
  • \$\begingroup\$ ...e.g. {(1, 0, 4), (2, 0, 3), (3, 0, 2), (4, 0, 1), (5, 0, 0)} \$\endgroup\$ Commented Nov 3, 2022 at 18:22
  • \$\begingroup\$ @JonathanAllan This would not be a valid set since none of them are comparable. It appears things are still confusing. Do you think it would be better if I simply disallow tuples that have any element-wise equalities? \$\endgroup\$ Commented Nov 3, 2022 at 18:30
  • \$\begingroup\$ So "all pairs must be comparable" means one must be "less than" the other? If you spell that out it's probably fine, but it would probably be worth adding an invalid example output to ensure the point gets accross. \$\endgroup\$ Commented Nov 3, 2022 at 18:43
  • 1
    \$\begingroup\$ Went ahead and did both, if anybody still finds this confusing let me know \$\endgroup\$ Commented Nov 3, 2022 at 18:57
1
\$\begingroup\$

Number to letters

\$\endgroup\$
1
\$\begingroup\$

Is it a legal atomic chess move?

\$\endgroup\$
8
  • \$\begingroup\$ How would one know what the move is? Make sure to include that in the input \$\endgroup\$
    – DialFrost
    Commented Nov 20, 2022 at 5:40
  • \$\begingroup\$ @DialFrost errr I’m not too sure I understand… it is part of the input, that’s the entire point of the challenge. \$\endgroup\$
    – Aiden Chow
    Commented Nov 20, 2022 at 8:52
  • \$\begingroup\$ You didnt state it in any part of the question! \$\endgroup\$
    – DialFrost
    Commented Nov 20, 2022 at 10:05
  • \$\begingroup\$ @DialFrost I did… “….given a board state, whose turn it is (black or white), and a move….” \$\endgroup\$
    – Aiden Chow
    Commented Nov 20, 2022 at 11:03
  • \$\begingroup\$ You didnt show it in the input examples you have :/ (NOT testcases) \$\endgroup\$
    – DialFrost
    Commented Nov 20, 2022 at 11:07
  • \$\begingroup\$ @DialFrost Wait what, but those aren't even test cases... those are just example positions to explain the game rules. Those aren't actual inputs. I haven't even made any test cases yet. \$\endgroup\$
    – Aiden Chow
    Commented Nov 20, 2022 at 17:26
  • \$\begingroup\$ Given that this challenge is already complicated enough, I suggest simplifying input to just cover white's turn (or black's, whatever). \$\endgroup\$
    – pajonk
    Commented Nov 22, 2022 at 5:45
  • \$\begingroup\$ @pajonk good idea, I will edit that in. \$\endgroup\$
    – Aiden Chow
    Commented Nov 22, 2022 at 8:33
1
\$\begingroup\$

Print the most uncommon character

Your task is to write a full program or function that prints the character(s)* that appears in your code the least. For example, if my code was AAAABBBBCCCDDD, then the program should print CD or DC.

Rules

  • All printed characters must appear at least three times in your code, but you will print only one character for each.
  • You are only printing those character(s). If your language always includes a trailing newline, then that is allowed.
  • All printed characters must be printable characters or newlines.
  • If multiple characters all appear the least, you must print them all, without separation. Order does not matter.
  • The program or function cannot be empty, so it has to be a minimum of three characters long.
  • This is , so the shortest code in bytes wins.

*Where "character(s)" is mentioned in the rules above, exceptions may be made for languages like TI-Basic or Piet which do not use characters.

Meta

  • Are there any similar questions to this?
  • Should I change the rules?
\$\endgroup\$
4
  • \$\begingroup\$ Can't find any challenges that are similar. And I think the rules itself are fine, but I personally find the * after every character a bit distracting. Maybe remove those five * and change the footnote to "*Where 'character(s)' is mentioned in the rules above, exceptions may be made for languages like TI-Basic or Piet, which do not use characters." And just to make sure: the shortest program is 3 bytes with three of one character, that outputs one of such character? \$\endgroup\$ Commented Nov 25, 2022 at 16:18
  • \$\begingroup\$ Also, is there any reason why you specifically said 'full program', as apposed to the default program/function? The default is there for languages with verbose boilerplate code like Java or .NET C#. \$\endgroup\$ Commented Nov 25, 2022 at 16:37
  • \$\begingroup\$ @KevinCruijssen The shortest possible solution would indeed be 3 characters long. I found that a full program would fit better for a self-referential challenge, but I suppose a function would also be fine. I will replace the *s in the rules. \$\endgroup\$
    – Yousername
    Commented Nov 25, 2022 at 19:43
  • \$\begingroup\$ I think a lot of languages will have the solution 000. Additionally, I think it isn't a great idea to say "character" as characters are things that we see, rather than the bytes that make up a program. For example, should the Jelly program AAA output A or )? Both are 0x41 (what appears in the program) but one is the ASCII code page and the other is the Jelly code page. \$\endgroup\$ Commented Nov 28, 2022 at 20:30
1
\$\begingroup\$

Find the nth number where the digit sum equals the number of factors

\$\endgroup\$
3
  • \$\begingroup\$ Tag: sequence \$\endgroup\$
    – naffetS
    Commented Nov 26, 2022 at 3:23
  • \$\begingroup\$ Since this is sequence, can we use default sequence rules and output infinitely? Or return the first n numbers? \$\endgroup\$
    – naffetS
    Commented Nov 26, 2022 at 3:24
  • 1
    \$\begingroup\$ @Steffan yes you can. I've edited it into the challenge. \$\endgroup\$
    – The Thonnu
    Commented Nov 26, 2022 at 7:07
1
\$\begingroup\$

Range of ASCII values

\$\endgroup\$
1
\$\begingroup\$

Join Columnar Strings

Tags:

\$\endgroup\$
2
  • \$\begingroup\$ "You may NOT assume inputs are ASCII only" seems like a really bad rule. It heavily restricts the challenge for a ton of languages and adds absolutely nothing. \$\endgroup\$
    – rydwolf
    Commented Nov 28, 2022 at 16:45
  • \$\begingroup\$ @RadvylfPrograms edited to ascii only \$\endgroup\$
    – bigyihsuan
    Commented Nov 28, 2022 at 18:04
1
\$\begingroup\$

Merged strings

Not sure if this is already done

Basically, take two strings of reasonable length (like <32 chars) of numbers and X's and find the shortest superposition of those strings such that there's no 2 numbers at the same position. Number+X or X+X is allowed. Print the result.

Examples:

["01XX02","10XX2"]
-----
010X02

["5234XXX","431XXX"]
-----
523431XXX

Note:

  • Even if the string ends with X's, print those X's as they're part of the strings.
  • Oh and the result must start with the first string. (like test 4)

Tests:

1234   | 345    -> 12345
6573   | 2625   -> 65732625
11X    | 12     -> 112
XX1XX  | XX2XX  -> XX12XX
X1X2X3 | 1XX234 -> X1X2234

Scoring

The program with the least bytes wins!

\$\endgroup\$
2
  • \$\begingroup\$ In the current form this question is unclear. Please expand a bit and include test cases. Make sure to also include a scoring criteria \$\endgroup\$ Commented Dec 4, 2022 at 14:31
  • \$\begingroup\$ @mousetail Is it better? \$\endgroup\$
    – SuperPizz
    Commented Dec 4, 2022 at 15:38
1
\$\begingroup\$

><> numbers metagolf

\$\endgroup\$
1
  • \$\begingroup\$ I suggest linking to TIO (tio.run/#fish) or other online interpreter in the section "you can test your programs..." \$\endgroup\$
    – pajonk
    Commented Nov 30, 2022 at 13:49
1
\$\begingroup\$

KotH: Don't Kill the Curve!

In this KotH, you will take a test at school. Your goal, of course, is to get the highest grade, up to a maximum of 110%. This score consists of your actual grade, curved, as well as 10% which is the average of other students' scores, since your teacher wants to encourage students to study together.

You have a minimum of 100 turns leading up to the test. You can use these to either:

  • Study: This add a point to your score (initially 0), unless your score is already 100
  • Tutor: Adds two points to the score of any other student, up to a max of 100
  • Arson: Majorly disrupt another student's life, dropping their score by 10 points (down to a minimum of zero), and negating their next 10 actions as they rebuild their life

Arson requires a lengthy jail sentence, meaning that your next 10 actions are also negated. If you have fewer than 10 actions left, you miss the test, and must retake it, making the maximum score you can receive (after the curve, before the bonus from other students) 70 points. Your real score is still used in the class average. Note that being an arson victim in the last 10 turns does not prevent you from taking the test; it only prevents you from studying, tutoring, or paying it forward.

You can also miss the test by taking more than 100 turns. After 100 turns you can only tutor or commit arson against other students which have not yet taken the test. Missing the test normally still has the same impact as if you had missed it while in jail, so it is likely only an effective strategy if you would otherwise receive a score below 70 (perhaps due to being an arson victim or avid tutor).

The test is also curved. Whichever student has the highest raw score will have theirs adjusted to 100, and that same shift will be applied to all other students. The curve is not taken into account for student averages, so if all students receive a 20% raw score, they would receive 102% as their final score (if they did not miss the test).

Information:

You are aware of all other students' scores on previous tests, your own "preparedness" (the raw score you would get if you took the test now), and the list of students who are recovering from arson and/or in jail.

\$\endgroup\$
4
  • \$\begingroup\$ The cooperative aspect seems like it's intended to be a major aspect, but since the average score will be applied to all bots there seems to be no benefit to helping others for the final ranking. Unlike a real test where absolute score matters. \$\endgroup\$ Commented Dec 10, 2022 at 7:19
  • \$\begingroup\$ @mousetail That's a good point. One thing I'm considering, not sure if this would fix the problem, is running different combinations of bots instead of all of them for every game. That way a bot that's really bad at collaborating would lose points for pretty much every game, while the others it's matched with would only lose points due to it on a few games, giving the bad bot a lower total amount of points. \$\endgroup\$
    – rydwolf
    Commented Dec 10, 2022 at 16:01
  • \$\begingroup\$ Yes that might be better. You could even consider putting multiple copies of each bot in each classroom to increase the benefit of cooperation even more \$\endgroup\$ Commented Dec 10, 2022 at 16:28
  • \$\begingroup\$ @mousetail Ooh that's a good idea. Maybe even running a bot against itself only could be interesting. \$\endgroup\$
    – rydwolf
    Commented Dec 10, 2022 at 16:29
1
\$\begingroup\$

Smallest and largest 100-bit square with maximum Hamming weight

\$\endgroup\$
1
\$\begingroup\$

Two-leg train journey

Joseph wants to travel by train from town A to town C. There is no direct train, so he wants to transfer in town B. You get the railway timetables from A to B and from B to C, and the latest time when Joseph needs to arrive to C. Compute the latest time that Joseph can arrive to the railway station in A and still be in time.

Times are given as integers between 0 and 1440, meaning the number of minutes from midnight on the day of the journey. A schedule from a town to another is given as a list of pairs, each pair made of two times, namely the time when the train departs from the first station and the time when it arrives to the second station. Your program gets three inputs: the train schedule from town A to town B, the train schedule from town B to town C, and the time when Joseph has to arrive to C the latest. Your program must output a single time, namely the latest time when Joseph has to be on station A.

The transfer at B is immediate, so if the first train arrives to B at exactly the same time as the second train departs from B then Joseph can transfer. You can assume that there are enough trains that Joseph can arrive at the required time or earlier. You can also assume that each schedule is sorted by departure time, but you cannot assume that the schedule is sorted by arrival time. For example, in the example input below, the first train from B departs at time 319 (meaning 09:27) and arrives at time 567 (meaning 9:27), but the second train departs at 366 and arrives at 539, overtaking the first train. Joseph is in a hypothetical country where trains always run exactly in time according to their schedule.

Here's a non-golfed example solution in Python 3. The function transfer solves the problem. The function travel takes just one schedule and finds when you have to arrive to the station where the trains in that schedule start.

def travel(schedule, arrival):
    departure = -2000
    for train in schedule:
        if train[1] <= arrival and departure < train[0]:
            departure = train[0]
    return departure
def transfer(schedule0, schedule1, arrival1):
    return travel(schedule0, travel(schedule1, arrival1))

Here's how we invoke the above example solution with an example input triple.

print(transfer(
    ((270, 294), (337, 357), (390, 414), (457, 477), (510, 534), (577, 597), (630, 654), (697, 717), (750, 774), (817, 837), (870, 894), (937, 957), (990, 1014), (1057, 1077), (1110, 1134), (1230, 1254), (1338, 1362)),
    ((319, 567), (366, 539), (540, 714), (545, 809), (780, 954), (785, 1055), (900, 1074), (905, 1169), (1025, 1280), (1140, 1324)),
    720))

This prints 510, which is the correct output for these inputs. In station A, Joseph will take the train at time 510 (meaning 08:30), arrive to B at time 534 (08:54), get on the second train at time 540 (09:00), and arrive to C at time 714 (11:54), which is not later then the deadline time 720 (12:00).

This is a slightly modified version of an easy programming homework problem that I posed many years ago. I am shamelessly copying the single example input from there, since I'm too lazy to make up a new one.

Golf Sandbox, besides all the other feedback, please tell me what tags I should use.

\$\endgroup\$
1
  • \$\begingroup\$ This would benefit from test cases. \$\endgroup\$ Commented Dec 16, 2022 at 20:15
1
\$\begingroup\$

A decimal-based unit of time

\$\endgroup\$
1
\$\begingroup\$

Is this position a pure mirror mate?

\$\endgroup\$
2
  • \$\begingroup\$ I would add a test case where there is a white piece adjacent to the black king. I'd also add a test case just testing the guarding criteria. Otherwise I like it! \$\endgroup\$
    – jezza_99
    Commented Dec 21, 2022 at 1:41
  • \$\begingroup\$ Suggested test case 8/R7/4k3/2P3P1/3K4/7B/8/8. This passes all test criteria, apart from one square (C6) being attacked by the rook and guarded by the bishop, whereas your test case 2 would return False just from a test to see if there are more than two attackers per square \$\endgroup\$
    – jezza_99
    Commented Dec 21, 2022 at 21:00
1
\$\begingroup\$

Flip the order of operations

\$\endgroup\$
2
  • \$\begingroup\$ Your last test case (with the 2) contradicts the specs (only operators, parens and letters). \$\endgroup\$
    – pajonk
    Commented Dec 23, 2022 at 7:28
  • \$\begingroup\$ @pajonk thanks, fixed \$\endgroup\$ Commented Dec 23, 2022 at 7:31
1
83 84
85
86 87
162

You must log in to answer this question.

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