578
\$\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\$
3
  • 1
    \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$ Commented May 15, 2024 at 14:05
  • 2
    \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29, 2024 at 13:27
  • \$\begingroup\$ I have been once submitted a question to sandbox and downvoted to -1, but after submitting it anyway it has 8-9 score right now. \$\endgroup\$ Commented Dec 5, 2025 at 18:13

5006 Answers 5006

1
50 51
52
53 54
167
2
\$\begingroup\$

Index into a Fibonacci tiling

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

Draw U+30EDE

Biangbiang noodles are a type of Chinese noodle originating from Shaanxi cuisine. The noodles, touted as one of the "eight curiosities" of Shaanxi (陕西八大怪), are described as being like a belt, owing to their thickness and length.
Biangbiang noodles are renowned for being written using a unique character. The character is unusually complex, with the standard variant of its traditional form containing 58 strokes.

From Wikipedia, CC BY-SA 4.0

Task: Draw the character 𰻝(U+30EDE) in traditional chinese, in a graphical environment.

Your font probably doesn't have this character. This is what it looks like: Very complex chinese character

Similarly to flag-drawing challenges, simply displaying the character and letting the font renderer do the work is not allowed. This includes rendering other chinese characters, however characters in ASCII are allowed.

Drawing color is anything reasonably visible (ie not white on white).

It is allowed to simplify the strokes (they do not have to look like paint strokes), but each of the 58 strokes should be individually recongnizable,

This is , fewest bytes wins!

sandbox notes:

i'm aware this is critically underspecified. see comments. i don't have time to write up nice rules right now, so i'll hopefully fix this at some point before posting.

\$\endgroup\$
13
  • 1
    \$\begingroup\$ I like the idea behind this challenge. Can you please highlight each of the strokes so that it will be easier to understand how to draw this? On top of that, the requirements are a bit subjective here. Is this simplification allowed? If so, can it be simplified even more, and if not, what are the specific requirements we will need to follow? \$\endgroup\$ Commented Feb 6, 2025 at 10:41
  • 2
    \$\begingroup\$ @WeirdGlyphs thansk for the feedback, i'll try to make this more objective (when i get home). your specific simplification would not be allowed because it's missing at least one stroke, but overall the intent is to allow this type of simplifications, yes. would this gif from wikipedia: en.wikipedia.org/wiki/File:Bi%C3%A1ng-order(complete).gif help? \$\endgroup\$ Commented Feb 6, 2025 at 10:44
  • 3
    \$\begingroup\$ Yes, this gif is a great way to show how the character can be drawn. In order to be more objective, you should probably provide your own simplification so that the rules are more clearly defined. Btw, I knew that for some of the strokes, I draw them as one line when they normally bend a little more, but this was a good way to check the limits of the "Good as long as the strokes are visible" rule. \$\endgroup\$ Commented Feb 6, 2025 at 10:49
  • 1
    \$\begingroup\$ For clarity, I assume the missing strokes you're referring to in the proposed simplification are the 1st and 7th stroke in each 長, which the simplification fuses with the 6th? Also now making me wonder if anything in particular has to be done to make sure it's visible that, for example, the 口 is 3 strokes (and not 2 or 4) and the 馬 is 10 strokes as opposed to 8. And is it permitted to freely choose either the flat-topped 言 you have in the embedded example graphic or the standard slant-topped 言 in the stroke order GIF? \$\endgroup\$ Commented Feb 6, 2025 at 19:27
  • 1
    \$\begingroup\$ (also, suggest graphical-output tag--but perhaps it could also be opened up to ad-hoc encodings of the strokes themselves in coordinate space?) \$\endgroup\$ Commented Feb 6, 2025 at 19:31
  • 1
    \$\begingroup\$ In this extremely crude drawing... 1. which of the elements in blue are mandatory? 2. is it problematic that the strokes are so disconnected from each other? 3. how close is this to having the strokes too far out of place w.r.t. each other to be valid? 4. is it problematic that each 幺 and each 長 is different? \$\endgroup\$ Commented Feb 6, 2025 at 19:48
  • 1
    \$\begingroup\$ @UnrelatedString i was tripping and didn't see a clearly marked stroke. 1: i'm thinking either all or none. haven't decided yet. 2: i want to say yes, i think i'll add a rule that all strokes that touch in the original must also touch in submissions 3: unfortunately this might sink the challenge, as there are no objective criteria for this. 4: no, iff all other rules are followed. i'm adding the graph-io tag. \$\endgroup\$ Commented Feb 6, 2025 at 20:59
  • 2
    \$\begingroup\$ @UnrelatedString for the flat top, i'm going to allow it because it's a thing people already do when writing this. the actual number of strokes done won't be counted, just the graphical aspect of them (so 口 can be 2 strokes) because what a "stroke" is is not consistent across languages. \$\endgroup\$ Commented Feb 6, 2025 at 21:01
  • 1
    \$\begingroup\$ Suggest generating anything with same topology even if it doesn't look similar \$\endgroup\$ Commented Feb 12, 2025 at 0:46
  • \$\begingroup\$ Is this challenge still going to happen? It was a pretty good idea, would be a waste if it was canned. \$\endgroup\$ Commented Mar 29, 2025 at 21:58
  • 1
    \$\begingroup\$ @WeirdGlyphs it's still on my list. Life is getting in the way a lot lately, so i haven't had the time to specify it better. if you wish to do so and/or post it to main, you have my blessing, but if you don't i intend to post it eventually, just not right now. \$\endgroup\$ Commented Mar 29, 2025 at 22:35
  • \$\begingroup\$ @WeirdGlyphs I have tried and tried and i cannot find a way to specify this challenge in a way that objectively judges whether or not the output is correct. personally i'd like to avoid l4m2's idea of "topologically identical", though i fear this is the only way to actually do this properly. I'm abandoning this challenge, but if you find a way to make it work, feel free to post it. \$\endgroup\$ Commented Jun 23, 2025 at 11:18
  • \$\begingroup\$ The only problem with this challenge is that it is a bit time-consuming to formalize it. The best way would be to record where the stroke edges are located (probably using relative coordinates between (0,0) and (1,1)), but it takes a lot of time to record them, and then verify that vertical lines are truly vertical, etc. Maybe I can do it if I have the time, currently it is a bit limited and I am proposing a challenge rn so it would need to wait after that, but it's not impossible. \$\endgroup\$ Commented Jun 23, 2025 at 11:31
2
\$\begingroup\$

Snakes on a 2xN grid

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

Basic Uiua Planet Notation

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

Permute Kanbun

I'm still working out how Kanbun works exactly. There doesn't seem to be an accessible comprehesive explanation in English available online. So I have to piece things together. I'll post the challenge once it's complete.

Background

Kanbun was a system for writing literary Chinese used in Japan, that eventually lead to the invention of Japanese writing.

Interesting to us is that, since the word order of Japanese and Chinese differ, Japanese scribes would add special marks to Kanbun called kaeriten to indicate how to change the text to Japanese word order. There were other marking systems used for making Kanbun easier to read for Japanese speakers, but we are focusing on the kaeriten in this challenge.

Reversing

The reverse mark (reten) links adjacent words indicating their order should be reversed. If there are multiple consecutive reverse marks it indicates that the entire linked string should be reversed. For example:

敢レ諫レ君

becomes:

君諫敢

Linking

The link mark (tatesen) links adjacent characters indicating that they should be treated as a single character.

For example:

愛二丨讀古人え書一

becomes:

古人え書愛讀

Test cases

楚人有下鬻二��與一レ矛者上 => 楚人盾矛與鬻者有
敢レ諫レ君 => 君諫敢
愛二丨讀古人え書一 => 古人え書愛讀

\$\endgroup\$
7
  • \$\begingroup\$ The behavior of the reverse mark seems clear, but the link mark's behavior is very confusing to me, so that should probably be a point to clarify as you finish the challenge \$\endgroup\$ Commented Feb 25, 2025 at 0:27
  • \$\begingroup\$ @noodleperson Probably the confusion is that I haven't explained and yet which cause the movement in that example. I don't have a real-life example which just uses links and reverse marks. \$\endgroup\$ Commented Feb 25, 2025 at 1:40
  • \$\begingroup\$ How is 一 and 二 functional? \$\endgroup\$ Commented Mar 7, 2025 at 7:57
  • \$\begingroup\$ You meant 愛二丨讀古人之書一; notice and \$\endgroup\$ Commented Mar 20, 2025 at 3:29
  • \$\begingroup\$ Would you just assume 一 二 レdon't exist in text? \$\endgroup\$ Commented Apr 19, 2025 at 5:42
  • \$\begingroup\$ @l4m2 Yes, the special characters will just be omitted. In actual writing the special characters are written differently to be distinguishable. \$\endgroup\$ Commented Apr 19, 2025 at 12:45
  • \$\begingroup\$ Why are you using full-sized CJK characters instead of dedicated annotation characters for kanbun? ㆐㆑㆒㆓㆔㆕ The annotation characters are semantically different from the full-sized ideographs. On presentation, the annotation characters have smaller sizes so they don't get confused with the Chinese text they annotated on. \$\endgroup\$ Commented Apr 22, 2025 at 0:09
2
\$\begingroup\$

[DRAFT] A line in calendar.txt format

Tags:

Write the shortest full program, function, or code snippet that, when given a list of events happening today, outputs the events in calendar.txt format.

the calendar.txt Format

format from calendar.txt

The calendar.txt format contains the following sections:

  1. The date, in ISO-8601. (YYYY-MM-DD)
  2. A space.
  3. The ISO-8601 week number, in 2 digits, 1-indexed, preceded by w. (wNN)
  4. A space.
  5. The weekday, in English, abbreviated to 3 characters. The week starts on Monday. (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
  6. Two spaces.
  7. A space-separated list of events, ordered by earliest start time:
    • The starting and ending hours, separated by a minus -.
    • The event name.

Input

Input is a list of triplets of (startHour uint, endHour uint, eventName string). This list may be empty.

Output

Output is the representation of the given events, happening today, in the format described above.

Example cases

// triplets => "output"
// assuming that the current date is 2021-02-15.
(9,12,"project groups."),(17,18,"jogging.") => "2021-02-15 w07 Mon  9-12 project groups. 17-18 jogging."
\$\endgroup\$
2
\$\begingroup\$

Fix that slightly incorrect sum!

\$\endgroup\$
3
  • \$\begingroup\$ Nice idea. I think it would be better if submissions could do I/O as three integers, rather than strings in this format. \$\endgroup\$ Commented Mar 21, 2025 at 16:18
  • \$\begingroup\$ Yeah, that's fair. \$\endgroup\$ Commented Mar 22, 2025 at 0:46
  • \$\begingroup\$ Submitted: codegolf.stackexchange.com/questions/278835/… \$\endgroup\$ Commented Mar 22, 2025 at 1:07
2
\$\begingroup\$

Selection and Prediction

Your challenge: to select the strings A and B and predict others' selections in an -style .

All entries should be Python 3.10ish META: version? also possibly JS if I have time ._..

Part 1: Selection

You are tasked with selecting the strings A and B as randomly as possible. You are given the previous selections you have made and the guesses your 'opponent' has made. Each input is a list of As and Bs. For example, ["A", "B", "B", "A", "B"] and ["A", "B", "A", "B", "A"] may be arguments passed to your program.

Your program should output either of A or B deterministically, meaning the same input should result in the same output. This means no calling random.choice() or similar, or using the date and time as seeds for a random number generator. META: maybe I should choose the first letter for them, since this constraint results in them always starting with the same letter You may also output a tuple (letter_str, state) and the state will be passed in as a keyword argument next round.

An example entry (this will compete):

Selector: AAAAAA, 3 bytes

Not much to say. This program loves the letter A

def aaaaaa(selections, guesses):
    return "A"

Part 2: Prediction

Your task is to predict the most likely move that your opponent will make. Same input, output and constraints as above.

Another example entry: (this will compete too)

Predictor: Anti-repeater, 3 bytes

Assumes you tend to repeat your previous selection.

def anti_repeater(selections, guesses):
    # It's fine to modify the lists
    return selections.pop()

Part 3: Scoring

Each Selector submission will go against each Predictor submission for a total of 110 rounds. They will select and predict for the first round, then select and predict again, and again, until all rounds have finished.

For each round correctly predicted (excluding the first 10 rounds, since they may be hard to predict) the Predictor submission wins 1 point. For each round incorrectly predicted (also excluding the first 10 rounds) the Selector submission wins 1 point.

The winners are the submissions with the most total points from all Selector and Predictor submissions. Since there are two winners no answer will be accepted.

If you type hint you get 0 extra points. my respect!

(Part 4: meta)

EDIT: added scoring

What do you call a where every cop goes against every robber and vice versa?

EDIT: Change 'key' to 'string' and fix up typo

EDIT: Some other stuff added

\$\endgroup\$
7
  • \$\begingroup\$ How will submissions be scored? \$\endgroup\$ Commented Dec 18, 2022 at 12:06
  • \$\begingroup\$ It's a KOTH - they go against each other \$\endgroup\$ Commented Dec 18, 2022 at 19:56
  • \$\begingroup\$ Who wins the KOTH though? \$\endgroup\$ Commented Dec 18, 2022 at 20:26
  • \$\begingroup\$ forgot that >_< Added now \$\endgroup\$ Commented Dec 19, 2022 at 20:33
  • \$\begingroup\$ Isn't it supposed to be random.choice()? \$\endgroup\$ Commented Dec 20, 2022 at 12:57
  • \$\begingroup\$ Thanks @UndoneStudios don't know how I missed that \$\endgroup\$ Commented Dec 20, 2022 at 23:00
  • 1
    \$\begingroup\$ Maybe you can allow seeded random.choice() as it still deterministic . \$\endgroup\$ Commented Jan 4, 2023 at 3:30
2
\$\begingroup\$

Bring back cup stacking

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

Balance the eggs!

Problem

You just bought a full \$2 \times 5\$ carton of \$10\$ eggs:

A molded pulp egg carton with ten eggs.

For now on, we will depict cartons with ASCII art. The top-view of the above carton would look like:

+-----+
|ooooo|
|ooooo|
+-----+

To save on production costs, the egg factory has a master egg. Every egg produced is an identical clone of the master egg, so you may assume that all eggs are the same weight and volume.

Since these eggs are of pristine quality, they come with a hefty price. You decide that it would be better if you ordered them in bulk and stack them in a freezer so that you're stocked for the whole year. Managing all those eggs is tedious, so you also design and build a robot, to automatically pick random eggs every morning for you. They have to be random so that the robot's gears wear out evenly and don't jam.

As the robot takes out \$4\$ eggs out of the carton:

+-----+
|.oo.o|
|.ooo.|
+-----+

the carton becomes unbalanced. We have \$2\$ rows, an even number, so the \$X\$-axis passes between them and seperates the carton into two regions, \$X_{top}\$ and \$X_{bottom}\$:

  X_top

  +-----+
  |.oo.o|
X -------
  |.ooo.|
  +-----+

  X_bottom

And we have \$5\$ "columns", an odd number, so the \$Y\$-axis passes ontop of the middle column of eggs. It ignores the middle column and seperates the carton into two regions again, \$Y_{left}\$ and \$Y_{right}\$. Thus, we end up with four regions:

          X_top

             Y
             |
          +--|--+
          |.oo.o|
Y_left  X ---+---  Y_right
          |.ooo.|
          +--|--+
             |

          X_bottom

While munching on eggs and admiring your creation, you realize a terrible mistake you've made. As more and more cartons become unbalanced, the stacks become unstable. Soon, egg cartons will start falling, and they might even land on other cartons! A cascading-chain-egg-carton-fall-apocalypse!

Randomly picking eggs uniformly should've already taken care of this, but the hardware RNG is bugged. Buying new hardware is very costly and it would arrive too late anyway. You don't have enough space in the freezer to unstack the cartons either and you certainly don't have enough time to unfreeze and eat so many eggs. You have only one option.

Goal

You have to update the robot's firmware to automatically balance a carton.

Balancing

To balance a carton, you realize that the following conditions suffice:

  1. The number of eggs in the \$X_{top}\$ region of the carton must be equal to the number of eggs in the \$X_{bottom}\$ region.
  2. Extending that condition, the two regions must be the reflection of each other, mirrored either through a single axis or both axes.
  3. Similarly for the \$Y_{left}\$ and \$Y_{right}\$ regions.

If you were to balance the previous carton, you'd get:

+-----+
|.ooo.|
|.ooo.|
+-----+

After some thinking, you realize a second solution is also possible:

+-----+
|o.o.o|
|o.o.o|
+-----+

But you don't really care, as long as the carton is balanced. You name these perfect cartons. A full carton would also qualify, as would a fully empty carton.

An invalid solution, however, would be this:

+-----+
|o.oo.|
|o.oo.|
+-----+

While condition 1 is satisfied, the regions \$Y_{left}\$ and \$Y_{right}\$ are not reflections of each other, so condition 2 is not satisfied.

Condition 2 (Mirror regions)

Examples of mirror regions through a single axis:

X regions   Y regions   X & Y regions

 .o.        o.|.o        .o|o.
 ...        .o|o.        ..|..
-----       o.|.o       ---+---
 ...                     ..|..
 .o.                     .o|o.

In some cases, reflections through both axes must be considered for a solution to count as valid. In the \$2 \times 5\$ carton, for example, this configuration is considered perfectly balanced:

+-----+
|oo..o|
|o..oo|
+-----+

and thus constitutes a third solution. Let's break it down:

          X_top

             Y
             |
          +--|--+
          |oo..o|
Y_left  X ---+---  Y_right
          |o..oo|
          +--|--+
             |

          X_bottom

In shorter form:

oo . .o
o. . oo

Ignoring the middle column, as it's already symmetric:

oo|.o
--+--
o.|oo

Reflecting \$X_{top}\$ through both axes:

Through X-axis first   Then through Y-axis (but order doesn't matter)
oo|.o        |           |          |
--+--  =>  --+--       --+--  =>  --+--
  |        oo|.o       oo|.o      o.|oo  <- Same as X_bottom!

Reflecting \$Y_{left}\$ through both axes:

Through X-axis first   Then through Y-axis (again, order doesn't matter)
oo|        o.|         o.|          |.o
--+--  =>  --+--       --+--  =>  --+--  <- Same as Y_right!
o.|        oo|         oo|          |oo

Respectively \$X_{bottom}\$, \$Y_{right}\$.

This allows for many more valid solutions:

+-----+  +-----+  +-----+  +-----+  +-----+
|o..oo|  |.oo.o|  |.oo.o|  |.o.oo|  |oo.o.|
|oo..o|  |o.oo.|  |o.oo.|  |oo.o.|  |.o.oo|
+-----+  +-----+  +-----+  +-----+  +-----+

All of the above are perfectly balanced; balanced on both the \$X\$ and \$Y\$ axes.

Edge cases

After skimming through your digital egg database, you realize that some cartons cannot be perfectly balanced. This carton:

+-----+
|..o..|
|..o.o|
+-----+

doesn't have enough eggs that you can move around to balance it! It would need atleast one more. Throwing eggs away just to balance a carton is overly wasteful and the robot's CPU is too slow to calculate whether it can borrow eggs from other cartons; it can only handle one carton at a time. Fortunately, not many of such cartons are actually in your freezer, so you believe that it's enough to balance on atleast one of the axes, either \$X\$ or \$Y\$. These are imperfect cartons.

Two example solutions of the above would be:

+-----+  +-----+
|..o..|  |.....|
|o...o|  |o.o.o|
+-----+  +-----+

The second solution might seem inferior to the first one, or that it should be outright rejected. But remember: the carton is imperfect, so it's enough to balance on a single axis. Here, specifically, the carton is balanced on the \$Y\$-axis in both solutions.

Non-cases

In a sudden moment of mathematical thinking, you discover that there are also some cartons that cannot be balanced at all. This carton:

+--+
|..|
|.o|
+--+

cannot be balanced on either axis, it's an unbalanceable carton. You query your database and... No such carton exists in your freezer! After some head-scratching, it becomes apparent that, to prevent future headaches, you should handle these cartons in one of the following ways:

  • Leave them unchanged.
  • Try to (unsuccessfully) balance them, but preserve their number of eggs and size.

Thus, for the carton above, any of these - and only these - following outputs is valid:

+--+  +--+  +--+  +--+
|..|  |..|  |o.|  |.o|
|.o|  |o.|  |..|  |..|
+--+  +--+  +--+  +--+

The robot must not crash on unbalanceable cartons under any circumstances!

Input

Since the robot can only handle one carton at a time, the firmware should accept a single carton as input. As you've had this egg setup for a while now, you've developed multiple formats for digitally storing your eggformation. Every carton is available in various formats, so you use the most convenient one for you. Example formats include:

  • ASCII art:

    +-----+      +-----+
    |.oo.o|  or  | oo o|  or  .oo.o
    |.ooo.|      | ooo |      .ooo.
    +-----+      +-----+
    
  • List of lists:

    [[0,1,1,0,1],  or negated  [[1,0,0,1,0],  or  [[False, ...],
    [0,1,1,1,0]]               [1,0,0,0,1]]       [False, True, ...]]
    
  • List:

    Carton = list[int]  # Or `list[bool]`.
    
    def balanced_carton(rows: int, cols: int, carton: Carton) -> Carton:
        ...
    
    output = balanced_carton(2, 5, [0,1,1,0,1, 0,1,1,1,0])
    
  • Binary blob, including bitmap images.

  • Combination of the above, as long as it's documented.

While the eggs are all identical, the cartons are not! Your freezer contains cartons of various sizes. Your formats reflect that and your new firmware must handle any size of carton.

Output

Your output must be a single carton, as well-balanced as possible, in whatever format you find most convenient. Given the first carton as an example, if you were to output in the "ASCII art" format, your output could be:

+-----+
|o.o.o|
|o.o.o|
+-----+

or any other valid solution.

To achieve consistent carton configurations, if the input carton is already balanced, the robot is allowed to rebalance it and arrive at a different - or the same - solution.

The firmware should not output whether the carton is perfect/imperfect/unbalanceable.

Constraints

  • You don't want to go through this again, so you won't cut any corners (no loopholes)!
  • The robot's onboard EEPROM is but a few bytes. Your code must be as small as possible ()!

Examples

TODO

\$\endgroup\$
15
  • \$\begingroup\$ I hope that the goal of this challenge is clear enough and that the conditions I came up with encompass all the listed cases. If not, please let me know! I'm not sure what kind of examples to include yet, so suggestions are welcome. Also, what tags are appropriate for this? \$\endgroup\$ Commented Apr 19, 2025 at 5:27
  • 1
    \$\begingroup\$ What exactly is the required information in the output? Are solutions only required to output the carton, balanced as perfectly as possible, or are they also required to output perfect/imperfect/error? (Personally, I'd recommend the former, and additionally guaranteeing that invalid cases simply won't be given as input.) \$\endgroup\$ Commented Apr 19, 2025 at 16:56
  • \$\begingroup\$ ...and also come to think of it... is there any difference at all between different inputs with the same number of eggs? \$\endgroup\$ Commented Apr 19, 2025 at 16:59
  • 1
    \$\begingroup\$ @UnrelatedString Yes, the output should be a carton, in any format you find most convenient, that should be as perfectly balanced as possible. I'd like for the "robot" to be able to handle any carton configuration, so I don't want to outright ban "impossible" cartons. But I agree that I should relax the "report error" part and allow solutions to just return a carton untouched, if it can't be balanced at all. As for your second question; Every egg is identical, but carton sizes vary. I think that information is enough so that solvers can infer other invariants. \$\endgroup\$ Commented Apr 19, 2025 at 18:58
  • \$\begingroup\$ @UnrelatedString, I've made quite a few of changes and fixed some things. Feel free to take a look again. \$\endgroup\$ Commented Apr 20, 2025 at 1:11
  • 1
    \$\begingroup\$ (1) Are we going to output all possibilities of a balanced carton, or do we just need to output one solution? (2) The introduction story can be shorter (I personally don't like unnecessary details like "master" eggs and RNGs and such.) (3) If there are cases of unbalanceable carton, how about: Output a minimum number of eggs that need to remove in order to make the carton balanceable again. Just to be realistic. \$\endgroup\$ Commented Apr 21, 2025 at 9:49
  • \$\begingroup\$ @Explorer09 Only one, like the example under the "Output" section. I show many the possibilities to make clear that I really only care if a carton is balanced, not about its configuration. This is in the hopes that solvers will come up with different algorithms, where some might be less/more golfier than others. \$\endgroup\$ Commented Apr 21, 2025 at 11:33
  • \$\begingroup\$ @Explorer09 ...Continuing, I think the unbalanceable carton rules are okay enough. Certainly, this is a part of the puzzle where many different alternative paths could be taken. I decided to go with those rules so that the problem doesn't expand to have many special cases. Currently, solutions are only required to just output a carton. Ofcourse, it's subjective if that's the right call. But, in my opinion, the edge-case rules already make for an interesting challenge that isn't trying to be as "smooth" as possible. \$\endgroup\$ Commented Apr 21, 2025 at 11:42
  • \$\begingroup\$ @Explorer09 ...As for the story fluff. I originally wanted to release this on Easter Day. That did not happen. The silly story was written as an "easter egg", if you will. No doubt, all this can be reduced to "take a binary matrix as input and do some weird things to it", but that's just boring. You can find many formal problem descriptions in this site, this isn't trying to be one. \$\endgroup\$ Commented Apr 21, 2025 at 11:50
  • \$\begingroup\$ @pan The problem with an indeterministic solution is that people would be difficult to verify whether the submission programs work correctly. And, as people may come up with different algorithms with solving this, the competition on code golfing would be focused on discovery of the best algorithm of the job, rather than the code minification of the same or similar algorithms. Like merge sort vs. bubble sort, the choice of algorithm might significantly affect code size. \$\endgroup\$ Commented Apr 21, 2025 at 14:33
  • \$\begingroup\$ @pan And, for (2), I don't object to made-up stories for a challenge. What I don't like is when a story fills up unnecessarily details, not relevant to the challenge presented. Yes, it's about placing eggs in a carton in a balanced fashion, but if you go all the way in giving an initial setup (rathen than just number of eggs and the carton's dimensions), I expect the solution should be related to that setup in some way (such as, requiring only the minimum number of moves from that setup). That's how your story can be plausible. \$\endgroup\$ Commented Apr 21, 2025 at 14:46
  • \$\begingroup\$ @Explorer09 Agree to disagree. I want people to search for the "best" algorithm. It promotes clever answers, rather than just blindly golfing a set-in-stone solution (not that it's easy). Also, I can imagine that the golfiest algorithms would be different across imperative, functional and array languages, and others. Yes, that makes verifying a little bit harder, but that happens with many challenges here. The burden falls upon the solver and the participants. Is it possible to miss a wrong answer? Sure, but it wouldn't be the end the world or the first time. \$\endgroup\$ Commented Apr 21, 2025 at 15:45
  • \$\begingroup\$ @Explorer09 Taking the number of eggs instead of the actual configuration is a valid argument. I'm leaving it as it is for now for two reasons. First, although it's probably trivial to make that observation, I'd like for one to find that "symmetry" on their own. And second, it doesn't add that much boilerplate to sum the rows and columns of a matrix. Having a solution related to the setup is a nice idea for a future challenge! \$\endgroup\$ Commented Apr 21, 2025 at 15:49
  • \$\begingroup\$ Allow me to express my concern in another way: How would you prepare your example data where there multiple possible solutions for a particular test case? And how would you verify that people's submissions are correct? \$\endgroup\$ Commented Apr 21, 2025 at 23:52
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ Commented Apr 22, 2025 at 1:15
2
\$\begingroup\$

Self-deranging but self-fixing?!?!

Challenge

  • Find a program that prints another program, which prints another program and so on, and goes back to the original program.

  • At each step, the program must print a program that is a derangement of itself. A derangement is a permutation of a string that leaves no character fixed.

  • The programs should not take any inputs nor have direct access to its own source code file.

  • The program must be at most 1000 bytes.

Scoring

  • The score would be the period or the number of steps it takes to return to the original program. The higher the score, the better.

\$\endgroup\$
4
  • \$\begingroup\$ related but not duplicate, possible duplicate, \$\endgroup\$ Commented Jun 16, 2025 at 9:28
  • \$\begingroup\$ Welcome to Code Golf and nice first question draft! It's possible to create an arbitrarily long-period quine of this form by e.g. having something of the form abcabcabcabc... for some same-length blocks a, b, c, with no characters in the same positions, and rotating some of them different amounts to reach most of the permutation space. I'd recommend either bounding the length of the program, or dropping that score and just making the challenge [code-golf], since constructing a quine of this form is already quite difficult. \$\endgroup\$ Commented Jun 16, 2025 at 9:40
  • \$\begingroup\$ @emaresuA Thanks for the suggestion, I bounded the program size but 1000 bytes, I guess that will do \$\endgroup\$ Commented Jun 16, 2025 at 10:05
  • \$\begingroup\$ I think "1000" feels very arbitrary and diminishes the question. \$\endgroup\$ Commented Jul 8, 2025 at 21:50
2
\$\begingroup\$

Triangular transposition cipher

\$\endgroup\$
2
  • \$\begingroup\$ Perhaps it would be beneficial to guarantee that n is large enough that all 22 permutations are distinct? Some clever approaches might choke on the edge case otherwise. \$\endgroup\$ Commented Jun 22, 2025 at 22:14
  • \$\begingroup\$ @UnrelatedString I was thinking about that too, would limiting the number of permutations to 22 total work as well? So that duplicates are allowed for n<4 \$\endgroup\$ Commented Jun 24, 2025 at 2:25
2
\$\begingroup\$

Crash your program

Okay, so. As far as I can tell, we don't actually have a simple, generic "crash the program" challenge yet. (We do have some challenges where crashing the program is the overall goal, but it needs to be done in a particular manner — for instance, by raising a specific signal. This challenge aims to do away with the specifics.)

Challenge

Write a full program that unconditionally crashes when run.

  • The program must not take any input. Arbitrary output is allowed.
  • For the purpose of this challenge, a program crashes when it performs an action at runtime that results in abnormal termination of the process (or the equivalent).
    • For interpreted languages, the program must be syntactically valid. For example, ) is not a valid answer in Python, since syntax errors aren't an action performed by the program; raise SyntaxError(), however, is OK (albeit quite boring).

    • For compiled languages, the program must successfully compile (warnings don't matter) and produce a binary that crashes at runtime; crashing the compiler does not count.

    • Exceptions are made for languages which cannot cause runtime crashes in this manner; compiler/interpreter errors are allowed in this case. Please add a note if your answer makes use of this exception.

      Meta: I'm not completely sure about what, specifically, I want this exception to permit.

  • The program may take an arbitrarily long time to crash, as long as it can be proven that it will, eventually, do so.

Scoring

Meta: I'm not entirely sure what kind of winning criteria I want to go for here — I'm seeking to give answerers creative freedom to crash in however way they please.

seems closest to what I'm looking for, but I'm not sure whether this challenge is too vague for that. I'm open to suggestions!

This is a ; the highest-voted valid answer wins. Note that code size is irrelevant here — feel free to show off some quirks of your language! (Multiple answers in the same language are allowed and encouraged if there are several interesting ways to crash in said language.)

\$\endgroup\$
1
  • \$\begingroup\$ @macOsithebestOS Good question \$\endgroup\$ Commented Jul 9, 2025 at 17:18
2
\$\begingroup\$

Less is better

You choose between two halves of a pitch. If you are on the half with fewer players, you win!


Structure

Each game will have 1000 rounds.

Each round will consist of the following:

  • Your bot is given their move history for each previous round during this game. This will be given as a list of 0s and 1s.
  • Your bot is given the history for each previous round during this game on the number of bots in each half. This will be given as a list of tuples, with each tuple containing exactly two integers.
  • Your bot is given their custom memory dictionary which they can mutate to store custom data inbetween rounds. Memory does not persist across games.
  • Your bot must return either 0 or 1, with 0 being the first half, and 1 being the second half. Your bot will move to that half.

At the end of a game, every bot on the half of the pitch with the least bots wins! If both halves are at a tie, nobody wins!

Note: the winner of the whole tournament is determined by who won the most games. Multiple games occur to determine the winner.

Entries must be in Python 3.


Example entries

Not moving

def not_moving(move_history, round_history, memory):
 memory.update({len(move_history): [move_history, round_history, "I AM STANDING STILL FOREVER!"]}) # Demonstrating the three arguments
 return 0 # Look, I had to choose a number, ok?

Alternating

def alternating(move_history, round_history, memory):
 if len(move_history) == 0: # Error handling, lol
  return 0
 return 1 - [move_history[-1]] # This happens to alternate between moves

I am waiting for feedback before I make the controller for the challenge.

\$\endgroup\$
5
  • \$\begingroup\$ how is the singular winner chosen? as it stands, you could have 49.9% of winners, unless i misunderstand how bots are eliminated. \$\endgroup\$ Commented Jul 25, 2025 at 8:21
  • \$\begingroup\$ suggest creating a superclass for bots, because you do not want to find each bot's run function and it'd be much easier for everyone to inherit from the bot class. This would also enable bots to have custom attributes instead of passing around a dict for memory. \$\endgroup\$ Commented Jul 25, 2025 at 8:23
  • \$\begingroup\$ @Themoonisacheese Multiple games are run to determine the winner. I will edit that into the post. \$\endgroup\$ Commented Jul 25, 2025 at 9:31
  • \$\begingroup\$ i don't think this is enough. most bots will behave deterministically, (unless you introduce a random bot on purpose, which could be a solution), so games will mostly always end up the same way. \$\endgroup\$ Commented Jul 25, 2025 at 9:35
  • \$\begingroup\$ Even with only deterministic solutions one can run games with random subsets of the participants \$\endgroup\$ Commented Jul 26, 2025 at 4:38
2
\$\begingroup\$

Squared Squares

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

Sort Key for Japanese Wikipedia Article

Introduction

Unlike English, Japanese language has massive amount of letters, therefore Japanese Wikipedians have to give how the article's title has to be read in hiragana and make it sortable with the {{DEFAULTSORT:}} magic word for categories. I'm an Uncyclopedian btw :-P

Task

Write a program/function to take a string of hiragana characters to return a string of hiragana characters suitable for sorting.

Character encoding

Your function input/output shall handle, at your choice, encoding or character set registered in IANA as of September 2025 including but not limited to one of the following encoding or codepoints, and must be consistent: Unicode, JIS X 0208, JIS X 0213, UTF-8, UTF-16 (BE or LE), UTF-32 (BE or LE), ISO-2022-JP, EUC-JP, Shift_JIS. Your encoding must implement exactly every character in Input range. Your encoding must: (1) implement hiragana, and (2) must distinguish hiragana and katakana.

Input range

These characters and choompu symbol shall appear (separated by newlines for readability):

あいうえおかきくけこさしすせそたちつてと
なにぬねのはひふへほまみむめもやゆよ
らりるれろわをん
がぎぐげござじずぜぞだぢづでど
ばびぶべぼ
ぱぴぷぺぽ
ぁぃぅぇぉっゃゅょ
ー

Theose code points are:

  • in JIS X 0213, 1-1-28 for , 1-4-1 through 1-4-77 for through , 1-4-79, 1-4-82 and 1-4-83 for わをん; and
  • in Unicode, U+3041 through U+308D for through , U+308F, U+3092 and U+3093 for わをん, and U+30FC for .

You must not use (U+3099), U+309B (the combination character of that dakuten), (U+309C), U+309A directly.

What your function should do

The rules are as follows:

(1) each symbol is converted to a hiragana depending on a letter it immediately follows:

  1. (1a) when it follows one of あかさたなはまやらわがざだばぱぁゃ; or
  2. (1b) when it follows one of いきしちにひきりぎじぢびぴぃ; or
  3. (1c) when it follows one of うくすつぬふむゆるぐずづぶぷぅゅ; or
  4. (1d) when it follows one of えけせてねへめれげぜでべぺぇ; or
  5. (1e) when it follows one of おこそとのほもよろごぞどぼぽぉょ.

(1-2) The symbol shall occur to satisfy one of rules (1a)-(1e).

(2) The dakuten and handakuten symbols are removed; that is, here are how hiragana characters with those symbols shall be remapped:

  1. (2a) がぎぐげござじずぜぞだぢづでどばびぶべぼ to かきくけこさしすせそたちつてとはひふへほ; and
  2. (2b) ぱぴぷぺぽ to はひふへほ.

(3) The small characters are enlarged; that is, ぁぃぅぇぉっゃゅょ to あいうえおつやゆよ.

(4) Other characters are left unchanged.

Test cases

Input => Output

おっくすふぉーどだいがくしゅっぱん => おつくすふおおとたいかくしゆつはん
こーどごるふあんどこーどちゃれんじすたっくえくすちぇんじ => こおとこるあんとこおとちやれんしふすたつくえくすちえんし
ぽぷてぴぴっく => ほふてひひつく
うぃきぺでぃあとあんさいくろぺでぃあのちがい => ういきへていあとあんさいくろへていあのちかい
しーしゃーぷとじゃばのちがい => しいしやあふとしやはのちかい
ふぁーれんはいと => ふああれんはいと
かがく => かかく
しょぐうかいぜん => しよくうかいせん
ぶぶづけ => ふふつけ
ばーる => はある
あぼりじに => あほりしに
こーとじぼわーる => こおとしほわある
わーるどかっぷ => わあるとかつふ

Other rules

Standard loopholes. Standard I/O. .

Links

Meta

I have found a loophole that the task-answering people would use encoding such that usual hiragana and dakuten (or handakuten) are separated as in sequence of and (U+3099: combinating characater, not U+309B) to replace (U+304C); how do I prohibit the loopholes?

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

Is it n-th A121016 or A328594?

Task

Given an unsigned integer, output two items:

  1. a boolean value to indicate whether it is in sequence of A121016 or A328594; and
  2. an integer N when input integer is N-th value of the sequence. N shall be either 0-indexed or 1-indexed, and for both sequences, it must be consistent.

A121016: Numbers whose binary expansion is properly periodic.

For example, 204=(1100 1100)_2 and 292=(100 100 100)_2 belong to the sequence, but 30=(11110)_2 cannot be split into repeating periods.

A328594: Numbers whose binary expansion is aperiodic.

It's complement of A121016; every nonnegative integer not belonged to A121016 is A328594, for example 30 is in but 204, 292 are not.

Test cases

This is 0-indexed version.

Input => (is_periodic,N)
0 => false,0
1 => false,1
2 => false,2
3 => true,0
4 => false,3
5 => false,4
6 => false,5
7 => true,1
8 => false,6
9 => false,7
10 => true,2

Rules

Code-golf. Standard i/o. Standard loopholes.

Meta

\$\endgroup\$
2
  • 2
    \$\begingroup\$ why specifically focusing on the oeis sequences? a simple challenge classifying numbers as having binary expansions (a)periodic and just mentioning the oeis sequences for further reference would be fine \$\endgroup\$ Commented Aug 27, 2025 at 13:45
  • 2
    \$\begingroup\$ We already have this similar challenge for strings without the binary aspect. I'd expect most answers to use a binary-string built-in then apply the same techniques. \$\endgroup\$ Commented Aug 27, 2025 at 17:03
2
\$\begingroup\$

Solve my Reaction equation

Inspired by a joke a friend of mine recently made:

Screenshot discord, 21 times 131 equals 112 shown in reacts

The image shows a series of emoji reactions to a Discord message, where, by one reading of the emojis used and the number of reactions, one can "conclude" that \$21 \times 131 = 112\$. This then lead to the group discussing under what circumstances this equation can be made true, given that some digits change depending on who reacts with what emoji. For instances, at current writing, the equation actually reads \$27 \times 637 = 819\$ (clearly false).

You will be given three single digits and a mathematical operation: \$+, -, \times\$. You must then output 5 single digits that "complete" the equation given.


Blah blah, , y'all know the drill. To be elaborated on later. General thoughts?

\$\endgroup\$
3
  • \$\begingroup\$ I like the idea but I spent a solid minute trying to figure out the image before reading the text because I thought the quote about a science class was relevant (maybe this is just my issue) \$\endgroup\$ Commented Sep 25, 2025 at 23:02
  • \$\begingroup\$ Presumably the output digits cannot be zero? If these are also restricted to be 1-9 then I think there are several scenarios that do not have a solution. In basically every case the minimum product will be more than three digits and for subtraction the result is often required to be negative. This isn't really a problem, but you might want to allow more digits to get a larger space of valid inputs. \$\endgroup\$ Commented Oct 22, 2025 at 19:31
  • \$\begingroup\$ @FryAmTheEggman There are cases where 0 would be permissable, specifically only the "3" emoji in the example, while the rest would all be leading 0s. I'm not super sure about whether to allow that specific rules quirk, or just be consistent with 1-9 for everything \$\endgroup\$ Commented Oct 23, 2025 at 12:36
2
\$\begingroup\$

Cold Bee and Old Beer Part 1:

Tags:

Posted


Cold Bee and Old Beer Part 2:

Tags:

@Xcali's idea when I had my Cold Bee and Old Beer challenge in the Sandbox:

Also, an interesting, possibly more complex challenge comes to mind. The issue with the scrolling sign isn't that it lops off the first or last letter, per se. It's that it only has space for 8 characters. Another challenge might be to select from the dictionary a phrase (one or more words) which will always display only valid words on the sign no matter where it is in the phrase. Basically, given the dictionary and a sign width (n), find a string such that all substrings of length n have only valid words.

Challenge:

Given a list of strings \$D\$ictionary and an integer \$w\$idth, output the largest 'sentence' of delimited words from \$D\$ for which every substring of length \$w\$ split by the delimiter-character are separated words from \$D\$, or a letter.

This may be a bit vague, so here an example:

Inputs:
\$D\$ = ["be","bears","bee","beer","his","is","the","these","this"]
\$w\$ = 5

Output: "this beer"

Since all 5-part substrings are: ["this ","his b","is be","s bee"," beer"], containing the words and letters ["this","his","b","is","be","s","bee","beer"], of which all the words of 2+ letters are present in \$D\$.

Challenge rules:

  • I/O is flexible. Can be a list of words; a delimited string (with spaces, commas, newlines, a digit, etc.); loose inputs and output-lines; etc.

General Rules:

  • This is , so the shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (e.g. TIO or ATO).
  • Also, adding an explanation for your answer is highly recommended.

Test Cases:

D: ["be","bears","bee","beer","his","is","the","these","this"]
w: 5
Output: "this beer"

TODO: More test cases.

\$\endgroup\$
9
  • \$\begingroup\$ I object to calling the video stupid. I believe it is excellent! \$\endgroup\$ Commented Apr 23, 2024 at 6:35
  • \$\begingroup\$ @Tbw I've removed the word stupid. ;) I also realized after just removing it, I meant to state 'silly'. Mb \$\endgroup\$ Commented Apr 23, 2024 at 7:00
  • \$\begingroup\$ Suggest some multiple output cases \$\endgroup\$ Commented Apr 27, 2024 at 10:51
  • \$\begingroup\$ @l4m2 I intended to. I've just added some more multi-output test cases. \$\endgroup\$ Commented May 1, 2024 at 13:34
  • 2
    \$\begingroup\$ Are the two words in the pair allowed to be the same word. Something like this input: ["beer","bee","eer"] producing ["beer","beer"] as an output? \$\endgroup\$ Commented May 1, 2024 at 16:45
  • 1
    \$\begingroup\$ Also, an interesting, possibly more complex challenge comes to mind. The issue with the scrolling sign isn't that it lops off the first or last letter, per se. It's that it only has space for 8 characters. Another challenge might be to select from the dictionary a phrase (one or more words) which will always display only valid words on the sign no matter where it is in the phrase. Basically, given the dictionary and a sign width (n), find a string such that all substrings of length n have only valid words. \$\endgroup\$ Commented May 1, 2024 at 16:49
  • \$\begingroup\$ @Xcali Good question. I would say no, but that does make my potential implementation approach incorrect. :) As for the alternative approach, I might make a part 1 and 2. \$\endgroup\$ Commented May 6, 2024 at 13:12
  • \$\begingroup\$ @Xcali 1.5 years later.. 😅 But I've put your alternative challenge idea as a part 2. Lmk if this is roughly what you had in mind and if you have rules or test cases you'd like to see added. \$\endgroup\$ Commented Sep 30, 2025 at 13:51
  • \$\begingroup\$ With Part 2: the example doesn't contain any spaces, but the output does. Should answers include spaces by default, or only allow them if an element of D contains a space? \$\endgroup\$ Commented Oct 11, 2025 at 5:06
2
\$\begingroup\$

Rebase Until Inert

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

Compute the NFL passer rating

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

Eat More Brains Than The King

Zombie Dice is a dice rolling game about balancing how many brains you, an average zombie, can eat before you get shot 3 times by a shotgun wielding madman, unreasonably obsessed with keeping his brain. You are to write a zombie bot that is able to eat more brains than any other bot, and become King Zombie.


How to play

There are 13 6-sided dice available: 6 green, 4 yellow and 3 red. Each dice has a different distribution of symbols depending on color:

  • Green: 3 "brains", 2 "footsteps" and 1 "shotgun"
  • Yellow: 2 brains, 2 footsteps and 2 shotguns
  • Red: 1 brain, 2 footsteps and 3 shotguns

On a player's turn, they choose and remove 3 dice, blindly, from the pool of available dice. They roll them, and then decide: they can roll again, or end their turn.

  • If they choose to roll again, they set aside all rolled dice showing brains or shotguns, keep all dice showing footsteps and collect as many dice from the pool as needed to have 3 dice. If there aren't enough dice in the pool, their counts of brains and shotguns are recorded for the turn and all brains and shotguns returned to the pool. They then roll these 3 dice, and repeat their choice: roll again, or end their turn.

  • If they choose to end their turn, their score is increased by the number of brains they rolled, the dice are returned to the pool and the next player begins their turn.

  • However, if, at any point, the player has rolled 3 or more total shotguns, their turn immediately ends, all dice are returned to the pool and all their rolled brains that turn are discarded.

Once a player ends their turn with a score of 13 or more, every other player takes one final turn to attempt to beat that, and all other, scores. The player with the highest score wins their game.


Example game

Three Zombies - Alice, Bob, Carol - are playing. Alice begins by taking 3 dice (2 red, 1 green) and rolls 1 shotgun (red) and 2 footsteps (red, green). She decides to continue, taking 1 extra dice from the pool (yellow) and rerolls the 2 footsteps, resulting in 1 shotgun (green) and 2 brains (red, yellow), for a total of 2 and 2. Not willing to risk losing her two brains by rolling a third shotgun, she ends her turn and makes her score 2.

Bob then begins his turn by taking 2 red and 1 yellow dice, only to roll 2 shotguns (red) and a footstep (yellow). This is a dire position, but he decides to gamble, taking 2 more dice: one red and one yellow. He rolls these 3 dice, only to see a shotgun and 2 brains. Having rolled 3 total shotguns, his turn is over, and the two brains discarded, for a total score of 0.

Carol then begins her turn by taking 2 green, 1 red dice, and rolls 3 brains. Continuing her good luck streak, she takes 3 dice (2 red, 1 yellow) and rolls 2 brains (reds) and a footstep (yellow). Going again, she takes 2 green dice, rolls 2 more brains and 1 shotgun. Happy with how her luck has gone, she ends her turn, increasing her score to 7.

Back to Alice, she takes another turn, and so on, until one of the Zombies' scores reaches 13 or more.


Challenge

This is a challenge based in . You are to write a function zombie_<name> that accepts the following arguments:

  • scores: a dictionary with keys equal to the names of all players in the game, and values equal to their scores;

  • rolls: A history of the rolls this turn, consisting of lists of 3 tuple pairs in the format (roll, color) for the three dice rolls:

    • roll will be one of b, f, s,
    • color will be one of g, y, r;

    The most recent 3 rolls will be at the end of rolls, while the first roll at the start;

  • brains: a non-negative integer equal to the number of brains the bot has rolled so far on this turn, including any rolled in rolls;

  • shotguns: a non-negative integer equal to the number of shotguns the bot has rolled so far on this turn, including any rolled in rolls;

  • global_wins: a dictionary with keys equal to the names of all bots, and values equal to the points earned by winning their games; and,

  • global_info: a dictionary with keys equal to the names of all bots, and values equal to an initially blank dictionary. You can use this dictionary to store information between turns, and you may not attempt to access information under other bots' names.

You should then return one of two strings, Again or End, to indicate if you'd like to continue rolling, or end your turn and bank your score.

Your bot will be called repeatedly by the controller until their turn ends. If the shotguns argument is 3 or more when passed to your bot, the bot will still be called, but their output will be ignored.


Scoring

Every bot, including the two example bots below, will compete against every other bot in games of 4 Zombies each. A bot scores 1 point for winning (including a tie), and the top 4 Zombies after all games are played will play five finale games against each other, with the overall winner of those games being crowned King Zombie.


Example Bots

Play It Safe

def zombie_play_it_safe(scores, rolls, brains, shotguns, global_scores, global_info):
	if any('b' == roll[0] for roll in rolls[-1]):
		return 'End'
	return 'Again'

Play It Safe only cares if it rolls at least one brain. If that's the case, it ends its turn immediately and banks those brains. Otherwise, it rolls again.

Braiiinnnssss

def zombie_braiiinnnsss(scores, rolls, brains, shotguns, global_scores, global_info):
	if shotguns == 2:
		return 'End'
	return 'Again'

Braiiinnnssss is the opposite of Play It Safe and will constantly reroll until it rolls 2 shotguns, not caring about any dice colors or previous other rolls.


Meta

\$\endgroup\$
2
  • \$\begingroup\$ What does rolling a footstep do? \$\endgroup\$ Commented Sep 16, 2025 at 17:17
  • 1
    \$\begingroup\$ @Seggan Ah, it's implied in the text but I suppose not explicit: when rerolling, you keep dice that rolled footsteps and reroll them. So if you roll 1 brain on any color and 2 footstep on 2 greens, it's better to reroll than rolling 1 brain and 2 footsteps on 2 reds \$\endgroup\$ Commented Sep 17, 2025 at 9:58
2
\$\begingroup\$

Divide 1 by a sum/difference of square roots

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

Represent a fraction as a 2-adic integer

Objective

Given a reduced fraction whose denominator is positive and odd, represent the fraction as a 2-adic integer.

Introduction to 2-adic integers

Informally

Informally, a 2-adic integer is an infinite string of binary digits that expands to left. As a consequence, 2-adic integers consist a superset of integers. Addition on 2-adic integers is defined as the usual bit-wise addition-with-carry, and multiplication on 2-adic integers is defined as the same as the schoolbook multiplication.

What's interesting about 2-adic integers is that negation is well-defined. Given a 2-adic integer \$x\$, its negation \$-x\$ is defined as \$\mathsf{bitNOT}(x)+1\$. That is, to arithmetically negate a 2-adic integer, bit-wise negate it and add \$1\$. This is akin to the two's complement representation of signed integers.

Provided that \$q\$ is a positive odd integer, it's possible to divide any 2-adic integer by \$q\$. Its explicit method of computation requires formal definition of 2-adic integers, which is explained below.

Formally

A formal, alternative representation of the 2-adic integers is a certain subring of the product ring \$\prod_{n=1}^\infty {\mathbb{Z}/\langle2^n\rangle}\$ (That is, the Cartesian product of integers modulo 2, integers modulo 4, integers modulo 8, and so on infinitely). The restriction employed by the 2-adic integers is that, for every positive integer \$n\$, the entry in \$\mathbb{Z}/\langle2^{n+1}\rangle\$ must be equal to the entry in \$\mathbb{Z}/\langle2^n\rangle\$, up to modulo \$2^n\$.

Provided that \$p\$ is a 2-adic integer and \$q\$ is a positive odd integer, the division \$p/q\$ is simply entry-wise modular division by \$q\$. This is possible because \$q\$ is coprime to \$2^n\$ for every positive integer \$n\$, and the division results in a well-defined 2-adic number.

The formal representation above can be turned into the informal representation recursively as follows. The resulting rightmost bit is 0 if the provided entry in \$\mathbb{Z}/\langle2\rangle\$ is \$0\$, and is 1 otherwise. For every positive integer \$n\$, the \$n\$-th (zero-indexed) rightmost bit is 0 if the entry in \$\mathbb{Z}/\langle2^{n+1}\rangle\$ is equal to the entry in \$\mathbb{Z}/\langle2^n\rangle\$ up to modulo \$2^{n+1}\$, and is 1 otherwise.

I/O format

It is known that every rational number amongst the 2-adic integers has repeating informal representation. As such, there shall be two binary strings for the output, one for the non-repeating part, the other for the repeating part. The repeating part shall have at least one bit.

For every input, you must give the shortest expansion as the output. That is, no redundant expansion. For example, provided that the output format is (<repeating part>)<non-repeating part>, the input \$1/3\$ must give (01)1, not (10)11 nor (01)011, as the output.

Otherwise flexible.

Examples

Here, the output format is (<repeating part>)<non-repeating part>.

Input, "Output"

0/1, "(0)"
1/1, "(0)1"
2/1, "(0)10"
-1/1, "(1)"
-2/1, "(1)0"
-3/1, "(1)01"
1/3, "(01)1"
2/3, "(01)10"
4/3, "(01)100"
5/3, "(01)11"
-1/3, "(01)"
-2/3, "(10)"
1/5, "(0110)1"
2/5, "(0110)10"
3/5, "(0011)1"
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I don't think the ASCII part is core to the challenge; perhaps consider just asking for two binary lists. \$\endgroup\$ Commented Oct 11, 2025 at 13:02
  • \$\begingroup\$ @JonathanAllan I'd say removing the ASCII part would offer ambiguity to the output. Namely, which array to output first, and to output LSB-first or MSB-first. So I'm not comfortable with doing that. \$\endgroup\$ Commented Oct 17, 2025 at 8:14
  • 2
    \$\begingroup\$ It does mean people would need to specify their output format, but it gives more focus on the core part of the challenge and also provides more flexibility to the approaches to golfing. I would say the net improvement would be positive (the core part is hard enough already without the output formatting getting in the way of golfing that probably complex code). You could ask people to specify their format or ask for their test suite to format their results as in your examples. \$\endgroup\$ Commented Oct 18, 2025 at 13:44
2
\$\begingroup\$

\$n\$-Simplicial Numbers

The \$n\$-simplicial numbers, or simplicial polytopic numbers, are a family of sequences of non-negative integers.

An \$n\$-simplex is an \$n\$-dimensional analogue to the tetrahedron, and the \$n\$-simplicial numbers can be defined as the sequence of numbers of objects it takes to arrange an \$n\$-simplex. In particular, the \$i\$th \$n\$-simplicial number is the number of (non-overlapping) \$\left(n-1\right)\$-spheres that can fit in an \$n\$-simplex of edge length \$i\$.

The simplicial polytopic number can be generated in any number of ways, including nested summations, combinatorics, columns of a left-justified Pascal's triangle, and so on.

For clarification:

The 2-simplex is the triangle, and the 2-simplicial numbers are the triangular numbers (A000217): 1, 3, 6, 10, 15....

The 3-simplex is the tetrahedron, and the 3-simplicial numbers are the tetrahedral numbers (A000292): 1, 4, 10, 20, 35....

The 4-simplex is the 5-cell (or sometimes 'simplex'), and the 4-simplicial numbers are: 1, 5, 15, 35, 70....

And so on.

Also worth discussing are the 1-simplex numbers, which are the natural numbers (A000027): 1, 2, 3, 4, 5....

Finally, the degenerate case: the 0-simplex numbers are an infinite sequence of units (A000012): 1, 1, 1, 1, 1....

The Challenge

Calculate the \$n\$-simplicial numbers for a given \$n\$.

As per the rules, you may do any one of the following:

  • Given a single input \$n\$, output the infinite sequence of \$n\$-simplicial numbers.
  • Given two inputs \$n\$ and \$i\$, output the \$i\$th \$n\$-simplicial number.
  • Given two inputs \$n\$ and \$i\$, output the first \$i\$ \$n\$-simplicial numbers.

Both inputs will be non-negative integers. You may 0-index or 1-index your sequences. Inputs can be in any order and format.

As this is , fewer bytes is better.

Test Cases

The following test cases text two inputs \$n\$ and \$i\$ and output the \$i\$th \$n\$n-simplicial number.

0, 600000 -> 1
1, 34     -> 34
2, 5      -> 15
4, 4      -> 35
5, 2      -> 6
15, 1     -> 1
1100, 0   -> 0
16, 256   -> 25751746463640423324267024

Meta

Open to criticism and suggestions, especially with the test cases. Also, I wasn't able to an existing challenge like this, but I also wasn't able to find a pure triangular numbers challenge, which I'm fairly sure we have, so it's possible I missed it.

\$\endgroup\$
2
  • \$\begingroup\$ I've realized that this challenge is hugely skewed towards languages with a binomial coefficient builtin... which is a bit of a shame, since there are other ways of generating these numbers which I think are more interesting. \$\endgroup\$ Commented Oct 25, 2025 at 19:07
  • 1
    \$\begingroup\$ This would just be a duplicate of the binomial coefficient challenge. (see: me four years ago, and the other exact dupe) \$\endgroup\$ Commented Oct 26, 2025 at 11:48
2
\$\begingroup\$

Order a list by the difference of its elements

Task

Given an unsorted list of integers, order it in such a way that the absolute difference of every two adjacent elements will always be equal to 1:

\$|dx| = 1\$

There will be one, two, or more solutions. You may choose any one of the solutions as your output. The list's minimal length is 2.

Your task is to output the list in the order that satisfies the condition of this challenge.

Test cases

Rules

This is code-golf. Standard i/o. Standard loopholes.

[1, 2] -> [1, 2] or [2, 1] 
[4, 5, 5, 5, 4] -> [5, 4, 5, 4, 5]
[1, 3, 2, 4, 5] -> [1, 2, 3, 4, 5] or [5, 4, 3, 2, 1]
[3, 0, 1, 1, 2, 4] -> [1, 0, 1, 2, 3, 4] or [4, 3, 2, 1, 0, 1]
[4, 2, 3, 4, 4, 5, 5] -> [2, 3, 4, 5, 4, 5, 4 ] or [4, 5, 4, 5, 4, 3, 2]
[1, 7, 5, 2, 6, 4, 4, 3, 3] -> [1, 2, 3, 4, 3, 4, 5, 6, 7] or the reverse of it
[6,10,2,12,13,5,7,1,14,9,2,1,4,10,13,11,11,12,8,3,9]
-> [11,12,13,14,13,12,11,10,9,10,9,8,7,6,5,4,3,2,1,2,1] or the reverse of it

Meta

  • Please check if the question is not a duplicate
  • You can suggest other difficult/non-trivial test cases
\$\endgroup\$
2
\$\begingroup\$

Pretty-print a table

Objective

Given an ASCII string that encodes a table in the format defined below, pretty-print it using Unicode box-drawing characters.

Input format

The input format identifies the cells of the table using ASCII control characters, namely \v (vertical tab; 0x0B), \t (horizontal tab; 0x09), and \f (form feed; 0x0C), as follows:

  • \v declares a new row and its first cell.
  • \t appends a new cell to the row it's in.
  • \f ends the table.

Note that each cell may contain \n (line feed; 0x0A).

It is assumed that:

  • All inputted characters other than these control characters are in the code range of (space; 0x20)—~(tilde; 0x7E).
  • All involved control characters are used where they're intended as above, and nowhere else. (So the inputted string must start with a \v and end with a \f.)

Otherwise flexible.

Output format

The row separators and the column separators of the inputted table is printed using the Unicode characters ─│┌┐└┘├┤┬┴┼ (U+2500, U+2502, U+250C, U+2510, U+2514, U+2518, U+251C, U+2524, U+252C, U+2534, and U+253C).

The widths and the heights of the cells are chosen to be as smallest as they can accommodate all their contents, while the cells in each row must have the same height and the cells in each column must have the same width. For this purpose, the 0x20 ASCII space is used to fill the "vacant spaces".

Note that the rows may have different numbers of cells, depending on the number of its \t.

It is assumed that:

  • Each row has height of at least one.
  • The font printing the output is monospaced.

Otherwise flexible.

Examples

"Input"
Output

"\vHello, world!\f"
┌─────────────┐
│Hello, world!│
└─────────────┘

"\vThe quick brown fox\tjumps over\tthe lazy dog.\f"
┌───────────────────┬──────────┬─────────────┐
│The quick brown fox│jumps over│the lazy dog.│
└───────────────────┴──────────┴─────────────┘

"\vThe quick brown fox\tjumps over\vthe lazy dog.\f"
┌───────────────────┬──────────┐
│The quick brown fox│jumps over│
├───────────────────┼──────────┘
│the lazy dog.      │
└───────────────────┘

"\vThe quick brown fox\vjumps over\tthe lazy dog.\f"
┌───────────────────┐
│The quick brown fox│
├───────────────────┼─────────────┐
│jumps over         │the lazy dog.│
└───────────────────┴─────────────┘

"\vThe quick brown fox\njumps over\tthe lazy dog.\f"
┌───────────────────┬─────────────┐
│The quick brown fox│the lazy dog.│
│jumps over         │             │
└───────────────────┴─────────────┘

"\vThe quick brown fox \njumps over\tthe lazy dog.\v\f"
┌────────────────────┬─────────────┐
│The quick brown fox │the lazy dog.│
│jumps over          │             │
├────────────────────┼─────────────┘
│                    │
└────────────────────┘

"\v\t\v\t\f"
┌┬┐
│││
├┼┤
│││
└┴┘

"\v \t\n\f"
┌─┬┐
│ ││
│ ││
└─┴┘
\$\endgroup\$
3
  • \$\begingroup\$ Very similar to Convert CSV to Table, not sure if it counts as a duplicate \$\endgroup\$ Commented Dec 25, 2024 at 14:34
  • \$\begingroup\$ It's difficult. \$\endgroup\$ Commented Dec 8, 2025 at 18:45
  • \$\begingroup\$ @QOO-OOKALAN As far as I've experienced, difficulty has no correlation to whether a challenge is viable. \$\endgroup\$ Commented Dec 8, 2025 at 23:26
2
\$\begingroup\$

Add two rational numbers... esoterically

Objective

Build a binary operator \$\star : \mathbb{Z} \times \mathbb{Z} \to \mathbb{Z}\$ such that, there exists a bijection \$i : \mathbb{Z} \to \mathbb{Q}\$ such that, for every integer \$M\$ and \$N\$, \$M \star N = i^{-1}(i(M) + i(N))\$ holds.

Or in mathematical terms, build a binary operator \$\star\$ that admits a group isomorphism from \$(\mathbb{Z}, \star)\$ to \$(\mathbb{Q}, +)\$.

I/O Format

Flexible. Standard loopholes apply.

Scoring

This is a challenge. The submission whose the asymptotic worst-case time complexity of \$\star\$ is the fastest wins.

The parameter \$n\$ for the time complexity is \$s(M) + s(N)\$, where \$s\$ is defined as follows:

  • \$s(0) = s(-1) = 0\$.
  • For every integer \$D > 0\$, \$s(D) = \lfloor \log_2 D \rfloor + 1\$.
  • For every integer \$D < -1\$, \$s(D) = \lfloor \log_2 (-D-1) \rfloor + 1\$.

Note that only worst-case time complexity is considered; as such, for example, \$O(n)\$ is not considered faster than \$\Theta(n)\$.

In case that multiple submissions are tied, the earliest submission wins.

Notes and Rules

Note that each bijection \$i\$ induces \$\star\$ uniquely. As such, your submission must specify your choice of \$i\$.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ How would you score built-ins (e.g. for arithmetic operations on integers, int to string, ...)? O(1), the complexity of the languages implementation or the complexity of the best known algorithm? \$\endgroup\$ Commented Sep 20, 2023 at 9:56
  • 1
    \$\begingroup\$ Additionally, I'd suggest having something else other than code-length as the tie breaker, according to Using shortest code as a tie-breaking winning criterion in code-challenge questions \$\endgroup\$ Commented Sep 21, 2023 at 10:52
  • \$\begingroup\$ I thought of an interesting solution, so I removed my comments regarding interesting solutions \$\endgroup\$ Commented Sep 22, 2023 at 11:54
  • \$\begingroup\$ Is O(1) possible on word-RAM model? \$\endgroup\$ Commented Oct 8, 2023 at 9:08
  • \$\begingroup\$ @l4m2 it depends on what operators you allow, but O(n) is definitely possible \$\endgroup\$ Commented Oct 8, 2023 at 10:37
2
\$\begingroup\$

Find the outcome of a Cortex Prime dice roll

\$\endgroup\$
1
  • \$\begingroup\$ In my opinion the challenge is simple enough that including the edge cases of not enough eligible dice may add some interesting golfing. \$\endgroup\$ Commented Jan 29 at 18:42
1
\$\begingroup\$

I've Got The Key, I've Got The Secret

A cryptography challenge in 2 parts.

Part 1

Implement a pair of programs in any language (the two programs could be in different languages if you wanted) to encode and decode a string of plaintext.

Input and Output

The encoder must take the plaintext (and an optional key) and return an encoded string. The decoder must take the cyphertext (and an optional key) and return the plaintext exactly as it was given to the encoder.

Restrictions

  • The encoding and decoding code must be entirely implemented in the language - no libraries or cryptography functions may be used.
  • The code (encoder+decoder) cannot be longer than 1024 characters.

Part 2

Implement programs (multiple programs per answer, one answer per entrant) which crack your opponents encryption algorithms.

Input

The cyphertext.

Output

The plaintext that generated the ciphertext.

Scoring

I will upvote all answers to part 1 which have working encryption and have obviously made an attempt at golfing their answer.

In order to be eligible to win, an entrant will have to have taken part in both parts of the question. Overall score will be (length of shortest program that cracks your code-(length of encoder+length of decoder)). Highest score wins and winning entrant's entries will be accepted on both questions.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ The obvious place for this to fall flat on its face is if someone is able to implement AES or something similar within the 1024 character restriction. \$\endgroup\$ Commented Jun 13, 2012 at 13:06
  • 1
    \$\begingroup\$ Probably better if the methods of the part one programs are disclosed in non-obfuscated language, though with the short length restriction this may not be necessary. \$\endgroup\$ Commented Jun 13, 2012 at 15:23
  • 3
    \$\begingroup\$ Forget AES: RSA is easily doable. That aside, you need to define "crack" in part 2. \$\endgroup\$ Commented Jun 13, 2012 at 15:35
  • 1
    \$\begingroup\$ Also, it's not clear whether "optional key" means that it's optional to make the algorithm unkeyed (doesn't make much sense, I admit) or optional to supply it, in which case it uses a default key. \$\endgroup\$ Commented Jun 13, 2012 at 15:42
  • 1
    \$\begingroup\$ @PeterTaylor I just put optional in to leave it up to the implementer whether or not they wanted to have the key input or hard-coded (or use no key). I'd have thought everyone would have the key input into their program, but I didn't want anyone to feel forced into it by the spec. Hmm, if RSA is doable within the character restriction I'll end up with a load of unbreakable codes which would make for a pretty crap part 2. By crack I meant cyphertext goes in, some time later plaintext comes out. Would restricting the character count further help, or is this question beyond help? \$\endgroup\$ Commented Jun 13, 2012 at 16:05
  • 3
    \$\begingroup\$ On that definition of crack, I can brute force for the length of the decoder plus a few bytes to iterate over all keys of the right length and some heuristics to check plausibility of the plaintext. The brute force cracker might even be shorter than the decoder if the decoder wasn't written in GolfScript... I think this question may be beyond help. \$\endgroup\$ Commented Jun 13, 2012 at 16:28
  • 3
    \$\begingroup\$ @PeterTaylor Okay, thanks. I like the 'build your own - knock everyone else's down' aspect of this question though. I'll have to find another area where it could apply. \$\endgroup\$ Commented Jun 13, 2012 at 16:34
  • 2
    \$\begingroup\$ @Gareth I too like the competitive nature of this idea. I'm looking forward to a question with this plan in mind! \$\endgroup\$ Commented Jun 13, 2012 at 19:31
  • 2
    \$\begingroup\$ I think it would be better to split this into a "cops" post and a "robbers" post. \$\endgroup\$ Commented Feb 16, 2017 at 9:46
  • 1
    \$\begingroup\$ @wizzwizz4 Wow, this is another blast from the past. I think this pre-dates the cops-and-robbers tag. I always seem to be ahead of my time. :-) \$\endgroup\$ Commented Feb 16, 2017 at 9:49
1
50 51
52
53 54
167

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.