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

4545 Answers 4545

1
129 130
131
132 133
152
0
\$\begingroup\$

Escape the maze

Introduction

Here is a random maze:

#####
#M.#E
#.##.
#.##.
#....
#####

Here M is the starting point and E is the endpoint. # is a maze wall and . is a path.

Now we can get out of this maze by following the sequence sssdddwww. (s is dow, d is right, w is up, a is left.)

Your challenge

Given a maze, output the shortest possible route to the endpoint. (E) You may assume the maze is solvable.

Test cases

#####
#M.#E
#.##.
#.##.
#....
#####

outputs

#####
#..#E
#M##.
#.##.
#....
#####

#####
#..#E
#.##.
#M##.
#....
#####

#####
#..#E
#.##.
#.##.
#M...
#####

#####
#..#E
#.##.
#.##.
#.M..
#####

#####
#..#E
#.##.
#.##.
#..M.
#####

#####
#..#E
#.##.
#.##.
#...M
#####

#####
#..#E
#.##.
#.##M
#....
#####

#####
#..#E
#.##M
#.##.
#....
#####

#####
#..#M
#.##.
#.##.
#....
#####

(Notice the newlines between the steps.)

Scoring

This is , so shortest code wins.


Todo

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Meta code golf. add tag maze :p \$\endgroup\$
    – Fmbalbuena
    Nov 18, 2021 at 20:21
  • \$\begingroup\$ @Fmbalbuena Done. \$\endgroup\$
    – Alan Bagel
    Nov 18, 2021 at 20:22
  • \$\begingroup\$ Dupe of Find the shortest path from point A to point B. That challenge has itself been closed as a dupe of Textual maze solver, a decision I don't necessarily agree with, but better to reopen the existing challenge than create a new one. \$\endgroup\$
    – Dingus
    Nov 18, 2021 at 22:31
0
\$\begingroup\$

Solve the halting problem for Minyrinth

Introduction

Minyrinth is the stripped-down version of Labyrinth. It has the same routing semantics as Labyrinth but only four non-wall commands, and only one register (that can hold unbounded signed integers) instead of two stacks. The register is initialized to zero.

Commands

  • " is a no-op path.
  • @ halts the program.
  • ) increments the register.
  • ( decrements the register.

You may assume that the input only contains the four command characters plus spaces (non-path) and newlines (used for 2D layout).

Execution semantics

Copied directly from the README, with some parts edited for Minyrinth:

The source code consists of single-character instructions and is interpreted as a 2D grid. The instruction pointer starts at the first non-whitespace character in the file (in reading order) going right.

Labyrinth is interpreted in a simple loop. At each step, the command under the instruction pointer is executed, then the new movement direction is determined, and then the instruction pointer moves one cell in that direction. The edges of the grid are not connected.

The instruction pointer will generally follow "corridors" of instructions. Junctions can be used for non-trivial control flow. How the new movement direction is determined depends on the number of available steps (i.e. number of direct neighbours with known commands):

  • 4 neighbours: The top of the main stack is examined. If it's 0, keep moving straight ahead. If it's negative, turn left. If it's positive, turn right.

  • 3 neighbours: Do the same as for four neighbours, but if you hit the wall, reverse the direction. Hence, a T-junction hit from the side differentiates between 0 and non-zero. A T-junction hit from the bottom on the other hand sends negative/positive to the left/right whereas a 0 value reverses the direction.

  • 2 neighbours: The first rule here is, don't turn around. So if you came from one of the two directions, continue in the other direction. If this is not the case, but one of the two directions is straight ahead, follow that one (this can happen, for instance, at the start of the program in a corner).

  • 1 neighbour: Go towards the only available direction. Usually, this means you have hit a dead end and turn around on the spot (executing the command you turn around on only once).

  • 0 neighbours: Remain where you are without changing your direction. This can occur at the very start of the program.

Challenge

Solve the halting problem for Minyrinth. Unlike Labyrinth which is Turing-complete, Minyrinth simulates a specific case of a pushdown automaton whose halting problem is decidable.

For output, you can choose to

  • output truthy/falsy using your language's convention (swapping is allowed), or
  • use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.

Standard rules apply. The shortest code in bytes wins.

Some hints can be found in CS Stack Exchange: Decidability of halting problem for DPDAs with \$\epsilon\$-transitions?, Counter Machine (Halting Problem)

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

Plan my factory

"Factory games", such as Factorio, Mindustry, and Satisfactory are my favourite genre of video games, and the way I play them involve a lot of ratio calculations to make sure the factory is running as efficiently as possible.

Given a list of recipe specifications, and a desired production rate of an end product, output the necessary input rates of raw materials, where "raw material" is any ingredient that does not have a provided recipe.

For example:

Recipes:

[
    {
        name: "Iron Plate",
        time: 3.2,
        quantity: 1,
        input: [{
            name: "Iron Ore",
            quantity: 1
        }]
    },
    {
        name: "Copper Plate",
        time: 3.2,
        quantity: 1,
        input: [{
            name: "Copper Ore",
            quantity: 1
        }]
    },
    {
        name: "Iron Gear",
        time: 0.5,
        quantity: 1,
        input: [{
            name: "Iron Plate",
            quantity: 2
        }]
    },
    {
        name: "Automation Science Pack",
        time: 5,
        quantity: 1,
        input: [
            {
                name: "Iron Gear",
                quantity: 1
            },
            {
                name: "Copper Plate",
                quantity: 1
            }
        ]
    },
]

Desired production rate:

{
    name: "Automation Science Pack",
    rate: 60
}

Expected output:

[
    {
        name: "Iron Ore",
        rate: 120
    },
    {
        name: "Copper Ore",
        rate: 60
    }
]

Both input and output may be any standard IO format that represents item names as strings and quantities/rates as integers.

Testcases

TBA

Sandbox

Is this a chameleon challenge?

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

Golf a Friedman's tree sequence for 3 colors

Friedman proved that given a sequence of 3-labelled rooted trees with following conditions, TREE sequence, must be finite and defined maximum length of such sequence as TREE(3).

  • \$i\$th tree, \$T_i\$, should have no more than \$i\$ vertices. (index is 1-based)
  • No tree \$T_i\$ can be homeomorphically embeddable into any of the following tree \$T_j\$ if \$i < j\$.
    • A tree \$A\$ is said to be homeomorphically embeddable to tree \$B\$ if and only if there exists a function \$f\$ from vertices of \$A\$ to vertices of \$B\$ which satisfies following conditions:
      1. \$f\$ preserves label. That is, \$v\$ and \$f(v)\$ has same label.
      2. If \$u\$ is ancestor of \$v\$, then \$f(u)\$ is ancestor of \$f(v)\$.
      3. If \$u_1\$ and \$u_2\$ are children of \$v\$, then the path from \$f(u_1)\$ to \$f(u_2)\$ contains \$f(v)\$.
    • There is a guide with examples in this youtube video.

It is well known that TREE(3) is far larger than \$2^{64}\$.

Challenge

Find a TREE sequence with length of \$2^{64}\$ or longer. Your task is to implement a program or a function or a subroutine that takes one 64-bit integer \$i\$ and outputs a tree \$T_i\$ of your TREE sequence.

Rules

  • Standard loopholes apply.
  • Standard I/O rules apply.
  • Shortest code wins.
  • Output can be any format as long as it describes a 3-labelled tree.
  • Describe how your outputs form valid TREE sequence.

Example of valid sequence, length 16

1 - {}              # 1 vertex tree with label {}. Note that any tree after this cannot contain node with label {}.
2 - [[]]            # 2 vertex tree with label both []. Any tree after this cannot contain two ancestor-child node with both label [].
3 - [(())]
4 - ([][])          # Root with label (), 2 children with label [].
5 - ([]((())))
6 - ([](()))
7 - [()]
8 - []
9 - ((((((((()))))))))
10 - (((((((())))))))
11 - ((((((()))))))
12 - (((((())))))
13 - ((((()))))
14 - (((())))
15 - ((()))
16 - (())

Meta

This is my first challenge. Suggestions?

I'm sure that normal computers will have serious difficulty to execute code for this problem, but also I don't want answers to just brute force TREE sequence and print ith term. How can I balance the question?

\$\endgroup\$
1
  • \$\begingroup\$ You definitely need some examples of the rules. Also, "homeomorphically embeddable" is not a term the average codegolfer is familiar with. \$\endgroup\$
    – Maya
    Nov 16, 2021 at 22:21
0
\$\begingroup\$

OEIS A049190

your task is to print all numbers of this sequence.

is separated by newline, is separated by space or separated by comma.

the first few numbers are:

1, 3, 5, 59, 245, 2491, 235253, 127756731, 330567489269, 258479716298484155, 36823182192123209878050549, 25576412117054296344209353299113896379, 10994511204169842163496446583221775727830456269734123253

How to get numbers of this sequence:

this is look and say but in binary and convert to decimal

Meta

  • How to clarify this?
\$\endgroup\$
0
\$\begingroup\$

Convert codepoint to UTF-1

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

Infinite ordinals from a well-ordering

\$\endgroup\$
3
  • \$\begingroup\$ Are the score categories essentially arbitrary? If so, it's not clear to me whether this is a good idea: it seems like these constraints provide the only motivation for choosing a well-ordering different from the 'default' (1, 2, 3, ...). Poor constraint choices could derail the challenge (i.e. make it too trivial or too hard). On the subject of scoring, looking at the bytes category for example, do you mean that if the default ordering is chosen, the code must be exactly 1 byte? \$\endgroup\$
    – Dingus
    Nov 12, 2021 at 0:48
  • \$\begingroup\$ Also, there's a typo under the second example: 2 < 101 is true. \$\endgroup\$
    – Dingus
    Nov 12, 2021 at 0:48
  • \$\begingroup\$ @Dingus I tried to clarify the scoring part. So if you choose \$\omega\cdot 2\$ you just try to golf an implementation of it. In this case someone has (hypothetically) managed to do it in one byte. As for the difficulty of the ordinals, the first two are one-liners in most languages, \$\omega^\omega\$ can be implemented with a while loop and \$\epsilon_0\$ with a tree. The score categories are not totally arbitrary. \$epsilon_0\$ is an important ordinal, and the smaller ones follow a natural pattern. Another option is to have just one ordinal, making this a normal golf and not a challenge. \$\endgroup\$
    – AnttiP
    Nov 12, 2021 at 7:41
0
\$\begingroup\$

Baloney Sandwich KOTH

Tags: [king-of-the-hill], [python]

Introduction

In this King Of The Hill Challenge, your bots will be playing Baloney Sandwich.

How Baloney Sandwich is played

  1. First, the entire deck is dealt equally to all players (EVERY BOT PLAYS; if there is more than 26 bots, it will be 2 decks mixed together).
  2. Then, the player with the ace of spades goes first.
  3. They play all of their aces
    • However! They could opt to "cheat" and instead play cards that are not aces, or mix and match aces with other cards.
  4. Every other player has their call_bs (bs = Baloney Sandwich) method called after this play, in turn until a player returns True; if a player returns True then the cards played are "revealed".
    • Every player has their bs_call_outcome method to "reveal" the cards
    • If no player returns True but the player was lying, the pb method is called (pb = Peanut Butter)
  5. Play continues with twos, threes, etc.; after kings, start over at aces

Creating A Player

Your player should be in this format:

class ExamplePlayer(AbstractBSPlayer):
    def __init__(self, hand: list[int]):
        super().__init__(hand)
        # Any necessary initialization goes here

    def call_bs(self, player_name: str, card_rank: int, number_of_cards: int) -> bool:
        """
        player_name is the name of the bot who just played
        The number of cards they played is number_of_cards
        The claimed rank is card_rank (1 is Ace; 11-13 are face cards)
        """
        # Magic decision maker
        return False # never calls "Baloney Sandwich"
        # return True would always call "Baloney Sandwich"
    
    def bs_call_outcome(self, player_name: str, caller_name: str, card_rank: int, cards: list[int], cheated: bool):
        """
        player_name is the name of the bot who just played
        caller_name is the name of the bot who called "Baloney Sandwich"
        The claimed rank is card_rank
        The cards they played is cards
        cheated is True if the player cheated
        """
        pass  # Couldn't care less
    
    def pb(self, player_name: str, card_rank: int, number_of_cards: int):
        """
        player_name is the name of the bot who just played
        The number of cards they played is number_of_cards
        The claimed rank is card_rank (1 is Ace; 11-13 are face cards)
        """
        pass # Couldn't care less

    def play_cards(self, card_rank: int) -> list[int]:
        """
        The rank you will claim to play is card_rank
        """
        # Magic decision maker
        return self.hand[0] # Always plays the first thing in hand

A player has access to the following instance variables:

  • self.store: A dictionary that is empty by default. The only instance variable allowed to be written to.
  • self.hand: A list of ints, each representing a card (1 is Ace, 11-13 are face cards)

Testing Your Player

The controller can be found at https://github.com/sethpeace/bs-koth. I apologize in advance that it is janky beyond comprehension.

Rules

Runtime Disqualifications

  • You must play at least one card every turn
  • You can't play cards you dont have in your hand
  • You can't take longer than one second to return from a function

Pre-runtime Disqualifications

  • No reading or writing to controller, runtime, or other submissions (bots can't read them; you can if you feel like it)
  • Only write to self.store instance variable
    • Other variables inside function scope are of course OK
  • Don't design a bot to defend or support specific bots
  • Bots can't use the same strategy as another bot
  • Standard loopholes apply
\$\endgroup\$
4
  • \$\begingroup\$ This seems too similar to codegolf.stackexchange.com/questions/48473/thats-bs-card-game \$\endgroup\$ Nov 27, 2021 at 16:45
  • \$\begingroup\$ @RedwolfPrograms you are correct; thank you \$\endgroup\$
    – Seth
    Nov 27, 2021 at 16:46
  • \$\begingroup\$ It's cool to see some more KotHs being written though! If you have any ideas for ones that you're not sure are dupes, feel free to bring them up in chat to save the effort of having to write out a whole spec first. \$\endgroup\$ Nov 27, 2021 at 16:48
  • \$\begingroup\$ @RedwolfPrograms alright thanks again :) \$\endgroup\$
    – Seth
    Nov 27, 2021 at 16:49
0
\$\begingroup\$

Implement xorshift128+

I don't have time to finish writing this draft at the moment.

Might also consider something like xoroshiro if it's more interesting to implement, but since xorshift128+ is so common it seems like a clearer choice.

(Possible idea: Given initial seed, determine number of iterations it'll take to get a certain random number with xorshift128+. It's not a CSPRNG, so there might be something more interesting than brute force.)

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

Radiate a prime checker into a sum program

Write a program or function that takes a number n and returns/print truthy if it is prime, and falsy otherwise. Additionally, if you remove 1 character of the source code, the program must now take a list of one or more numbers and return/print the sum. This must work for at least one character, and your score is however many characters that this does /not/ work for. Lowest score wins.

meta:

let me know if i need to clarify anything etc also: would it make sense to allow the programs to be the other way around (i.e. a sum checker where removing 1 character makes it a prime checker instead)? Just in case it could lead to a more interesting golf

\$\endgroup\$
2
  • \$\begingroup\$ It says "remove or change 1 character". By change, do you mean simply changing an arbitrary character to another arbitrary character, e.g. abc -> axc? If so, a lot of golfing languages will likely be able to make a trivial 0-score program where they simply change a 1-byte prime checker to a 1-byte sum command. That might not be a bad thing, per se, but it's something to keep in mind. \$\endgroup\$ Dec 8, 2021 at 21:16
  • \$\begingroup\$ @AaroneousMiller True, ill stick to just "remove". Wasn't sure of potential ramifications, thanks \$\endgroup\$ Dec 8, 2021 at 21:18
0
\$\begingroup\$

Quickly pour liquid nitrogen

I have a container of liquid nitrogen, but nothing to measure it with. I do have some containers, whose volumes I know, and I know how much I start with. My goal is to fill any container with a given amount of liquid nitrogen, with the fewest possible pours.

Importantly, liquid nitrogen boils away as I pour it. Every time I pour liquid nitrogen into a container, a milliliter is lost.

Pouring mechanics:

If I have two containers, a and b, and I pour a into b:

  • If both are empty, nothing changes
  • If b's unused volume is greater than or equal to the volume of liquid nitrogen in a, a is emptied into b, and a milliliter boils away from b
  • Otherwise, as much as possible is poured from a into b, and an additional milliliter is taken from a (so b will still be full)

If I have three containers, x, y, and z, they all have volumes of 25, and they contain 25, 10, and 18 milliliters of liquid nitrogen respectively, here are some example pours (one after another, not indiviudual):

  1. x into y: y is filled, and x is left with 9 milliliters
  2. y into z: z is filled, and y is left with 1 milliliter
  3. z into x: x remains full, z is left with 24 milliliters
  4. y into z: z remains at 24 milliliters, y is emptied

(Note that in your input, not all containers will have the same volume)

Task:

Given a list of container sizes, where the first container is initiallyfull and the amount of liquid nitrogen you must measure out, return the minimum number of pours that would be needed to leave that much in any container.

You may assume volumes are non-negative integers, and the initial amount of liquid nitrogen will never be less than the amount you should end with. The actual sequence of pours you use doesn't matter, as long as you output the minimum possible count.

Test cases:

Containers          Target      Output

7, 4                3           5
12, 3, 3            4           2
100, 10, 8          84          6
8, 8                5           3
10, 0               8           2
100, 20, 20, 17     73          7

Other:

I don't think this is a good challenge after doing the test cases

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

Chunk Sort a Sequence

\$\endgroup\$
6
  • \$\begingroup\$ use fastest-code there are few questions with both tags. \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:28
  • \$\begingroup\$ time spent on what interpreter? can you say TIO? \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:30
  • \$\begingroup\$ @Fmbalbuena what if the interpreter is not on TIO? \$\endgroup\$
    – Alan Bagel
    Dec 4, 2021 at 16:31
  • 2
    \$\begingroup\$ You'd need many more test cases to get significant results with fastest-code. Also, using TIO for timing is a bad idea (I'm sure there's a post on meta about that, but I don't know exactly where). \$\endgroup\$
    – Arnauld
    Dec 4, 2021 at 16:33
  • 1
    \$\begingroup\$ @Arnauld here \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2021 at 16:35
  • \$\begingroup\$ @Arnauld added more test cases \$\endgroup\$
    – Alan Bagel
    Dec 4, 2021 at 16:37
0
\$\begingroup\$

Tinla Resqua (Latin Square of rotated words)!

Based on this (currently closed) question on Puzzling, your task is to take a single word generate a valid 'latin square', not by permuting the letters in a word, but by rotating the word.

E.g. if one row was CENTURY then ENTURYC is a valid row, but ENTCTURY is not.

Also unlike some Latin Squares, no diagonal may contain repeated letters either.

1 2 3 4 5 6 7
C E N T U R Y
R Y C E N T U
T U R Y C E N
E N T U R Y C
Y C E N T U R
U R Y C E N T
N T U R Y C E

Is a valid grid.

\$\endgroup\$
5
  • \$\begingroup\$ For even-length words, I think it is impossible to create such square by only rotating the word. At least it is surely true for length 2 and 4. \$\endgroup\$
    – Bubbler
    Dec 14, 2021 at 23:38
  • \$\begingroup\$ @bubbler then they could error or return null or similar? \$\endgroup\$ Dec 15, 2021 at 0:02
  • \$\begingroup\$ That could work. (I'd make it more lenient and say "output something that can be distinguished from a valid solution".) Determining absence of solution is actually harder than that, because it's also impossible for 3. It seems to depend on the existence of solution to "toroidal n-queens problem". \$\endgroup\$
    – Bubbler
    Dec 15, 2021 at 0:19
  • \$\begingroup\$ I found the solution here, which states that such a square is possible exactly when the smallest prime factor is 5, which is equivalent to n%6 being 1 or 5. \$\endgroup\$
    – Bubbler
    Dec 15, 2021 at 0:44
  • \$\begingroup\$ @bubbler very interesting \$\endgroup\$ Dec 15, 2021 at 2:16
0
\$\begingroup\$

This was heavily inspired by the donut.c program


Challenge:

You have to come up with a program that prints (in console) a shape that looks exactly like the shape of your code.

For example, if your code's shape looks like this:

    2343
3kf5
     3o*/f
   3%kt^7

then the output's shape should look like this:

    9I8b
&yt^
     )ph67
   {}fgh]

(the byte don't need to match, just the shape)

Rules

  • Empty programs/whitespace-only programs are not allowed.

  • Your program should have more than 2 lines/statements of code.

  • Each line should not be identical to every other line.

  • All whitespace characters (space, tab,...) don't have to be identical.

  • Whitespaces characters don't count towards the minimum bytes count.

  • Your program's source code and the output should not be identical. It should be at least has one different character.

  • The output should have at least two different bytes on one line.

  • You should not use comments.

Scoring criteria

  • Longest code (in bytes) wins!

  • If two same programs have the same byte count, the one with the most unique characters in the output wins!

  • If two same programs have the same unique characters, the one with the most different characters in output compared to source code wins!


Meta

  • Does this question have any duplicates?

  • My wording is bad, can you improve it?

  • Is this question interesting? Fit within the rules of the site?

\$\endgroup\$
9
  • \$\begingroup\$ How will you tie-break solutions that change all characters from source to output, while having no duplicated characters in the output? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:06
  • \$\begingroup\$ Are programs without any whitespace allowed? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:12
  • \$\begingroup\$ Please avoid requiring minimum scores. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:15
  • \$\begingroup\$ Please avoid cumbersome I/O formats like requiring printing in a console, which also makes assumptions about language features and arbitrarily overrides the defaults. Instead, refer to the default for code golf output methods. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:19
  • \$\begingroup\$ I suggest changing "input" to "source code". \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:23
  • \$\begingroup\$ Can you confirm that this is an optimal answer (minimum allowed byte count changing all its characters while having no duplicates in the output) and that if I post this answer, I win? Note also that the source has no duplicated characters either, so that it won't help to add a rule for tie-breaking on unique characters in the source. Furthermore, code and output have no characters in common at all, preventing that as a tie-break too. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 10:25
  • \$\begingroup\$ I think "longest code wins" is problematic. People can probably make it as long as they want. \$\endgroup\$
    – Ivo
    Dec 15, 2021 at 11:54
  • \$\begingroup\$ Oh, I completely missed the change to code-bowling. Have a look at the tag wiki for tips and warnings. Also, note that the maximum number of unique characters will be 1114112. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 11:59
  • \$\begingroup\$ Closely related, potentially a duplicate \$\endgroup\$ Dec 15, 2021 at 12:41
0
\$\begingroup\$

Get all binary between a binary number and its reverse

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

Challenge

You should write a program that has one in (your code in bytes) chance to output a 4 (could be a function that returns a 4). So if your code has 10 bytes, your code should have 1 in an 10 chance to print out a 4. Otherwise, output "finding my dice".

Rules

  • You can use whitespaces, comments or any unnecessary code to get to the number of bytes that you want.
  • You shouldn't use any loopholes.

Winning criteria

This is , so shortest code in bytes wín!

\$\endgroup\$
6
  • \$\begingroup\$ What should the solution do in the n−1 out of n cases? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 13:42
  • \$\begingroup\$ @Adám Do you mean when it doesn't print 4? Just trying to clarify. \$\endgroup\$
    – Ginger
    Dec 15, 2021 at 13:58
  • \$\begingroup\$ Say my code is 10 bytes long and I run it 50 times. On average, 5 of those runs should print a 4. What should the remaining 45 runs do? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 13:59
  • \$\begingroup\$ You phrasing sounds a lot like a program that prints is required. Please clarify if a function (e.g. taking a dummy argument) that returns 4 is allowed. \$\endgroup\$
    – Adám
    Dec 15, 2021 at 14:00
  • \$\begingroup\$ Are we allowed to embed unnecessary strings to reach a desired byte count? \$\endgroup\$
    – Adám
    Dec 15, 2021 at 14:01
  • \$\begingroup\$ @Adám Wouldn't that just make your score worse though? \$\endgroup\$ Dec 15, 2021 at 16:58
0
\$\begingroup\$

Find duplicates, quickly

In this challenge, you'll be given a list of positive integers or non-empty alphabetical strings (your choice), and must return a list containing all duplicates. You must do this with the minimum time complexity you can, and as few bytes as possible.

Task:

Given a list of either positive integers or non-empty alphabetical (lower or uppercase, your choice) strings, return a list containing all duplicates. You may contain a duplicate value any number of times, so for the input [a, b, b, c, d, d, d, d], any of [b, d], [b, d, d, d], [b, b, d, d, d, d], or even [b, b, b, b, d] would be fine.

Scoring:

Scoring is by both average time complexity and bytes. A better time complexity will always beat an answer with a lower one, and byte count is a tie breaker. E.g., if there are two \$O(n^2)\$ answers, at 10 and 20 bytes, and an \$O(n\log{n})\$ answer at 140 bytes, it would rank higher than either of the others (until either a shorter \$n\log{n}\$ answer or an answer faster than \$n\log{n}\$ showed up).

As in , this is per-language, so Vyxal and Vim, Charcoal and C, or Japt and Java are not competing.

\$\endgroup\$
1
  • \$\begingroup\$ But what if I don't know the time complexity of some operations in my compiler / interpreter? Some languages only define the correct output for certain operator without specify the time complexity. This could happen when some language provide a Map<> without specify if the Map<> is TreeMap<> or HashMap<>. \$\endgroup\$
    – tsh
    Dec 24, 2021 at 5:37
0
\$\begingroup\$

Check if the string is reshaped.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ I don't understand this. Can you try to reword it? \$\endgroup\$
    – pxeger
    Dec 16, 2021 at 19:58
  • \$\begingroup\$ @pxeger read examples carefully \$\endgroup\$
    – Fmbalbuena
    Dec 16, 2021 at 20:00
  • \$\begingroup\$ @Fmbalbuena I did, but it's really not clear what you mean by "reshape" \$\endgroup\$ Dec 16, 2021 at 20:01
  • \$\begingroup\$ @RedwolfPrograms in APL. \$\endgroup\$
    – Fmbalbuena
    Dec 16, 2021 at 20:04
  • 6
    \$\begingroup\$ @Fmbalbuena I don't know APL, and you can't expect people solving the challenge to either. You need to explain what you mean by "reshape", in a way that people will be able to understand without a background in any particular language. \$\endgroup\$ Dec 16, 2021 at 20:09
  • \$\begingroup\$ @RedwolfPrograms ask to Adám. \$\endgroup\$
    – Fmbalbuena
    Dec 16, 2021 at 20:15
0
\$\begingroup\$

Dumbo octopus flashing time

Day 11 of this year's AoC was about a grid of bioluminescent dumbo octopi. I'll try to explain how this works, click on the link for a better explanation.

You have a 10x10 grid of octopi which slowly gain energy and flash when fully charged. Each octopus has an energy level from 0 to 9:

5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

The flashes and energy amounts can be modelled with steps. At each step:

  • All octopi have their energy level increase by 1
  • Then, any octopus with an energy level greater than 9 flash. When an octopus flashes, it increments the energy levels of all octopi adjacent (orthogonally or diagonally) to it.
  • The flashing repeats until no more octopi can flash. Then, all octopi that flashed during this step have their energy level reset to 0.

For example (stolen from AoC):


Before any steps:
11111
19991
19191
19991
11111

After step 1:
34543
40004
50005
40004
34543

After step 2:
45654
51115
61116
51115
45654

In step 1, the octopi with energy level 9 are all incremented to 10 and flash, all incrementing the octopus with energy level 1 (initially incremented to 2) in the center and causing it to flash as well.

The second part of the puzzle asks how long a configuration will take to have all octopi simultaneously flash in the same step. However, not all configurations will do this - some will fall into other cycles. Eventually, all of the configurations will repeat themselves, as there's only \$10^{10 \cdot 10 } = 10^{100}\$ possible configurations - still a huge amount, but finite.

Your challenge is to find a configuration that takes as many steps as possible to return to a configuration it's reached before, with more steps being better.

People on reddit have been investigating this, and the number to beat is 372886.

Meta

Is the explanation good, and should I bother with it?

Better examples?

\$\endgroup\$
4
  • \$\begingroup\$ Why is it not \$10^{100}\$ configurations? Also, it's not initially clear that an octopus increments for each adjacent flash. \$\endgroup\$
    – att
    Dec 20, 2021 at 8:40
  • \$\begingroup\$ @att Oops, made a mistake with #1 and I'll try clear up #2 \$\endgroup\$
    – emanresu A
    Dec 20, 2021 at 8:42
  • \$\begingroup\$ @att Better now? \$\endgroup\$
    – emanresu A
    Dec 20, 2021 at 8:45
  • \$\begingroup\$ Yeah, I think so \$\endgroup\$
    – att
    Dec 20, 2021 at 8:51
0
\$\begingroup\$

Kolmogorov-simple numbers

\$\endgroup\$
3
  • \$\begingroup\$ Why not more flexible IO? Requiring a print seems pointless to me. \$\endgroup\$
    – pxeger
    Dec 15, 2021 at 8:50
  • 1
    \$\begingroup\$ Seems like this would be better if the challenge was stated as "output the smallest number \$l\$ in \$n\$ bytes, such that \$l < \log_{256}(n + 1)\$". I agree with pxeger, it's a lot more simple to just use our standard I/O rules, and not worry about it \$\endgroup\$ Dec 15, 2021 at 12:58
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Dec 22, 2021 at 1:04
0
\$\begingroup\$

Return all letter counts as an integer

\$\endgroup\$
1
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Dec 22, 2021 at 1:06
0
\$\begingroup\$

Repeat average

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

Event scheduler

\$\endgroup\$
6
  • \$\begingroup\$ Thanks for using the sandbox. The challenge type is called fastest-code here. It looks well-defined in general, but a few minor issues: 1) You don't really need restrictions in time complexity (the requirement 1) when submissions are competing for it. 2) Looks like the build instruction is linux only. If so, it should be clarified as such (along with dependencies like cmake). \$\endgroup\$
    – Bubbler
    Dec 7, 2021 at 2:12
  • \$\begingroup\$ FYI, language-specific challenges are discouraged here, and fastest-code without language restriction is usually done by measuring time on a single machine (often the challenge author's). (Not sure how to adapt this specific challenge to other languages, so I'd say it's fine in this case.) And unfortunately we're not like other competitive programming sites, and therefore have very few C++ users. \$\endgroup\$
    – Bubbler
    Dec 7, 2021 at 2:15
  • \$\begingroup\$ OK so would it be acceptable to submit a sample C++ code as guidance and open up to other languages? \$\endgroup\$
    – user108147
    Dec 7, 2021 at 5:12
  • \$\begingroup\$ @Bubbler Changed the terms of the challenge. Does it look better as it stands? \$\endgroup\$
    – user108147
    Dec 7, 2021 at 5:28
  • \$\begingroup\$ I mean, because of the nature of the task, it's near impossible to establish fair comparison across languages. Normally you'd feed input in a standardized format through STDIN and let the programs output through STDOUT, but 1e8 events would make I/O time way too significant. And not all languages have mt19937 implementation or seeding it like C++ does. So I was saying that limiting to C++ is fine here, though it won't get many answers on this site. \$\endgroup\$
    – Bubbler
    Dec 7, 2021 at 5:36
  • \$\begingroup\$ Hmm we could then open by classes like in boxing but per language here. Winner for C++, Java, Python, etc. And the IO is really not much - just generate a random sequence in memory and submit. \$\endgroup\$
    – user108147
    Dec 7, 2021 at 5:38
0
\$\begingroup\$

Identify basic building blocks for new natural and programming language

(Based on Invent new programming language and write Hello world in it, but re-phrased to gain more focus on answers).

There exists variety of different programming languages, also variety of natural languages.

If we could create new programming language, which in a turn would possess structure of natural language - what basic structures you would choose ?

one example of artificially constructed language is Toki Pona:

It can be used as natural language, but not as a programming language.

One example of programming language is for loop - for example in C#:

for(int i = 0; i < 10; i++) { ... }

If you want to express this kind of sentence in natural language - then you can use 'equals' for '=', 'less than' for '<' - but scope begins ('{') and scope ends ('}') is relatively long and difficult to express / pronounce.

What basic language structures you would propose for new language ?

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

Identify a "reverse checkers" position

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

High throughput prime numbers

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

Find out what type of adjective it is

There are 3 types of adjectives: absolute, comparative, and superlative adjectives. Your program should print what type of adjective it is. The program is supposed to work on finite lost of words.

Notes

  • Input will be a string, (not always 1 word), it'll be an adjective (the number of words will be finite)
  • Output must be anything that represents absolute, comparative and superlative.
  • The 15 adjectives below should be used as test cases and your program should be at least 90% accurate.

This is , so the shortest code wins!

Test cases:

pushiest => superlative
homeliest => superlative
most miserly => superlative
outgoing => absolute
most feline => superlative
roasted => absolute
frightening => absolute
fairer => comparative
more uncomfortable => comparative
more classic => comparative
smarter => comparative
muffled => absolute
scratchier => comparative
meager => absolute
tartest => superlative
\$\endgroup\$
6
  • \$\begingroup\$ So it only needs to correctly identify 14 of the below 15? \$\endgroup\$
    – rak1507
    Jun 30, 2021 at 14:00
  • \$\begingroup\$ @rak1507 at least. I'll add more test cases if necessary \$\endgroup\$
    – math scat
    Jun 30, 2021 at 14:02
  • \$\begingroup\$ @rak1507 but checking everyone of these won't work, as it's code golf \$\endgroup\$
    – math scat
    Jun 30, 2021 at 14:04
  • 4
    \$\begingroup\$ It should be made very clear whether the program is supposed to work on a finite list of words (as currently suggested) or on any input in theory. The approaches are going to be very different. \$\endgroup\$
    – Arnauld
    Jun 30, 2021 at 22:34
  • \$\begingroup\$ "tartest" is a superlative. \$\endgroup\$
    – DjinTonic
    Jul 17, 2021 at 2:04
  • \$\begingroup\$ @DjinTonic okay done \$\endgroup\$
    – math scat
    Jul 25, 2021 at 7:58
0
\$\begingroup\$

Is it a mathy-county-number

So I recently reinvented some boring type of number. Reinvented because I'm sure somebody else invented it before, but 'till figure out who invented it, let's call these numbers mathy-county-numbers.

So what is a mathy-county-number?

A mathy-county-number number is a number whose count of each digit also appears in the number.
It's a number like 332222410.
The number 3 occurs 2 times, so there must be a 2. The number 2 occurs 4 times, so there must be a 4. 4 occurs once, and some other numbers occur 0 times.

The task is simple: Write a program to check if a number (received by the input) is a mathy-county-number.

Rules

  • Default loopholes apply
  • Default I/O rules apply
  • Output must be a truthy or falsy value
  • No digit will appear more than 9 times

Examples

332222410
> True

33222241
> False

1
> False

33222
> False

1122233334444455555566666667777777788888888890
> True

112223333444445555556666666777777778888888889
> True

122334444456789
> False
\$\endgroup\$
14
  • \$\begingroup\$ "The number 3 occurs 2 times, so there must be a 2." Does this means "3312" is valid as there is a 2 (although not followed by 3). \$\endgroup\$
    – tsh
    Jul 26, 2021 at 9:48
  • \$\begingroup\$ Why "1" is falsy? \$\endgroup\$
    – tsh
    Jul 26, 2021 at 9:49
  • \$\begingroup\$ @tsh 1: no, because in 3312 there's no 0. but eg. 03312 would be valid \$\endgroup\$
    – math scat
    Jul 26, 2021 at 10:44
  • \$\begingroup\$ @tsh 2: 0 is not there, 9, 8, 7, ... occur 0 times \$\endgroup\$
    – math scat
    Jul 26, 2021 at 10:54
  • \$\begingroup\$ "If any digit occurs more than 9 times, count it as a 9." is needlessly complicated, I'd suggest just saying that no digit will appear more than 9 times. The output for the last 2 test cases in unclear - what is sdcvbhnjmk supposed to represent? Just use something like true/false. Additionally, why is 33222 true? By the same logic as the example, it contains "some other numbers zero times", so should include a 0 to be true, right? \$\endgroup\$ Aug 6, 2021 at 14:02
  • \$\begingroup\$ @cairdcoinheringaahing thanks, don't know why I'm addressing the changes now \$\endgroup\$
    – math scat
    Jan 7, 2022 at 13:06
  • \$\begingroup\$ If 0 does not occur in a number, does that mean that some number appears 0 times? \$\endgroup\$ Jan 7, 2022 at 14:03
  • \$\begingroup\$ 0 has to occur in a mathy-county-number if some number appears 0 times. Example 112 would be invalid because eg. 3 appears 0 times. 1120 would be valid though. \$\endgroup\$
    – math scat
    Jan 7, 2022 at 14:20
  • \$\begingroup\$ @thejonymyster ^ \$\endgroup\$
    – math scat
    Jan 7, 2022 at 14:30
  • \$\begingroup\$ in the number 123456789, 0 appears 0 times. However, there is no 0 in the number to account for the fact that there is 0 of that number. Should this output truthy or falsy? (Note: this is a paradox) \$\endgroup\$ Jan 7, 2022 at 14:33
  • \$\begingroup\$ Also, you should clearly define what makes a number mathy-county, rather than having the user rely on an example. (Not that it isn't easy to figure out, but it's good practice and leads to no assumptions being made, especially ones you weren't prepared for) \$\endgroup\$ Jan 7, 2022 at 14:34
  • \$\begingroup\$ @thejonymyster I'd say the number itself should be falsy because there is no 0. However even if you add a 0 it'll stay falsy. \$\endgroup\$
    – math scat
    Jan 7, 2022 at 14:40
  • \$\begingroup\$ Thanks, I'll add that in \$\endgroup\$
    – math scat
    Jan 7, 2022 at 14:41
  • \$\begingroup\$ @mathcat so any number without a 0 in it should return falsy. Also, numbers with leading 0s being counted differently is strange. How is 01 different from 1, numerically? \$\endgroup\$ Jan 7, 2022 at 15:09
0
\$\begingroup\$

Wordle

The game Wordle is quickly becoming popular.

The way the game works is as follows:

  1. Players are trying to guess a 5 letter word
  2. Players have six attempts to guess the word
  3. After each attempt, the player is told:
    a. which letters are in the right place (index)
    b. which letters are in the word, but in the wrong place
    c. which letters are not in the word at all

The aim of this challenge is to create a Wordle application, as follows:

  1. On startup, the application reads from a dictionary of 5-letter words and selects one at random
  2. The application then prompts for user input
  3. On input:
    a. The application checks the input to ensure it is also a 5-letter word and in the dictionary. If it is not, the application returns any failure message and exits
    b. If the input matches the chosen word, the application returns any success message and exits
    c. Otherwise, the application checks the letters of the input against the letters of the word, and returns to the user an indicator for each letter of whether it is correct, misplaced, or incorrect. If a letter is repeated in the input, only the first occurrence is marked as correct/misplaced; the remaining occurrences are marked as incorrect [sandbox qn: what happens if the actual word has repeated letters?]
  4. Steps 2 and 3 are repeated until the application aborts in step 3a or 3b; or the user has failed to guess the word a total of 6 times; at which point the application exits

Sandbox

I am thinking of this as a code-golf challenge, but I wonder if there's another approach where people create the bot that's trying to solve the challenge, as well as the bot that's providing the challenge? Or something else? I'm not familiar with the other types of challenges to suggest something.

\$\endgroup\$
6
  • \$\begingroup\$ The hints wordle gives back are a little more complicated when a letter appears multiple times in the guess. I still think there's a lot left to clear up here otherwise but that sort of edge case behavior is one thing that should be made clear. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 11, 2022 at 15:04
  • \$\begingroup\$ @WheatWizard Thanks, yes, that's why I put it in the sandbox! \$\endgroup\$ Jan 11, 2022 at 15:04
  • \$\begingroup\$ Somone has played around and found out the repeated letter rules over on Reddit. \$\endgroup\$ Jan 11, 2022 at 23:29
  • \$\begingroup\$ IMHO in its current form it contains too many tasks in one challenge. Maybe limit the challenge just to step 3 or even just step 3c? \$\endgroup\$
    – pajonk
    Jan 12, 2022 at 11:10
  • \$\begingroup\$ @JonathanAllan thanks, that's helpful. \$\endgroup\$ Jan 13, 2022 at 15:24
  • \$\begingroup\$ @pajonk I agree it's probably too complicated as-is for a [code-golf] challenge. I don't want to reduce it to just a simple "which letters are in the correct place" challenge though - I feel that's not interesting enough. What about a different scoring system - perhaps a variant of [king-of-the-hill], where you're either trying to create a bot that can solve Wordle quickly; or a bot that picks words to avoid being solved easily - and they're pitted against each other. Would that be more interesting? \$\endgroup\$ Jan 13, 2022 at 15:27
0
\$\begingroup\$

Universal Command Sequence

Posted

\$\endgroup\$
4
  • \$\begingroup\$ Very related: Shortest universal maze exit string \$\endgroup\$
    – xnor
    Jan 6, 2022 at 8:59
  • \$\begingroup\$ I feel like answers to this will be very hard to test. Probably the golfiest way to do this, if it's valid, would be not to code anything with mazes, but just to produce some massive random-looking sequence of directions. If the length is a fast-enough growing function of n, with overwhelmingly high probability works on every maze for every n. Like, "output 3^3^3^n in base 4". \$\endgroup\$
    – xnor
    Jan 6, 2022 at 9:06
  • \$\begingroup\$ @xnor This question is actually from a Russian math olympics problem :D that problem is to prove the existence of the sequence. The proof states that the sequence can be generated by following a certain rule (a certain rule of concatenating sequences, to be exact). And I think I do have written a testing code for it; see section "Test Code" (sorry but English isn't my mother tongue, but now I know it is called a "validator", isn't it?) \$\endgroup\$
    – atzlt
    Jan 6, 2022 at 15:42
  • \$\begingroup\$ Ah yes I rembered, it's 1998 All-Russian Math Olympiad, Grade level 9, Day 1, Problem 4. Original problem is 8x8 grid, but the proof can be generalized to nxn. \$\endgroup\$
    – atzlt
    Jan 6, 2022 at 16:02
1
129 130
131
132 133
152

You must log in to answer this question.

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