567
\$\begingroup\$

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

\$\endgroup\$
0

4480 Answers 4480

1
42 43
44
45 46
150
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\$ 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\$ Jun 24, 2022 at 21:12
  • \$\begingroup\$ Thanks for the response I’ll fix this on Wednesday \$\endgroup\$
    – Alice F
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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\$ 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
    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
    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
    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
    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
    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\$ 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
    Jul 16, 2022 at 7:43
  • 3
    \$\begingroup\$ Duplicate? \$\endgroup\$
    – pajonk
    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\$ Jul 16, 2022 at 9:22
2
\$\begingroup\$

All Crossword Grids

In crossword terminology, the grid is the region into which the crossword answers are inserted, consisting of white and black squares. The crossword answers, called entries, are inserted into contiguous sequences of white squares in a row or column, separated by black squares.

Example of a crossword grid

For straight (American) crosswords, the grids usually follow a specific set of rules:

  • They should have 180 degree rotational symmetry (if there is a black square in the \$x\$th row and \$y\$th column, there should be a black square in the \$x\$th-to-last row and \$y\$th-to-last column).
  • All entries must be at least 3 squares long.
  • All white squares must be joined in a single region.
  • No row/column can be completely filled with black squares.

Some examples of invalid and valid crossword grids:

Valid and invalid crossword grids

Your challenge: given a grid consisting of two unique values representing black and white squares, determine if it's a valid crossword grid. Assume that it's a square grid with \$n\$ rows and columns (so there are \$n^2\$ white/black cells), where \$n \geq 3\$. For example, if \$n=3\$ there is only one valid grid (I'm using . for white cells and # for black cells):

...
...
...

If \$n=4\$, there are 3 valid grids:

....  #...  ...#
....  ....  ....
....  ....  ....
....  ...#  #...

If \$n=5\$, there are 12 valid grids:

.....  #....  ##...  #....  ##...  ##...  
.....  .....  .....  #....  #....  ##...  
.....  .....  .....  .....  .....  .....  
.....  .....  .....  ....#  ....#  ...##  
.....  ....#  ...##  ....#  ...##  ...##  

....#  ...##  ....#  ...##  ...##  #...#  
.....  .....  ....#  ....#  ...##  .....  
.....  .....  .....  .....  .....  .....  
.....  .....  #....  #....  ##...  .....  
#....  ##...  #....  ##...  ##...  #...#  

Examples:

Input Output Explanation
......... True Valid grid
#..............# True Valid grid
...#........#... True Valid grid
...#........#... True Valid grid
......... True Valid grid
#...#......#...# True Valid grid
......................... True Valid grid
##...#.............#...## True Valid grid
................................................. True Valid grid
........................#........................ True Valid grid
....###.....##......##.....##......##.....###.... True Valid grid
................................................................ True Valid grid
##....####....##...........##......##...........##....####....## True Valid grid
...##.......#...........##.....##.....##...........#.......##... True Valid grid
#............... False No 180 degree symmetry
#..##..##..##..# False 2-letter entries, filled-in columns
#........................ False No 180 degree symmetry
.......#...###...#....... False 1-letter and 1-letter entries
######....#....#....#.... False No 180 degree symmetry, filled-in column & row
######...##...##...###### False Filled-in columns & rows
...#......#......#......#......#......#......#... False White squares not contiguous, filled-in column
.................###....#....###................. False 1-letter entries
...#......#...............##..................... False No 180-degree symmetry
....#.......#.......#........######........#.......#.......#.... False White squares not contiguous
..#.........#.......#......##......#.......#.......#.........#.. False 1-letter and 2-letter entries
.#......#..............................................#......#. False 1-letter entries, white squares not contiguous
...........................##......#............................ False No 180-degree symmetry
####............................................................ False No 180-degree symmetry
#......##......##......##......##......##......##......##......# False Filled-in columns

Standard loopholes are forbidden. Shortest code wins.

Sandbox Questions

I may have misused some crossword terminology above, let me know if I can improve the explanation.

I also don't know if the final rule should be included, since it's not usually explicitly stated when constructing crosswords.

I'm considering adding an optional parameter \$n\$ which describes the number of rows/columns to make the input easier to parse, but I don't know how people feel about optional parameters.

\$\endgroup\$
4
  • \$\begingroup\$ Suggested tags: crossword, grid \$\endgroup\$
    – pajonk
    Jul 27, 2022 at 5:45
  • 3
    \$\begingroup\$ I don't see any clever algorithm for grid generation (that doesn't mean that there isn't one), so the answers are most likely use the brute-force method of generating all grids and checking their crosswordness - why not make it decision-problem then? \$\endgroup\$
    – pajonk
    Jul 27, 2022 at 5:51
  • \$\begingroup\$ @pajonk I've modified the question as per your suggestion, but that makes it very similar to a previously posed question, so I'm unsure about this. I think there are some meaningful shortcuts to make the generation easier. \$\endgroup\$ Jul 27, 2022 at 18:56
  • \$\begingroup\$ if you see shortcuts that make generation easier than brute-force, then ignore my previous comment. \$\endgroup\$
    – pajonk
    Jul 28, 2022 at 9:36
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
    Aug 4, 2022 at 12:50
  • \$\begingroup\$ I think they should be limited to being positive. \$\endgroup\$ 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
    Aug 4, 2022 at 17:23
  • \$\begingroup\$ That was just a typo, sorry about that \$\endgroup\$ 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
    Aug 7, 2022 at 15:17
  • \$\begingroup\$ I've added a rule for that. \$\endgroup\$ 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
    Aug 8, 2022 at 6:02
  • \$\begingroup\$ I've edited the rule I just added to accommodate these strings. Check it out. \$\endgroup\$ Aug 8, 2022 at 6:08
  • \$\begingroup\$ How come makes a brief appearance in rule 5 and nowhere else? \$\endgroup\$ Aug 8, 2022 at 12:40
  • \$\begingroup\$ Oops, didn't delete that. \$\endgroup\$ 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
    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
    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
    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\$ 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\$ 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
    Aug 26, 2022 at 1:41
  • \$\begingroup\$ @Steffan you cant assume the order of the elements \$\endgroup\$ 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\$ 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\$ 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\$ Sep 4, 2022 at 1:36
  • \$\begingroup\$ @thejonymyster one hundred and one \$\endgroup\$ Sep 5, 2022 at 6:33
  • \$\begingroup\$ Maybe you need include how to read number in UK English in your post. \$\endgroup\$
    – tsh
    Sep 9, 2022 at 9:40
  • \$\begingroup\$ @tsh updated to try and clarify \$\endgroup\$ Sep 9, 2022 at 10:15
  • 1
    \$\begingroup\$ 40 is "forty" in all standard English variants. \$\endgroup\$
    – pxeger
    Sep 9, 2022 at 12:14
  • \$\begingroup\$ @pxeger TIL. Corrected in spec. Thanks \$\endgroup\$ 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
    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\$ Sep 20, 2022 at 7:46
  • \$\begingroup\$ @Arnauld aside from that, I'll lower the bounds to 999 \$\endgroup\$ 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\$ 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\$ 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
    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
    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
    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
    Sep 22, 2022 at 4:35
2
\$\begingroup\$

Print every Fool's Mate

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

N-element Rock Paper Scissors

Given an odd integer \$n>2\$, decide the winner for \$n\$-element Rock Paper Scissors.

What is \$n\$-element Rock Paper Scissors?

Rock Paper Scissors is a game in which two players choose between the elements Rock, Paper, and Scissors, and simultaneously reveal their selections. If one player chooses Rock, they will win against a player who chose Scissors, lose against a player who choses Paper, and tie a player who also chose Rock. It is a zero sum game, so a player losing means their opponent has won, and vice versa. Every element beats one element, loses to another, and ties with itself.

A common extension to this game is to add two aditional elements (most famously "Lizard" and "Spock"). In this extension, there are now 5 elements, so each element beats two elements, loses to two elements, but still ties only itself. We can generalize this cleanly to any odd number of elements \$n\$, in which each element will beat \$(n-1)/2\$ elements, lose to \$(n-1)/2\$ elements, and tie with itself.

Challenge specification

Program 1

This program should take an odd integer \$n>2\$ as input in any reasonable format decided by the solver, and output the Program 2 as defined below in terms of \$n\$. Alternatively, this program may instead take the Program 2's inputs along with \$n\$, and provide the Program 2's expected output instead.

This program is the one you will be scored on. This is , so shortest code in bytes wins.

Program 2

This program should take two elements \$A\$ and \$B\$ as input in any reasonable format decided by the solver, and consistently output either one of the following:

  • Whether \$A\$ beats \$B\$, loses to \$B\$, or ties with \$B\$.
  • The winner between \$A\$ and \$B\$, or in the case of a tie, some other distinct output.

Only \$n\$ possible inputs need to be handled by this program. Each possible element must consistently beat \$(n-1)/2\$ elements, lose to \$(n-1)/2\$ elements, and tie with itself. If some element \$a\$ beats an element \$b\$, element \$b\$ loses to element \$a\$. Which elements are allowed and which elements beat which etc. are to be decided by the solver. This must be consistent for each execution of Program 2 for the same \$n\$

Examples:

Your I/O may differ.

Format:
n (input to Program 1)
a b c d e (list of inputs accepted by Program 2, space delimited for all examples)
x y (inputs to Program 2, space delimited for all examples)
value (whether x wins, loses, or ties y)

3
r p s
r p
lose

3
r p s
r r
tie

3
r p s
r s
win

5
0 1 2 3 4
0 1
win

5
0 1 2 3 4
0 2
win

5
0 1 2 3 4
0 3
lose

5
0 1 2 3 4
0 4
lose

5
abcde bcdea cdeab deabc eabcd
bcdea cdeab
lose

5
abcde bcdea cdeab deabc eabcd
bcdea deabc
lose

5
abcde bcdea cdeab deabc eabcd
bcdea eabcd
win

5
abcde bcdea cdeab deabc eabcd
bcdea abcde
win

5
abcde bcdea cdeab deabc eabcd
bcdea bcdea
tie

13
a b c d e f g h i j k l m
g e
lose

13
a b c d e f g h i j k l m
g m
win

13
a b c d e f g h i j k l m
d h
win

13
a b c d e f g h i j k l m
h d
lose

Meta

Everything clear? Any other examples needed? Maybe a worked out example?

\$\endgroup\$
1
  • \$\begingroup\$ info: i am currently working on a worked-out example including a visual aide, and also like in the process of getting a new job, so thats what is taking me so long on this lol \$\endgroup\$ Oct 17, 2022 at 13:16
2
\$\begingroup\$

Repeat Values In Array

\$\endgroup\$
1
  • \$\begingroup\$ this is actually a builtin in jelly (x) \$\endgroup\$
    – naffetS
    Sep 25, 2022 at 1:05
2
\$\begingroup\$

Abbreviate the inputted phrases

Given an ASCII string, replace all occurrences of " is ", " are ", " am ", and " have " with "'s ", "'re ", and "'ve " respectively. This must be done case insensitively.

Examples

Input Output
I am I'm
She is She's
The dog is The dog's
I have a dog I've a dog
I have been hurt I've been hurt
Wadsfajsdfl have asdasd Wadsfajsdfl've asdasd
So, is 6 am fare So,'s 6'm fare
foo amxyz foo amxyz
have I have I
HAVE I HAVE I
I HAVE I've
I AM I'm
I haven't I'ven't
ambc xisz ambc xisz
\$\endgroup\$
7
  • 1
    \$\begingroup\$ What is the expected result for "So, is 6 am fare"? \$\endgroup\$
    – Adám
    Oct 1, 2022 at 23:57
  • \$\begingroup\$ I'll add it as a test case, one moment. \$\endgroup\$
    – Qaziquza
    Oct 2, 2022 at 1:06
  • 1
    \$\begingroup\$ Related (this one is much simpler) \$\endgroup\$
    – naffetS
    Oct 2, 2022 at 1:10
  • 1
    \$\begingroup\$ What's the winning criterion? What character set is expected in the input? What to do if the word to replace is at the beginning of string? How do we handle upper case? Please specify those the rules. Suggested test cases: "foo amxyz", "have I", "I HAVE", "I haven't", "ambc xisz". \$\endgroup\$
    – pajonk
    Oct 2, 2022 at 4:08
  • \$\begingroup\$ Done! <filler text> \$\endgroup\$
    – Qaziquza
    Oct 2, 2022 at 6:59
  • \$\begingroup\$ Personally, I think this challenge would be better if it wasn't a simple replacement challenge, and wouldn't replace things in the middle of words and after punctuation. For example: "So, is 6 am fare" -> "So, is 6'm fare", "foo amxyz" -> "foo amxyz" \$\endgroup\$
    – pigrammer
    Oct 2, 2022 at 18:34
  • \$\begingroup\$ Hmmm, that would make sense. I'll change the rules, then. \$\endgroup\$
    – Qaziquza
    Oct 3, 2022 at 1:55
2
\$\begingroup\$

Make a Court Transcriber

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

Partial Fractions

\$\endgroup\$
5
  • 2
    \$\begingroup\$ I think that most of this challenge would involve the somewhat tedious task of parsing the input rather than actually making the partial fractions. Also, isn't the first testcase you gave using a factorised input ((x+3)^2)? \$\endgroup\$ Oct 8, 2022 at 19:18
  • 1
    \$\begingroup\$ Suggested input format: two list of integers that represent the coefficients of the numerator and the denominator. Suggested output format: A list of pairs of lists of integers. For example: ([1, 4], [1, 6, 9]) -> [([1], [1, 3]), ([1], [1, 6, 9])]. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:27
  • \$\begingroup\$ @DialFrost x^2+3 would be [1,0,3]. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:31
  • \$\begingroup\$ @alephalpha fixed! Tysm, is there anything else that needs fixing? \$\endgroup\$
    – DialFrost
    Oct 11, 2022 at 2:45
  • \$\begingroup\$ @DialFrost Suggested tag: polynomials. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:49
2
\$\begingroup\$

Infinite Integer Derivative

We can consider the derivative of a integer sequence to simply be the difference between each element and the next:

1  5  8  13  2
 4  3  5  -11

Note this will produce a sequence one shorter than the original. We can repeat this process to find the second derivative:

-1 2 -16

And continue this process till there is one element left.

Conjecture A sequence of length n can be exactly represented by first element of each integer derivative. We call this the infinite integer derivative.

Example:

              [8   4  12   6  3]
8              [-4  8   -6  -3]
8 -4             [12 -14  3]
8 -4 12           [-26  11]
8 -4 12 -26          [37]
8 -4 12 -26 37

Example python code:

f = lambda x:x and [x[0]]+f([x[i]-x[i-1] for i in range(1,len(x))])

Note there may be more efficient ways to compute values than this formula.

Test cases

{
    [1,2,3,4,5]:    [1,1,0,0,0],
    [1,2,1,2,1]:    [1,1,-2,4,8],
    [1,2,4,8,16]:   [1,1,1,1,1],
    [5,1,-1,0,6,3]: [5,-4,2,1,1,-17],
    []:             [],
    [12]:           [12],
    [5,5,5,5,5,4]:  [5,0,0,0,-1],
    [5,4]:          [5,-1]
}
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Related but closed. \$\endgroup\$
    – alephalpha
    Oct 10, 2022 at 9:57
  • \$\begingroup\$ While the pyramid shape is the same this is about a different combination of sides and the formula appears to be completely different. \$\endgroup\$
    – mousetail
    Oct 10, 2022 at 10:41
  • 1
    \$\begingroup\$ I believe your example has an arithmetic error, it should be ``` [8, 4, 12, 6, 3] [-4, 8, -6, -3] [12, -14, 3] [-26, 17] [43] ``` \$\endgroup\$ Oct 11, 2022 at 17:50
  • \$\begingroup\$ Perhaps you shouldn't have [] as a valid input, since I don't think it adds anything in particular to the challenge and it might prevent some interesting approaches. \$\endgroup\$ Oct 20, 2022 at 17:01
  • 1
    \$\begingroup\$ Very closely related: binomial transform, which is the same as this but with the sign flipped at odd indices (see wikipedia). \$\endgroup\$
    – Bubbler
    Oct 24, 2022 at 5:45
2
\$\begingroup\$

Prime factor power sorting

Background

We will introduce a new way of writing numbers where the digits represent powers of primes starting with the largest prime factor of the number, and ending with the power of 2 in the prime factorization. As an example, 2 = 21, so it would be written as 1. Slightly more complicated, 3 = 31 * 20, so it is written as 1 0. Here's a few more:

6:     1 1
7: 1 0 0 0
8:       3
9:     2 0
10:  1 0 1

So the place value of the n'th "digit" is the n'th prime number, and the digit itself represents the power of that prime in the factorization of the number. 1 is encoded simply as or 0 (the choice does not affect comparison).

The Challenge

We can compare numbers in this form by first examining how many digits it has, and then breaking ties by comparing the digits themselves like normal. For instance, any power of 2 has only one digit, and so 2n < 3 for all n because 3's prime power representation has two digits. However, when numbers have the same length (meaning their highest prime factors are equal) we compare the lists of digits element-wise. Therefore 12 < 9 because 12th = 1 2 and 9 = 2 0.

Your challenge is to write a function or program which takes as input a collection of distinct integers greater than or equal to 1, and outputs the same collection sorted this way in ascending order. This is code golf, so the score is the length of your solution in bytes.

Examples:

I have written an example solution (Try it online!) which generates the following examples with the input and output separated by a colon:

1 2 3 4 5: 1 2 4 3 5
2 4 8 16 32 64 3: 2 4 8 16 32 64 3
1 3 5 7 9 11 13 15: 1 3 9 5 15 7 11 13
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55: 48 54 40 45 50 42 49 44 55 52 51 46 41 43 47 53
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019: 1000 1008 1001 1014 1012 1015 1007 1003 1005 1010 1017 1016 1002 1004 1011 1006 1018 1009 1013 1019
 
\$\endgroup\$
2
\$\begingroup\$

Triangular honeycomb numbers

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

Box blur the string

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Don't forget to specify the scoring system, I'm assuming code golf, in which case you just need to stick a "This is code-golf, so shortest code in bytes wins." \$\endgroup\$ Oct 19, 2022 at 12:43
  • 1
    \$\begingroup\$ tag suggestions: ascii-art, array or maybe matrix i think \$\endgroup\$ Oct 19, 2022 at 12:43
2
\$\begingroup\$

Conversions Galore!

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

Generate the Sequence of Equivalence Relations (OEIS A231428)

Introduction

An equivalence relation \$R\$ on a set \$S\$ is

  • reflexive: \$ \forall a\in S: aRa\$
  • symmetric: \$ \forall a,b \in S: aRb \leftrightarrow bRa \$
  • transitive: \$ \forall a,b,c \in S: aRb \wedge bRc \rightarrow aRc \$

These relations can be represented as boolean matrices where:

  • reflexive: the diagonal is all ones
  • symmetric: the entries are symmetric over the diagonal (\$a_{ij}=a_{ji}\$)
  • transitive: the matrix, when pairs of rows and the corresponding pairs of columns are suitably swapped, consists of entirely-1 and entirely-zero blocks, with the on-diagonal blocks entirely-1.

Here are a few such matrices:

1 0        1 1 0 0 0        1 0 1 0       can swap rows     1 1 0 0
0 1        1 1 0 0 0        0 1 0 1  -->  2&3, columns  --> 1 1 0 0
           0 0 1 1 1        1 0 1 0       2&3 to obtain:    0 0 1 1
           0 0 1 1 1        0 1 0 1                         0 0 1 1
           0 0 1 1 1

Making use of the reflexive and symmetric properties, we can encode such a matrix by concatenating the rows of its upper-right triangle, and converting from binary to decimal. (The example matrices encode as 0b0=0, 0b10 0000 0111=519, 0b01 0010=18, and 0b10 0001=33.)

Challenge

Write a program or function that outputs all equivalence relations in order (as encoded above). Default sequence rules apply, so you can output an unbounded list, you can take an input \$n\$ and return the \$n^{th}\$ term, or you can take an input \$n\$ and return the first \$n\$ terms. Default Loopholes forbidden. This is , so shortest program wins.

For reference, the first 25 terms of this sequence are

0, 1, 2, 4, 7, 8, 12, 16, 18, 25, 32, 33, 42, 52, 63, 64, 68, 80, 96, 116, 128, 130, 136, 160, 170

Here are example matrices which generate the first few terms of the sequence:

A: 1 0 0     
   0 1 0    0b000 -> 0    
   0 0 1     
          
B: 1 0 0 0
   0 1 0 0    0b00 0000 0001 -> 1    (also: 1 1 among others)
   0 0 1 1                                  1 1 
   0 0 1 1

C: 1 0 0 0 0
   0 1 0 0 0
   0 0 1 0 1    0b00 0000 0010 -> 2
   0 0 0 1 0
   0 0 1 0 1

D: 1 0 0 0 0
   0 1 0 0 0
   0 0 1 1 0    0b00 0000 0100 -> 4
   0 0 1 1 0
   0 0 0 0 1

E: 1 1 1
   1 1 1    0b111 -> 7
   1 1 1

F: 1 0 0 1
   0 1 0 0    0b00 1000 -> 8
   0 0 1 0
   1 0 0 1

G: 1 0 0 0 0
   0 1 0 0 1
   0 0 1 1 0    0b00 0000 1100 -> 12
   0 0 1 1 0
   0 1 0 0 1

Sandbox notes

related: Is This an Equivalence Relation?, Determine if a relation is transitive

My first try, so please don't be shy about suggesting improvements, making edits, heckling... I can take it =)

\$\endgroup\$
3
  • \$\begingroup\$ While I think it's mostly clear, I think it would be helpful if you included the matrices for the first 2 or 3 values in the sequence. Additionally, the default [sequence] rules also allow answers to take \$n\$ as input and output the first \n\$ terms. I'd clarify that isn't allowed, if you intend to override the default. Other than that, looks like a well-written and interesting challenge! \$\endgroup\$ Oct 23, 2022 at 16:45
  • \$\begingroup\$ @cairdcoinheringaahing thanks for the thoughts. On including the first few examples: would you suggest making that code-block one fairly-wide line of examples, or include a few lines of matrices. (I don't know what's easiest to scroll around for people.) On the second point, I didn't intend to override the default--I'll just remove mention of \$n\$ from the challenge section. \$\endgroup\$
    – nitsua60
    Oct 23, 2022 at 19:12
  • 1
    \$\begingroup\$ I think either a code block, or a few lines of mathjax, would both work fine, it's probably just a matter of preference \$\endgroup\$ Oct 23, 2022 at 19:59
1
42 43
44
45 46
150

You must log in to answer this question.

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