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

4766 Answers 4766

1
43 44
45
46 47
159
2
\$\begingroup\$
\$\endgroup\$
0
2
\$\begingroup\$

Enumerate all pure sets

\$\endgroup\$
2
  • 1
    \$\begingroup\$ sequence IO? \$\endgroup\$
    – pxeger
    Commented Jun 12, 2022 at 9:05
  • \$\begingroup\$ @pxeger Good idea :P \$\endgroup\$
    – emanresu A
    Commented Jun 12, 2022 at 9:13
2
\$\begingroup\$

Is it a heapable sequence?

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

Find the walls!

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

Interpret BigTalk

Talk is a language which takes a single bit of input and has four commands:

  • 00 If the accumulator is 0, set the accumulator to 0.
  • 01 If the accumulator is 0, set the accumulator to 1.
  • 10 If the accumulator is 1, set the accumulator to 0.
  • 11 If the accumulator is 1, set the accumulator to 1.

These can be interpreted as replacement commands. We're going to extend that concept to positive integers, and make the language more complicated.

The language we're going to be defining is called BigTalk. It has an accumulator, which is a list of positive integers, initially set to only the input.

Programs are a series of commands. Each command is a pair of lists of integers, like ([24, 2], [32, 1]), and means to replace the first as a sequence with the second, as many times as it occurs.

The program runs repeatedly until the accumulator does not change. Finally, the accumulator is output.

For example, with the input [5, 5, 5, 5] and the program ([5, 5], [3, 2, 1]), ([3], [5]), ([2, 1, 5], [5, 1, 2]), the list goes:

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

Your challenge is to interpret this language. You may take input and program in any reasonable format.

This is , shortest wins!

Testcases

In the format of input, commands.

[5, 5, 5, 5], ([5, 5], [3, 2, 1]), ([3], [5]), ([2, 1, 5], [5, 1, 2]) -> [5, 2, 1, 1, 2, 2, 1]
[4], ([4], [4, 4]) -> Infinite loop
[2, 19, 13], ([13, 19], [2]) -> [2, 19, 13]
[39, 1, 23], ([1], [39, 23]), ([39, 39], [1, 1]), ([23, 23], [1]) -> [39, 23, 39, 23, 39, 23]

This language may be Turing-complete, and I have a +50 bounty for someone who proves it either way.

\$\endgroup\$
0
2
\$\begingroup\$

How far from binary?

\$\endgroup\$
3
  • \$\begingroup\$ Your description doesn't quite match your test cases. It should probably say that the absolute value of n-m is composed only of 1s and 0s. Since negative numbers have -. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jun 15, 2022 at 8:40
  • \$\begingroup\$ @WheatWizard Why is it necessary? -101 is a signed binary. \$\endgroup\$
    – Fatalize
    Commented Jun 15, 2022 at 8:46
  • 1
    \$\begingroup\$ -101 is not a binary string. It might be reasonable to interpret the intended way, but I certainly think it's more reasonable to interpret it another way. I don't see any harm in being explicit. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jun 15, 2022 at 8:48
2
\$\begingroup\$

Parse this handy graph format

There's a great number of ways to represent directed graphs like the following: Three examples of directed graphs

Most representations are tailored towards being easy to work with, either for humans (like the picture above) or for computers (like an adjacency matrix representation). A middle ground I found useful in the past is this format:

        A -> B <-> C                A -> B -> C -> A           A -> C -> D; B <-> C <-> E

It is basically a condensed edge list, which is still relatively close to a graphical representation (good for humans) but not too hard to parse for a computer.

The goal in this challenge is to take a string representing a graph in this format as input and output a list of the graph's nodes and a list of the graph's edges.

This is , so try to use as few bytes as possible in the language of your choice.

Input specification

  • Each node has a unique name consisting of alphabetical letters, for example A, b, or Node. It is also fine if you only support upper or lower case names.
  • Three types of arrows can appear: ->, <-, and <->.
  • A chain is formed by a sequence starting with node and then alternating between arrows and nodes, for example A -> B <- C or also just A.
  • A chain may be followed by another chain with ; as a separator in between.
  • Between node names and the arrows and the semicolon can be any number of spaces (including zero).
  • Self-loops are possible, i.e., A -> A describes an arrow from node A to itself.
  • You may assume the input string is a valid encoding of a graph.

Output specification

  • The list of nodes can be returned or printed in any reasonable format and order, e.g., A, B, C, ["A", "B", "C"], A\nB\nC, ...
  • Edges are represented as ordered tuples in any reasonable format, e.g., ("A", "B") or A B for the edge A -> B and ("D", "C") or D C for the edge C <- D.
  • The list of directed edges can again be output in any reasonable format.

Test cases

"A -> B <-> C"               : ["A", "B", "C"], [("A", "B"), ("B", "C"), ("C", "B")]
"A -> B -> C -> A"           : ["A", "B", "C"], [("A", "B"), ("B", "C"), ("C", "A")]
"A -> C -> D; B <-> C <-> E" : ["A", "B", "C", "D", "E"], [("A", "C"), ("C", "D"), ("B", "C"), ("C", "B"), ("C", "E"), ("E", "C")]
"AA<->BB"                    : ["AA", "BB"], [("AA", "BB"), ("BB", "AA")]
"A;B"                        : ["A", "B"], []
" "                          : [], []
"   A   <- B  ;  C  "        : ["A", "B", "C"], [("B", "A")]
"A -> A; B <- B"             : ["A", "B"], [("A", "A"), ("B", "B")]

Sandbox question:

Given that this is foremost a question, I'm tempted to drop the validity assumption and require answers to raise an error if the input does not follow the spec. What do you think, would that still be fun?

\$\endgroup\$
2
  • \$\begingroup\$ Definitely don't require validity. That makes the challenge two quite different challenges, and is in no way necessary. \$\endgroup\$
    – emanresu A
    Commented Jun 27, 2022 at 1:00
  • 1
    \$\begingroup\$ ^ probably a typo, but 100% you should allow users to assume validity. Don't require validity checking. \$\endgroup\$ Commented Jun 30, 2022 at 2:06
2
\$\begingroup\$

Flood fill by distance

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I suggest using a different character than O for obstacles, because it looks too much like 0. Maybe #? \$\endgroup\$
    – pxeger
    Commented Jun 20, 2022 at 12:52
  • 1
    \$\begingroup\$ In your third code block, the last two grids still use O intead of X in two places each. \$\endgroup\$
    – naffetS
    Commented Jun 25, 2022 at 21:24
2
\$\begingroup\$

Nest some addition

  • There's a natural follow-up with the other possible addition operator, where the order of application is reversed, i.e. \$\operatorname{add2}\overparen{\underparen a}\overparen{\underparen b} f=\left(\overparen{\underparen b} f\right)\circ\left(\overparen{\underparen a} f\right)\$.
\$\endgroup\$
10
  • \$\begingroup\$ Even though I've dabbled in similar contexts before, I would have been helped by a reminder to think of everything in terms of functions which act on functions. \$\endgroup\$
    – aschepler
    Commented Jun 20, 2022 at 21:05
  • \$\begingroup\$ It looks like the multiplication and exponentiation rules are part of the "Task", but if I understand right they're really an additional comment on add or a hint which could be useful for understanding / implementing / verifying behavior. \$\endgroup\$
    – aschepler
    Commented Jun 20, 2022 at 21:14
  • 1
    \$\begingroup\$ @thejonymyster add is binary, since it expects two curried arguments. \$\endgroup\$
    – att
    Commented Jun 20, 2022 at 22:14
  • 1
    \$\begingroup\$ May I take input as \$x_0,\dots,x_a\$ without taking the integer \$a\$? \$\endgroup\$
    – alephalpha
    Commented Jun 23, 2022 at 11:45
  • \$\begingroup\$ @alephalpha that should be allowed by default \$\endgroup\$
    – att
    Commented Jun 23, 2022 at 18:21
  • \$\begingroup\$ I think the \$ \mathsf {formatting} \$ might be clearer if you denoted "Church numeral of \$ n \$" as something like \$ [n] \$. Because at the moment, it's not entirely clear that \$ \mathsf {a^b} \$ means \$ [a^b] \$ and not \$ [a]^{[b]} \$ (which doesn't make any sense) \$\endgroup\$
    – pxeger
    Commented Jun 27, 2022 at 7:21
  • \$\begingroup\$ @pxeger What do you think about \$\overparen{\underparen n}\$ / \$\overparen{\underparen{a^b}}\$ (or maybe only over)? I feel like braces add a bit too much clutter. \$\endgroup\$
    – att
    Commented Jun 27, 2022 at 19:36
  • \$\begingroup\$ @att Sure, both work fine \$\endgroup\$
    – pxeger
    Commented Jun 27, 2022 at 19:38
  • \$\begingroup\$ @thejonymyster I think "where ∘ denotes function composition" should be sufficient (it's also defined as the multiplication rule) \$\endgroup\$
    – att
    Commented Jun 27, 2022 at 22:22
  • \$\begingroup\$ Oh, i skimmed right over that. I guess my friend just can't read :P \$\endgroup\$ Commented Jun 27, 2022 at 22:35
2
\$\begingroup\$

Is this a squashed series?

Given a string of digits, determine whether it is the concatenation of at least two ascending consecutive integers. (in decimal, with no leading zeroes)

For example, the string 7891011 is valid, because it's the concatenation of the sequence [7, 8, 9, 10, 11].

However, the string 54 could only be formed by concatenating [5, 4] (which is not ascending), or [54] (which does not have at least two numbers in it), so it is not valid.

(This challenge is essentially asking "Is it a valid input to Decipher a squashed series")

You should output using two distinct values of your choice to represent "valid" and "not valid".

Take care with leading zeroes: for example, 809 is not valid, even though it could be decomposed into [8, 09], because 09 is not a valid decimal integer.

You may assume the input does not start with a 0, and has a length of at least 2. The input will also only contain digits (and not -, so you don't need to handle negative numbers).

This is , so the shortest code in bytes wins.

Test cases

Valid

1234
7891011
293031323334
9991000

Invalid

54
66
28
3131
809

Valid numbers are given by A035333 in the OEIS.

Meta

  • Is this interesting enough? (It was just a byproduct of Decipher a squashed series)
  • Is my handling of the 809 case good? Or should I allow either output for inputs like that?
\$\endgroup\$
2
  • 2
    \$\begingroup\$ In Brachylog, this would be the exact same answer as your previous challenge, but I guess it’s mostly because of the declarative nature of the language. I don’t know if that’s interesting enough compared to the othe challenge with other language paradigms. \$\endgroup\$
    – Fatalize
    Commented Jun 28, 2022 at 13:58
  • \$\begingroup\$ Fwiw, in 05AB1E it isn't the exact same answer, but it's a pretty trivial change. My initial answer was .œ.Δ¥P; and it would be .œʒ¥P}g without the 809 test case or .œʒ¥P}ïJQO with the 809 test case (both outputting 2/1 for truthy/falsey respectively). So the 8,09 test case definitely adds something interesting, although 05AB1E's "09"==9 being truthy makes it a bit more tricky than in most other languages I'd imagine. \$\endgroup\$ Commented Jul 8, 2022 at 14:21
2
\$\begingroup\$

Is it shuffled FizzBuzz?

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

Decompress a Sparse Matrix (WIP)

The dual of this challenge.

Decompress a sparse matrix reversing the method here Compressed sparse row (CSR, CRS or Yale format).

There will be 4 inputs, either as separate variables or as a list of lists:

  • V, a list of the nonzero elements of the matrix in row-major form. This is of length NNZ (the number of nonzero elements in the original matrix)
  • NCOLS - the number of columns in the original matrix.
  • IA - a list that yields the number of nonzero elements in each row in the following way: IA[0] = 0, IA[i] = IA[i - 1] + <number of nonzero elements in row i>. The number of nonzero elements in row i is IA[i + 1] - IA[i].
  • JA - a list of the column indices of the elements in V, also of length NNZ. (zero-indexed)

Input will be a list of 3 lists and the number of columns in the original matrix, e.g. either

[
  [5, 8, 3, 6],
  [0, 0, 2, 3, 4],
  [0, 1, 2, 1],
  [4]
]

Or

V = [5, 8, 3, 6]
IA = [0, 0, 2, 3, 4]
JA = [0, 1, 2, 1]
NCOLS = 4

Output will be a decompressed matrix/list of lists:

[[0 0 0 0],
 [5 8 0 0],
 [0 0 3 0],
 [0 6 0 0]]

If your language doesn't support actual data structures, input and output may be text.

Process

  1. Create a 'matrix' of row width NCOLS.
  2. Populate the ith matrix row with N values from V if the corresponding array index (i + 1) of IA is non-zero, where N is the ith element of IA starting at the ith element of JA.
  3. repeat until V is empty
    i.e. above for the 0th matrix row IA[1] = 0, so this row has NCOLS=4 zeroes in it's first row. Then for matrix row 1, IA[2]=2 it takes 2 values from V starting at JA[1]=0. For matrix row 2, IA[3]=3 and IA[2]=2 so it takes the next (3 - 2 = 1) elements from V, starting at JA[2]=2. For matrix row 4 IA[4]=4 and IA[3]=3 so it takes the next (4 - 3 = 1) elements from V, starting at JA[3]=1.

Test cases

Input 1:

[ 5, 8, 3, 6 ]
[ 0, 0, 2, 3, 4 ]
[ 0, 1, 2, 1 ]
4

Output 1:

[[0 0 0 0],
 [5 8 0 0],
 [0 0 3 0],
 [0 6 0 0]]

Input 2

[ 10 20 30 40 50 60 70 80 ]
[  0  2  4  7  8 ]
[  0  1  1  3  2  3  4  5 ]
6

Output 2:

[[10 20 0 0 0 0],
 [0 30 0 40 0 0],
 [0 0 50 60 70 0],
 [0 0 0 0 0 80]]

Input 3:

[ ]
[ 0 0 0 0 ]
[ ]
3

Output 3:

[[0 0 0],
 [0 0 0],
 [0 0 0]]

Input 4:

[ 1 1 1 1 1 1 1 1 1 ]
[ 0 3 6 9 ]
[ 0 1 2 0 1 2 0 1 2 ]
3

Output 4:

[[1 1 1],
 [1 1 1],
 [1 1 1]]

Input 5:

[ 5, -9, 0.3, -400 ]
[ 0, 0, 2, 3, 4 ]
[ 0, 1, 2, 1, ]
4

Output 5:

[[0 0 0 0],
 [5 -9 0 0],
 [0 0 0.3 0],
 [0 -400 0 0]]

Assume inputs may contain any real number, you need not consider mathematical symbols or exponential representation (e.g. 5,000 will never be entered as 5e3). You will not need to handle inf, -inf, NaN or any other 'pseudo-numbers'. You may output a different representation of the number (5,000 may be output as 5e3 if you so choose).

Scoring

This is a , fewest bytes wins.

\$\endgroup\$
7
  • \$\begingroup\$ I'd suggest to at least briefly explain how the decompressing works in the post. The challenges should be self-contained as much as possible. \$\endgroup\$
    – Bubbler
    Commented Apr 22, 2021 at 23:55
  • \$\begingroup\$ @bubbler, that's coming, but I need to figure out how to do that/explain it myself. I've left (WIP) on the question because of this. \$\endgroup\$ Commented Apr 23, 2021 at 0:11
  • 1
    \$\begingroup\$ @Pureferret I think it would be better to allow only nonzero integers instead of any real number. It'd be easier for most languages that way \$\endgroup\$
    – user
    Commented May 2, 2021 at 20:59
  • \$\begingroup\$ @user I think it's more interesting seeing those languages work around those difficulties. Also the original challenge required them, so it I my makes sense this one does too. \$\endgroup\$ Commented May 2, 2021 at 21:14
  • \$\begingroup\$ @Pureferret I'm not sure many golfing languages support arbitrary precision floating point numbers. Would they be able to use strings, then? Edit: could you at least restrict it to rational numbers? Unlike Jon Skeet, most of us here don't know all the digits of pi :P \$\endgroup\$
    – user
    Commented May 2, 2021 at 21:17
  • \$\begingroup\$ @user it needn't be arbitrary, just as long as it matches the test cases \$\endgroup\$ Commented May 2, 2021 at 23:46
  • \$\begingroup\$ @Bubbler I think the process is correct? \$\endgroup\$ Commented Jun 29, 2022 at 16:17
2
\$\begingroup\$

Round it up Nicely

When I work out, I often don't have a good plan for how many times to repeat an exercise, but in the interest of pushing myself I always keep going until I've done a "nice" number. Multiples of 5 are ideal, but multiples of 4 are acceptable too--unless they're 1 less than a multiple of 5, in which case I may as well do one more, or they're 1 more than a multiple of 5, in which case why didn't I already stop?

The challenge

Given an integer \$n\$ and a descending, pairwise coprime list of integers \$k_1, k_2, ..., k_m\$, output the least integer \$x \geq n\$ which is a multiple of some \$k_i\$ but is not 1 more or less than any multiple of any \$k_j\$ with \$j<i\$.

Test cases

n    k[1]...k[m]                        result
1    [5, 4]                             5
15   [5, 4]                             15
12   [5, 4]                             12
16   [5, 4]                             20
7    [5, 4]                             8
996  [5, 4]                             1000
1    [11, 7]                            7
15   [11, 7]                            22
133  [11, 7]                            140
1    [5, 3, 2]                          3
6    [5, 3, 2]                          10
6    [5, 3]                             10
11   [5, 3, 2]                          12
1    [100, 49, 9]                       9

Sandbox

  • Would it be more interesting without the descending/coprime guarantees?
  • Test cases are a WIP, but any additional suggestions?
  • Better title?
  • [How] should I note that the 1-above exclusion only matters if it would exclude the input itself? Should the task not be "rounding up" to make it more relevant?
\$\endgroup\$
2
  • 1
    \$\begingroup\$ the "dynamic goal" thing made me think it was going to be a challenge about determining how much excersize youd be doing in a given section, the sequence thing seems way out of left field and the requirements to be a workout number arbitrary, even in relation to the lore \$\endgroup\$ Commented Feb 3, 2022 at 4:43
  • 1
    \$\begingroup\$ Could you please use words to describe the challenge? I do read quantifiers, but I suspect not all golfers do. \$\endgroup\$
    – pajonk
    Commented Jun 30, 2022 at 6:25
2
\$\begingroup\$

Draw the Progress Pride flag

\$\endgroup\$
3
  • \$\begingroup\$ This is a really nice flag. It breaks one of the "golden rules of flag design" (no more than 3 colours) but that's the point. And harder to draw than it looks because you can't just draw a triangle for the brown and black. The spec is slightly inconsistent: the height calculated from the diagonal strip width is (340+170+170)*2 = 1360 which differs from the height calculated from the horizontal strip width 224 * 6 = 1344 so you might wat to fix that. \$\endgroup\$ Commented Jun 24, 2022 at 21:04
  • 1
    \$\begingroup\$ I think the spec is reasonably clear but I have a few suggestions: 1. delete the word "obviously" - too patronizing. BTW this is covered by one of the standard loopholes here on Meta - it's always good to reference them. 2. So the minimum size is 1100 x 672? I recommend you state it explicitly rather than saying "only half" . "Exactly" is a strong word (especially when 170/sqrt 2 is actually 120.20815 ) - I recommend an error of 1 pixel. \$\endgroup\$ Commented Jun 24, 2022 at 21:12
  • \$\begingroup\$ Thanks for the response I’ll fix this on Wednesday \$\endgroup\$
    – Alice F
    Commented Jun 26, 2022 at 19:01
2
\$\begingroup\$

Draw this fractal generated by applying Newton's method to cosh(x) - 1

\$\endgroup\$
1
  • 1
    \$\begingroup\$ ooh seems really fun \$\endgroup\$
    – math scat
    Commented Jul 1, 2022 at 18:13
2
\$\begingroup\$

Implement Binary Exponentiation

\$\endgroup\$
1
  • \$\begingroup\$ interestingly you can do the same thing with binary or peasant multiplication. actually any associative operation. \$\endgroup\$
    – qwr
    Commented Jun 26, 2022 at 21:16
2
\$\begingroup\$

Is it an ordinal?

\$\endgroup\$
2
  • \$\begingroup\$ An interesting variation could be an open-ended-function sequence with the task being to generate every ordinal. Although I don't know if there would be a better way to answer that than smushing this decision problem and a "generate every ragged list" algorithm. \$\endgroup\$
    – pxeger
    Commented Jun 30, 2022 at 10:54
  • \$\begingroup\$ @pxeger There's no way to generate every ordinal. There are uncountable ordinals, as well as countable but incomputable ordinals. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jul 7, 2022 at 7:23
2
\$\begingroup\$

Draw the USA flag

\$\endgroup\$
1
  • 3
    \$\begingroup\$ "then your score is half of your program's length" is generally not welcomed here. \$\endgroup\$
    – tsh
    Commented Jul 4, 2022 at 6:33
2
\$\begingroup\$

Convert from Greeklish to modern Greek

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I like natural language challenges, however it seems a bit boring. I feel like we must have a few challenges already that are a substitution cypher with digraphs, and it probably isn't really doing anything new there. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jul 7, 2022 at 7:18
  • \$\begingroup\$ @WheatWizard I understand that character substitution challenges do exist in the site. However, from my search of the sandbox, there isn't one for Greek, so it's somewhat original. Therefore, I am considering to post this. If this goes any well, I will also consider posting a harder natural language Greek challenge ;) \$\endgroup\$
    – solid.py
    Commented Jul 7, 2022 at 8:08
  • \$\begingroup\$ I just don't think that it being Greek actually makes the task any more interesting. Like it's neat, but the task is just a very simple substitution. If you have a harder challenge about Greek I'd say go with that one first. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jul 7, 2022 at 8:26
  • \$\begingroup\$ @WheatWizard Since I made the effort to post and polish this a bit, I will post it. If it doesn't receive as much upvotes due to its unoriginality so be it. This site runs for many years and its hard to come up with something 100% original. Personally, I think its a solid challenge. Finally, I will also link to other related challenges, as I've seen quite recently on non-original challenges. \$\endgroup\$
    – solid.py
    Commented Jul 7, 2022 at 8:41
2
\$\begingroup\$

Solve a Card Suit Puzzle

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

Every possible pairing

\$\endgroup\$
1
  • \$\begingroup\$ Seems a little on the simple side I think. Might be a duplicate, but if it's not I think it's likely to score very well. :) \$\endgroup\$
    – Wheat Wizard Mod
    Commented Jul 8, 2022 at 20:05
2
\$\begingroup\$

Infinite Fibonacci word

The famous Fibonacci sequence of integers is defined as follows:

\$ F_0 = 0 \\ F_1 = 1 \\ F_n = F_{n-1} + F_{n-2} \$

But what if we use this same recurrence relation to produce an infinite sequence of strings? Instead of addition, we'll use concatenation. We'll also change the base case slightly:

\$ F_0 = \$ 0
\$ F_1 = \$ 01
\$ F_n = F_{n-1}F_{n-2} \$

The first few strings are:

0
01
010
01001
01001010
0100101001001
...

Each of these "words" is a prefix of the next, so they are all prefixes of the single infinite word \$ F_\infty = \$

010010100100101001010010010100100101001010010010100101001001010010010100101001001010010010100101001...

Your task is to output this infinite string as a sequence; you may choose to use any two distinct values to use for 0 and 1.

As with standard challenges, you may choose to either:

  • Take an input \$ n \$ and output the \$ n \$th item in the sequence
  • Take an input \$ n \$ and output the first \$ n \$ item
  • Output the sequence indefinitely, e.g. using a generator

and you may use 0-based or 1-based indexing for \$ n \$.

This string can be defined in many different ways; its OEIS entry A003849 and Wikipedia page have more information.

Errors due to floating-point imprecision are not allowed.

This is , so the shortest code in bytes wins.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Seems very similar to the infinite quote escaping sequence \$\endgroup\$
    – mousetail
    Commented Jul 15, 2022 at 13:05
  • 1
    \$\begingroup\$ It doesn't seem like it should be binary - 0 and 1 have no special meaning, they can be replaced by any symbol \$\endgroup\$ Commented Jul 15, 2022 at 13:07
  • \$\begingroup\$ @mousetail Yes, in fact the Fibonacci word can also be formed using a string rewriting rule like the quote sequence. In this case it's replacing 0 with 01, and 1 with 0. \$\endgroup\$
    – pxeger
    Commented Jul 15, 2022 at 13:11
  • \$\begingroup\$ This is a interesting challenge, however, of the 2 challenges I think the other one is slightly more interesting. \$\endgroup\$
    – mousetail
    Commented Jul 15, 2022 at 13:13
  • 1
    \$\begingroup\$ @mousetail Who's to say we can't have both? I think they're definitely not duplicates, because both have multiple different approaches, only one of which somewhat overlaps. \$\endgroup\$
    – pxeger
    Commented Jul 15, 2022 at 13:14
  • \$\begingroup\$ Fair enough, though I'd suggest to post it after the other challenge to acknowledge the inspiration \$\endgroup\$
    – mousetail
    Commented Jul 15, 2022 at 13:24
  • \$\begingroup\$ @mousetail It was not deliberately inspired by that challenge at all. (Maybe subliminally, because I had seen that challenge perviously?). But I learnt about the Fibonacci sequence independently while browsing Wikipedia. \$\endgroup\$
    – pxeger
    Commented Jul 15, 2022 at 13:26
  • \$\begingroup\$ I think you should specify if floating-point errors are allowed, since some approaches will probably use the golden ratio \$\endgroup\$ Commented Jul 16, 2022 at 4:35
  • \$\begingroup\$ @CommandMaster I've added a note about that, but AFAICT there aren't any direct methods to make the string using φ \$\endgroup\$
    – pxeger
    Commented Jul 16, 2022 at 7:43
  • 3
    \$\begingroup\$ Duplicate? \$\endgroup\$
    – pajonk
    Commented Jul 16, 2022 at 8:57
  • \$\begingroup\$ @pxeger the OEIS entry says "a(n) = floor((n+2)*r) - floor((n+1)*r) where r=phi/(1+2*phi) and phi is the Golden Ratio." \$\endgroup\$ Commented Jul 16, 2022 at 9:22
2
\$\begingroup\$

Add parentheses to Polish notation

\$\endgroup\$
4
  • \$\begingroup\$ Suggested test-case with multi-digit numbers. Also, are the numbers guaranteed to be positive? \$\endgroup\$
    – pajonk
    Commented Aug 4, 2022 at 12:50
  • \$\begingroup\$ I think they should be limited to being positive. \$\endgroup\$ Commented Aug 4, 2022 at 14:47
  • 2
    \$\begingroup\$ I'd suggest removing the edge case that extra trash at the end needs removed (such as the + 1 2 3 test case). Of course, it's your challenge, just a suggestion. I prefer sticking to the actual problem, and not adding extra edge cases. \$\endgroup\$
    – naffetS
    Commented Aug 4, 2022 at 17:23
  • \$\begingroup\$ That was just a typo, sorry about that \$\endgroup\$ Commented Aug 4, 2022 at 18:29
2
\$\begingroup\$

Change The Quotations as if in Microsoft Word

META: Posted

\$\endgroup\$
6
  • \$\begingroup\$ What to do with consecutive quotation marks? Or this won't ever be an input? \$\endgroup\$
    – pajonk
    Commented Aug 7, 2022 at 15:17
  • \$\begingroup\$ I've added a rule for that. \$\endgroup\$ Commented Aug 8, 2022 at 5:58
  • \$\begingroup\$ What will be the output for ''' and ''''? I other words, what is the precedence of the rules? \$\endgroup\$
    – pajonk
    Commented Aug 8, 2022 at 6:02
  • \$\begingroup\$ I've edited the rule I just added to accommodate these strings. Check it out. \$\endgroup\$ Commented Aug 8, 2022 at 6:08
  • \$\begingroup\$ How come makes a brief appearance in rule 5 and nowhere else? \$\endgroup\$ Commented Aug 8, 2022 at 12:40
  • \$\begingroup\$ Oops, didn't delete that. \$\endgroup\$ Commented Aug 12, 2022 at 7:39
2
\$\begingroup\$

Carry-less sum given a base b

posted

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

Are these numbers from the repeated application of this function?

Given a list of at least 3 positive integers \$L\$ and a function \$F\$ which takes a positive integer and returns a positive integer, determine if \$L\$ can be sorted such that each element of the list is the result of applying \$F\$ to the previous element (besides the first of course).

Rules

  • You may, of course, assume that \$F\$ always halts.
  • You may also assume that \$F\$ will have no side-effects and is deterministic.
  • You may take the \$F\$ as a black box function in any reasonable format.
  • Instead of taking \$F\$ as an input, you may take a second list \$M\$, which is the result of applying \$F\$ to each element of \$L\$.
  • This is , shortest solution in bytes wins.

Very simple worked out example

Inputting \$F(x)=x+1\$ and \$L=[5,4,3,2,1]\$ should output truthy, because \$L\$ can be rearranged into \$[1,2,3,4,5]\$, for which each element is the result of applying \$F\$ to the previous element: \$F(1)=2\$, \$F(2)=3\$, \$F(3)=4\$, and \$F(4)=5\$.

More examples:

Truthy

F(x) = 2x,           L = [4,2,1,8]
F(x) = ceil(10/x),   L = [2,2,2,5,5,5]
F(X) = 3x+1,         L = [5,16,49,148]
F(x) = length(x),    L = [1,2,10,9876543210,1]
F(x) = 13            L = [13,13,13,13,14]

Falsy

F(x) = 2x,           L = [2,4,6,8]
F(x) = ceil(10/x),   L = [5,2,5,2,5,2,5,5]
F(X) = 3x+1,         L = [5,16,8,4,2,1,4]
F(x) = length(x),    L = [3,1,10,2]
F(x) = 13            L = [13,13,13,14,15]

META

Is this ready to post or is it missing something / bad somewhere

\$\endgroup\$
7
  • 1
    \$\begingroup\$ You might want to clarify that black-box functions are allowed .See: 1 2 3 4 \$\endgroup\$
    – naffetS
    Commented Aug 23, 2022 at 23:16
  • \$\begingroup\$ Almost certainly this has very little to do with functional programming (other than the fact that the program should take a function as input). On the other hand, there is a proposed guideline for decision problem outputs. \$\endgroup\$
    – Bubbler
    Commented Aug 24, 2022 at 5:42
  • 1
    \$\begingroup\$ You can refer to these for black box function input methods. Currently the top two are accepted (predefined named functions and function arguments are both OK). \$\endgroup\$
    – Bubbler
    Commented Aug 24, 2022 at 5:47
  • 1
    \$\begingroup\$ Is there a reason the function is part of the input, instead of the input being something like L[i], F(L[i])? \$\endgroup\$ Commented Aug 24, 2022 at 11:32
  • \$\begingroup\$ @CommandMaster Interesting, I suppose that has about the same effect. I will probably edit this to allow both input formats, though I'll have to think about it \$\endgroup\$ Commented Aug 24, 2022 at 12:31
  • \$\begingroup\$ Doesn't that trivialize the task though? It's just checking whether L[1:] == M[:-1] if I understand correctly. \$\endgroup\$
    – naffetS
    Commented Aug 26, 2022 at 1:41
  • \$\begingroup\$ @Steffan you cant assume the order of the elements \$\endgroup\$ Commented Aug 26, 2022 at 1:48
2
\$\begingroup\$

Implement level-index addition

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

This is less of a challenge proposal, and more of a idea for how to mesh the two title tags.

A series of targeted fights

Consider a heads-up, 1v1 "game" between two king-of-the-hill style bots. However, unlike a general king-of-the-hill, where every bot plays against every other bot, we instead build bots that target specific bots to win against. An example of an existing bot would be Low Blow from Cooperative Counting, which aimed to identify it's opponent, then play counter to that bot. However, in this challenge, the bot wouldn't have to identify its opponent: it would only play one bot, the bot it was designed to beat.

The aspect comes from this targeting:

  • User A posts Bot A, targeting a provided example bot.
  • User B then posts Bot B, targeting Bot A.
  • User C then posts Bot C, targeting a second example bot.
  • User D then posts Bot D, also targeting Bot A.

And so on, creating a "tree" of answers, each targeting a previous answer. Note that new answers don't have to target the latest, but can instead target any previous answer.

However, to prevent bots that "target", but don't actual perform well against their target, we'd need to require that it beats its target in \$X\%\$ of \$Y\$ battles, or else it is disqualified. Obviously, this prevents bots from being edited to improve themselves once targeted.

This begs the question: what is our scoring criteria? Clearly, depth from the root bots (provided in the challenge) must be a central part, as it's harder to create a bot the further down the chain you go. However, this doesn't differentiate between Bot B and Bot D in our example, despite the fact that Bot D beats Bot A \$82\%\$ of the time, vs Bot B's meager win rate of \$61\%\$. Clearly, we should take winning rate into account. One potential score:

$$\text{Score} = \text{Win rate} \times \text{Depth}$$

where \$\text{Win rate}\$ is between \$0\$ (never wins) and \$1\$ (always wins).


Thoughts?

\$\endgroup\$
2
  • \$\begingroup\$ I don't know if this is a legitimate concern, but I'd be worried about rock-paper-scissors-like loops where A is always defeated by B, B is always defeated by C, and C is always defeated by A. In that case, it would always be advantageous to post a counter to the most recent post of A/B/C, which means that the score could go to infinity while resulting in very uninteresting bots. You could limit this by saying "no repeat answers", and people probably wouldn't do this in practice because it's boring, but it points to a possible failure mode. \$\endgroup\$ Commented Sep 10, 2022 at 17:53
  • \$\begingroup\$ @97.100.97.109 I don't think that's something to worry about. Ideally, the game would be designed such that, if Bot B beats Bot A the majority of the time, then, if Bot C defeats Bot B, it also must defeat Bot A. For example, in RPS, the "loop" style only occurs by defining the specific win/loss relationship. A 1v1 game with a points based scoring wouldn't encounter such a loop \$\endgroup\$ Commented Sep 10, 2022 at 18:25
2
\$\begingroup\$

write the "index by number" sequence

Imagine writing out positive integer numbers, and indexing each character in a 1-indexed array (indices read vertically on the top two rows, numbers read horizontally on the third):

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
one two three four five six seven eight nine ten

Now, imagine if we skipped some numbers so we write the index at the point we start the next number:

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
one five ten fourteen twenty three thirty six fo

now, imagine that the first number doesn't have to be "one":

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
      seven thirteen twenty two thirty three for

Input

A single number from 1..999, in any format you like ("1", '1', 1, "one" etc.)

This forms the starting number for the sequence

Output

A sequence of numbers, written long-hand in UK English ("one hundred and one" - no other differences), from (input)..(999) inclusive.

Code golf, usual rules.

\$\endgroup\$
9
  • \$\begingroup\$ 101 is "one hundred one" right? \$\endgroup\$ Commented Sep 4, 2022 at 1:36
  • \$\begingroup\$ @thejonymyster one hundred and one \$\endgroup\$ Commented Sep 5, 2022 at 6:33
  • \$\begingroup\$ Maybe you need include how to read number in UK English in your post. \$\endgroup\$
    – tsh
    Commented Sep 9, 2022 at 9:40
  • \$\begingroup\$ @tsh updated to try and clarify \$\endgroup\$ Commented Sep 9, 2022 at 10:15
  • 1
    \$\begingroup\$ 40 is "forty" in all standard English variants. \$\endgroup\$
    – pxeger
    Commented Sep 9, 2022 at 12:14
  • \$\begingroup\$ @pxeger TIL. Corrected in spec. Thanks \$\endgroup\$ Commented Sep 9, 2022 at 13:24
  • \$\begingroup\$ So we go up to the last number that starts before or exactly at 9999 even if it goes beyond 9999 once it's 'written'? 9999 is pretty high, btw. I think the challenge would be just as interesting but much easier to debug/verify with 999 (still high) or even 99 as the upper bound. \$\endgroup\$
    – Arnauld
    Commented Sep 19, 2022 at 20:35
  • \$\begingroup\$ @Arnauld I don't want to end up creating an edge case that needs to be coded separately, so I'm happy to take guidance on how that would work - if the input is 9999 the output would be either nine thousand nine hundred and ninety nine or n (i.e. writing index #9999 then nothing above that) - which is better? Or best left optional? \$\endgroup\$ Commented Sep 20, 2022 at 7:46
  • \$\begingroup\$ @Arnauld aside from that, I'll lower the bounds to 999 \$\endgroup\$ Commented Sep 20, 2022 at 7:46
2
\$\begingroup\$

Generate a different sudoku


Task

Given a valid sudoku board, generate another sudoku board that isn't equivalent to the one inputted.

What do we consider as equivalent sudoku boards?

  • they are the same,
  • the digits are relabeled (eg. 2<->7 or 2->5->8->2),
  • three-column or thee-row bands are permuted,
  • the rows or columns within a band are permuted,
  • one is a reflection of the other (horizontally, vertically or along any of the diagonals),
  • one is a rotation of the other,
  • or any combination of the above.

According to Ed Russell and Frazer Jarvis there are 5 472 730 538 essentially different sudoku classes.

What is a valid sudoku?

(borrowed from here)

  • Each row contains the digits from 1 to 9 exactly once.
  • Each column contains the digits from 1 to 9 exactly once.
  • Each of the nine 3x3 subgrids contains the digits from 1 to 9 exactly once.

Rules

You may take input and output in any reasonable format, like a 9x9 matrix, list of rows/columns, a string of 81 digits etc.

Taking digits 0-8 instead of 1-9 is allowed, but please be consistent.

Test cases

Input:
7 2 5 8 9 3 4 6 1
8 4 1 6 5 7 3 9 2
3 9 6 1 4 2 7 5 8
4 7 3 5 1 6 8 2 9
1 6 8 4 2 9 5 3 7
9 5 2 3 7 8 1 4 6
2 3 4 7 6 1 9 8 5
6 8 7 9 3 5 2 1 4
5 1 9 2 8 4 6 7 3
Example output:
1 2 3 4 5 6 7 8 9 
4 5 6 7 8 9 1 2 3 
7 8 9 1 2 3 4 5 6 
2 3 1 5 6 4 8 9 7 
5 6 4 8 9 7 2 3 1
8 9 7 2 3 1 5 6 4 
3 1 2 6 4 5 9 7 8
6 4 5 9 7 8 3 1 2 
9 7 8 3 1 2 6 4 5

Input:

Example output:

Meta

  • Any mistakes in the test-cases?
  • Is it sufficiently diffent to existing challenges?
  • Is it better as or a challenge to check whether two given grids are equivalent?
\$\endgroup\$
6
  • \$\begingroup\$ I think the decision-problem version would be better, since that doesn't actually involve validating a sudoku board, which i believe is already a challenge. IMO anyway. \$\endgroup\$ Commented Sep 21, 2022 at 19:51
  • \$\begingroup\$ Are there any other possible sudoku equivalencies? Or is it safe to say that's it / that's all we care about ? \$\endgroup\$ Commented Sep 21, 2022 at 19:52
  • \$\begingroup\$ You might want to use the word "permuted" instead of "swapped" (I'm pretty sure that's what you mean) \$\endgroup\$
    – Pandu
    Commented Sep 22, 2022 at 3:35
  • \$\begingroup\$ Since you were asking if you should do a related decision-problem question instead: In case you want it, here's another related question. I don't know it's that great is as is for CGCC -- feels so specific it's maybe too overspecified, but just in case it's useful: "Generate a specified equivalent sudoku given inputs originalSudoku, symbolPermutation, rowPermutations, columnPermutations, bandPermutation, stackPermutation, shouldReflect." Happy to elaborate on this if needed. \$\endgroup\$
    – Pandu
    Commented Sep 22, 2022 at 3:56
  • 1
    \$\begingroup\$ @thejonymyster in the open-ended-function challenge I was hoping for a smart solution using some transformation not listed. These transformations are actually what pops up in literature (wikipedia link) - your previous comment prompted me to research this closer. But if it isn't a case, you're right that decision-problem may be better. \$\endgroup\$
    – pajonk
    Commented Sep 22, 2022 at 4:33
  • \$\begingroup\$ @Pandu thanks for help in the wording. Regarding the challenge idea, I think you're right that it may be overspecified. \$\endgroup\$
    – pajonk
    Commented Sep 22, 2022 at 4:35
1
43 44
45
46 47
159

You must log in to answer this question.

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