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

5038 Answers 5038

1
27 28
29
30 31
168
3
\$\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
3
\$\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
3
\$\begingroup\$

Squared Squares

\$\endgroup\$
0
3
\$\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
3
\$\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
3
\$\begingroup\$

Identify Redundant Regex

\$\endgroup\$
4
  • \$\begingroup\$ While the table looks nice, I think it would be good to include the test cases in an easily copyable format as well. Assuming I am understanding correctly, this essentially boils down to checking if any string of the input split by |s is a substring of any other string? That doesn't appear to be a duplicate, but there are some related challenges (example). \$\endgroup\$ Commented Oct 22, 2025 at 19:11
  • 1
    \$\begingroup\$ @FryAmTheEggman (1) I've included a copyable version of the test cases. (2) I believe you're correct. \$\endgroup\$ Commented Oct 22, 2025 at 19:28
  • \$\begingroup\$ Is this equivalent to "is any string a substring of another"? \$\endgroup\$ Commented Oct 23, 2025 at 0:19
  • \$\begingroup\$ @xnor I believe you're correct. \$\endgroup\$ Commented Oct 24, 2025 at 0:03
3
\$\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
3
\$\begingroup\$

Translate BBCode into HTML

\$\endgroup\$
6
  • 1
    \$\begingroup\$ I'd like to see some more nested test-cases, including cases to test that [code] tags escape their contents. \$\endgroup\$ Commented Jan 28 at 11:06
  • \$\begingroup\$ @Themoonisacheese Done. Would appreciate a second eye to make sure my described test cases are all correct \$\endgroup\$ Commented Jan 28 at 15:54
  • 1
    \$\begingroup\$ much better. i'm not sure about the wrong order test, or as a matter of fact about the "mismastched order" rule in general, because [b][i]a[/b][/i] can ambiguously be a correct [b] tag with a garbage unclosed [i] tag inside it, in which case the output would be <strong> [i] a </strong> [/i]. I'm not sure what you should do about this, because both would technically be "correct". you can keep the rule as-is (maybe specify it a bit more), to be clear, but I don't know if you should, because that is a significant step in complexity. an option could be to allow undefined behavior. \$\endgroup\$ Commented Jan 28 at 16:20
  • \$\begingroup\$ Yeah I'll think about allowing undefined behavior \$\endgroup\$ Commented Jan 28 at 18:03
  • 1
    \$\begingroup\$ I just changed it so that inputs are always properly nesting, so no need to define undefinedness :P \$\endgroup\$ Commented Jan 28 at 20:21
  • 1
    \$\begingroup\$ yeah that's better, LGTM \$\endgroup\$ Commented Jan 28 at 21:18
3
\$\begingroup\$

Sort the Test Tubes

\$\endgroup\$
8
  • \$\begingroup\$ i'm not really sure about these scoring rules. all it takes is 1 person finding the optimal output, then it will probably be shorter to do kolmogorov-complexity on that output instead of computing it at runtime. \$\endgroup\$ Commented Feb 4 at 9:30
  • \$\begingroup\$ Idea was to suggest a challenge similar to this question : codegolf.stackexchange.com/questions/26232/… 15x15 should be too hard to brute force, so it's about trying to be creative and to find the most optimal solution (eg: technically, this mean finding the best heuristic). Do you have other scoring rules in mind ? I think this puzzle is interesting as it's not fully solved (as with all NP-hard puzzles) that why I posted it here. \$\endgroup\$ Commented Feb 4 at 9:36
  • \$\begingroup\$ I might have misread. You should probably clarify that a solution is expected to solve any solvable puzzle, but will be scored on a test-battery (which I strongly suggest you make much, much larger than n=12). the challenge you linked contains 100,000 test cases. \$\endgroup\$ Commented Feb 4 at 9:55
  • \$\begingroup\$ unrelated, but our defaults for IO are much more permissive than the formats you describe. You're free to impose such a format if you want, but i don't believe it serves the challenge. suggest you relax the formats like "input: the board to solve in a convenient format, output: pairs of tubes", our loopholes forbidden by default generally take care of trying to define an input format that trivialize the challenge (and finding a new loophole is considered a dick move). \$\endgroup\$ Commented Feb 4 at 9:59
  • \$\begingroup\$ Thanks for your suggestions. I have relaxed the input/output section. Battery test : the one I gave are manually crafted (and it take lot of time). I currently don't have an automatic way to create test cases and make sure they are solvable. I will try to improve this. \$\endgroup\$ Commented Feb 4 at 10:28
  • \$\begingroup\$ that's already much better. someone will inevitably ask whether or not we're allowed to substitue 0123456789abcdef for another encoding, such as ints, for both the colors and the tubes? \$\endgroup\$ Commented Feb 4 at 10:52
  • 2
    \$\begingroup\$ i thing hex is fine for the challenge text, but in some languages i'd be easier if you are allowed to not bother with it and use ints directly. there is much less consensus in either direction, but someone will definitely ask whether or not they can do that. \$\endgroup\$ Commented Feb 4 at 11:19
  • 1
    \$\begingroup\$ I suggest you simply use A-Z for ball colors and forget about hex numbers. Since number base is irrelevant to this challenge and writing using hex digits can be confusing to readers. \$\endgroup\$ Commented Feb 6 at 12:53
3
\$\begingroup\$

Unicode braille to block octant conversion

tags: code-golf, unicode

(Note: I would not host this challenge by myself, but I leave an idea here just in case someone is interested and wants to host it.)

This comes from a feature request post in the Cascadia font project:

I believe an external utility could even replace Braille with Octants on the fly, making it possible to pipe existing apps using Braille without modifying them. This makes the implementation of octants even more interesting[…]

Unicode 16.0 has introduced so-called "Block Octant" characters in the "Symbols for Legacy Computing Supplement" block. The "octants" are semigraphic characters, each being a matrix of 2 × 4 pixels. The dimension of the pixel matrix is the same as the braille characters in Unicode.

The conversion table:

U+2800 [⠀] ↔  U+00A0 [ ]
U+2801 [⠁] ↔ U+1CEA8 [𜺨]  U+284E [⡎] ↔ U+1CD49 [𜵉]  U+28B9 [⢹] ↔ U+1CD98 [𜶘]
U+2808 [⠈] ↔ U+1CEAB [𜺫]  U+284F [⡏] ↔ U+1CD4A [𜵊]  U+28B2 [⢲] ↔ U+1CD99 [𜶙]
U+2809 [⠉] ↔ U+1FB82 [🮂]  U+2854 [⡔] ↔ U+1CD4B [𜵋]  U+28B3 [⢳] ↔ U+1CD9A [𜶚]
U+2802 [⠂] ↔ U+1CD00 [𜴀]  U+2855 [⡕] ↔ U+1CD4C [𜵌]  U+28BA [⢺] ↔ U+1CD9B [𜶛]
U+2803 [⠃] ↔  U+2598 [▘]  U+285C [⡜] ↔  U+259E [▞]  U+28BB [⢻] ↔  U+259C [▜]
U+280A [⠊] ↔ U+1CD01 [𜴁]  U+285D [⡝] ↔ U+1CD4D [𜵍]  U+28A4 [⢤] ↔ U+1CD9C [𜶜]
U+280B [⠋] ↔ U+1CD02 [𜴂]  U+2856 [⡖] ↔ U+1CD4E [𜵎]  U+28A5 [⢥] ↔ U+1CD9D [𜶝]
U+2810 [⠐] ↔ U+1CD03 [𜴃]  U+2857 [⡗] ↔ U+1CD4F [𜵏]  U+28AC [⢬] ↔ U+1CD9E [𜶞]
U+2811 [⠑] ↔ U+1CD04 [𜴄]  U+285E [⡞] ↔ U+1CD50 [𜵐]  U+28AD [⢭] ↔ U+1CD9F [𜶟]
U+2818 [⠘] ↔  U+259D [▝]  U+285F [⡟] ↔  U+259B [▛]  U+28A6 [⢦] ↔ U+1CDA0 [𜶠]
U+2819 [⠙] ↔ U+1CD05 [𜴅]  U+2860 [⡠] ↔ U+1CD51 [𜵑]  U+28A7 [⢧] ↔ U+1CDA1 [𜶡]
U+2812 [⠒] ↔ U+1CD06 [𜴆]  U+2861 [⡡] ↔ U+1CD52 [𜵒]  U+28AE [⢮] ↔ U+1CDA2 [𜶢]
U+2813 [⠓] ↔ U+1CD07 [𜴇]  U+2868 [⡨] ↔ U+1CD53 [𜵓]  U+28AF [⢯] ↔ U+1CDA3 [𜶣]
U+281A [⠚] ↔ U+1CD08 [𜴈]  U+2869 [⡩] ↔ U+1CD54 [𜵔]  U+28B4 [⢴] ↔ U+1CDA4 [𜶤]
U+281B [⠛] ↔  U+2580 [▀]  U+2862 [⡢] ↔ U+1CD55 [𜵕]  U+28B5 [⢵] ↔ U+1CDA5 [𜶥]
U+2804 [⠄] ↔ U+1CD09 [𜴉]  U+2863 [⡣] ↔ U+1CD56 [𜵖]  U+28BC [⢼] ↔ U+1CDA6 [𜶦]
U+2805 [⠅] ↔ U+1CD0A [𜴊]  U+286A [⡪] ↔ U+1CD57 [𜵗]  U+28BD [⢽] ↔ U+1CDA7 [𜶧]
U+280C [⠌] ↔ U+1CD0B [𜴋]  U+286B [⡫] ↔ U+1CD58 [𜵘]  U+28B6 [⢶] ↔ U+1CDA8 [𜶨]
U+280D [⠍] ↔ U+1CD0C [𜴌]  U+2870 [⡰] ↔ U+1CD59 [𜵙]  U+28B7 [⢷] ↔ U+1CDA9 [𜶩]
U+2806 [⠆] ↔ U+1FBE6 [🯦]  U+2871 [⡱] ↔ U+1CD5A [𜵚]  U+28BE [⢾] ↔ U+1CDAA [𜶪]
U+2807 [⠇] ↔ U+1CD0D [𜴍]  U+2878 [⡸] ↔ U+1CD5B [𜵛]  U+28BF [⢿] ↔ U+1CDAB [𜶫]
U+280E [⠎] ↔ U+1CD0E [𜴎]  U+2879 [⡹] ↔ U+1CD5C [𜵜]  U+28C0 [⣀] ↔  U+2582 [▂]
U+280F [⠏] ↔ U+1CD0F [𜴏]  U+2872 [⡲] ↔ U+1CD5D [𜵝]  U+28C1 [⣁] ↔ U+1CDAC [𜶬]
U+2814 [⠔] ↔ U+1CD10 [𜴐]  U+2873 [⡳] ↔ U+1CD5E [𜵞]  U+28C8 [⣈] ↔ U+1CDAD [𜶭]
U+2815 [⠕] ↔ U+1CD11 [𜴑]  U+287A [⡺] ↔ U+1CD5F [𜵟]  U+28C9 [⣉] ↔ U+1CDAE [𜶮]
U+281C [⠜] ↔ U+1CD12 [𜴒]  U+287B [⡻] ↔ U+1CD60 [𜵠]  U+28C2 [⣂] ↔ U+1CDAF [𜶯]
U+281D [⠝] ↔ U+1CD13 [𜴓]  U+2864 [⡤] ↔ U+1CD61 [𜵡]  U+28C3 [⣃] ↔ U+1CDB0 [𜶰]
U+2816 [⠖] ↔ U+1CD14 [𜴔]  U+2865 [⡥] ↔ U+1CD62 [𜵢]  U+28CA [⣊] ↔ U+1CDB1 [𜶱]
U+2817 [⠗] ↔ U+1CD15 [𜴕]  U+286C [⡬] ↔ U+1CD63 [𜵣]  U+28CB [⣋] ↔ U+1CDB2 [𜶲]
U+281E [⠞] ↔ U+1CD16 [𜴖]  U+286D [⡭] ↔ U+1CD64 [𜵤]  U+28D0 [⣐] ↔ U+1CDB3 [𜶳]
U+281F [⠟] ↔ U+1CD17 [𜴗]  U+2866 [⡦] ↔ U+1CD65 [𜵥]  U+28D1 [⣑] ↔ U+1CDB4 [𜶴]
U+2820 [⠠] ↔ U+1CD18 [𜴘]  U+2867 [⡧] ↔ U+1CD66 [𜵦]  U+28D8 [⣘] ↔ U+1CDB5 [𜶵]
U+2821 [⠡] ↔ U+1CD19 [𜴙]  U+286E [⡮] ↔ U+1CD67 [𜵧]  U+28D9 [⣙] ↔ U+1CDB6 [𜶶]
U+2828 [⠨] ↔ U+1CD1A [𜴚]  U+286F [⡯] ↔ U+1CD68 [𜵨]  U+28D2 [⣒] ↔ U+1CDB7 [𜶷]
U+2829 [⠩] ↔ U+1CD1B [𜴛]  U+2874 [⡴] ↔ U+1CD69 [𜵩]  U+28D3 [⣓] ↔ U+1CDB8 [𜶸]
U+2822 [⠢] ↔ U+1CD1C [𜴜]  U+2875 [⡵] ↔ U+1CD6A [𜵪]  U+28DA [⣚] ↔ U+1CDB9 [𜶹]
U+2823 [⠣] ↔ U+1CD1D [𜴝]  U+287C [⡼] ↔ U+1CD6B [𜵫]  U+28DB [⣛] ↔ U+1CDBA [𜶺]
U+282A [⠪] ↔ U+1CD1E [𜴞]  U+287D [⡽] ↔ U+1CD6C [𜵬]  U+28C4 [⣄] ↔ U+1CDBB [𜶻]
U+282B [⠫] ↔ U+1CD1F [𜴟]  U+2876 [⡶] ↔ U+1CD6D [𜵭]  U+28C5 [⣅] ↔ U+1CDBC [𜶼]
U+2830 [⠰] ↔ U+1FBE7 [🯧]  U+2877 [⡷] ↔ U+1CD6E [𜵮]  U+28CC [⣌] ↔ U+1CDBD [𜶽]
U+2831 [⠱] ↔ U+1CD20 [𜴠]  U+287E [⡾] ↔ U+1CD6F [𜵯]  U+28CD [⣍] ↔ U+1CDBE [𜶾]
U+2838 [⠸] ↔ U+1CD21 [𜴡]  U+287F [⡿] ↔ U+1CD70 [𜵰]  U+28C6 [⣆] ↔ U+1CDBF [𜶿]
U+2839 [⠹] ↔ U+1CD22 [𜴢]  U+2880 [⢀] ↔ U+1CEA0 [𜺠]  U+28C7 [⣇] ↔ U+1CDC0 [𜷀]
U+2832 [⠲] ↔ U+1CD23 [𜴣]  U+2881 [⢁] ↔ U+1CD71 [𜵱]  U+28CE [⣎] ↔ U+1CDC1 [𜷁]
U+2833 [⠳] ↔ U+1CD24 [𜴤]  U+2888 [⢈] ↔ U+1CD72 [𜵲]  U+28CF [⣏] ↔ U+1CDC2 [𜷂]
U+283A [⠺] ↔ U+1CD25 [𜴥]  U+2889 [⢉] ↔ U+1CD73 [𜵳]  U+28D4 [⣔] ↔ U+1CDC3 [𜷃]
U+283B [⠻] ↔ U+1CD26 [𜴦]  U+2882 [⢂] ↔ U+1CD74 [𜵴]  U+28D5 [⣕] ↔ U+1CDC4 [𜷄]
U+2824 [⠤] ↔ U+1CD27 [𜴧]  U+2883 [⢃] ↔ U+1CD75 [𜵵]  U+28DC [⣜] ↔ U+1CDC5 [𜷅]
U+2825 [⠥] ↔ U+1CD28 [𜴨]  U+288A [⢊] ↔ U+1CD76 [𜵶]  U+28DD [⣝] ↔ U+1CDC6 [𜷆]
U+282C [⠬] ↔ U+1CD29 [𜴩]  U+288B [⢋] ↔ U+1CD77 [𜵷]  U+28D6 [⣖] ↔ U+1CDC7 [𜷇]
U+282D [⠭] ↔ U+1CD2A [𜴪]  U+2890 [⢐] ↔ U+1CD78 [𜵸]  U+28D7 [⣗] ↔ U+1CDC8 [𜷈]
U+2826 [⠦] ↔ U+1CD2B [𜴫]  U+2891 [⢑] ↔ U+1CD79 [𜵹]  U+28DE [⣞] ↔ U+1CDC9 [𜷉]
U+2827 [⠧] ↔ U+1CD2C [𜴬]  U+2898 [⢘] ↔ U+1CD7A [𜵺]  U+28DF [⣟] ↔ U+1CDCA [𜷊]
U+282E [⠮] ↔ U+1CD2D [𜴭]  U+2899 [⢙] ↔ U+1CD7B [𜵻]  U+28E0 [⣠] ↔ U+1CDCB [𜷋]
U+282F [⠯] ↔ U+1CD2E [𜴮]  U+2892 [⢒] ↔ U+1CD7C [𜵼]  U+28E1 [⣡] ↔ U+1CDCC [𜷌]
U+2834 [⠴] ↔ U+1CD2F [𜴯]  U+2893 [⢓] ↔ U+1CD7D [𜵽]  U+28E8 [⣨] ↔ U+1CDCD [𜷍]
U+2835 [⠵] ↔ U+1CD30 [𜴰]  U+289A [⢚] ↔ U+1CD7E [𜵾]  U+28E9 [⣩] ↔ U+1CDCE [𜷎]
U+283C [⠼] ↔ U+1CD31 [𜴱]  U+289B [⢛] ↔ U+1CD7F [𜵿]  U+28E2 [⣢] ↔ U+1CDCF [𜷏]
U+283D [⠽] ↔ U+1CD32 [𜴲]  U+2884 [⢄] ↔ U+1CD80 [𜶀]  U+28E3 [⣣] ↔ U+1CDD0 [𜷐]
U+2836 [⠶] ↔ U+1CD33 [𜴳]  U+2885 [⢅] ↔ U+1CD81 [𜶁]  U+28EA [⣪] ↔ U+1CDD1 [𜷑]
U+2837 [⠷] ↔ U+1CD34 [𜴴]  U+288C [⢌] ↔ U+1CD82 [𜶂]  U+28EB [⣫] ↔ U+1CDD2 [𜷒]
U+283E [⠾] ↔ U+1CD35 [𜴵]  U+288D [⢍] ↔ U+1CD83 [𜶃]  U+28F0 [⣰] ↔ U+1CDD3 [𜷓]
U+283F [⠿] ↔ U+1FB85 [🮅]  U+2886 [⢆] ↔ U+1CD84 [𜶄]  U+28F1 [⣱] ↔ U+1CDD4 [𜷔]
U+2840 [⡀] ↔ U+1CEA3 [𜺣]  U+2887 [⢇] ↔ U+1CD85 [𜶅]  U+28F8 [⣸] ↔ U+1CDD5 [𜷕]
U+2841 [⡁] ↔ U+1CD36 [𜴶]  U+288E [⢎] ↔ U+1CD86 [𜶆]  U+28F9 [⣹] ↔ U+1CDD6 [𜷖]
U+2848 [⡈] ↔ U+1CD37 [𜴷]  U+288F [⢏] ↔ U+1CD87 [𜶇]  U+28F2 [⣲] ↔ U+1CDD7 [𜷗]
U+2849 [⡉] ↔ U+1CD38 [𜴸]  U+2894 [⢔] ↔ U+1CD88 [𜶈]  U+28F3 [⣳] ↔ U+1CDD8 [𜷘]
U+2842 [⡂] ↔ U+1CD39 [𜴹]  U+2895 [⢕] ↔ U+1CD89 [𜶉]  U+28FA [⣺] ↔ U+1CDD9 [𜷙]
U+2843 [⡃] ↔ U+1CD3A [𜴺]  U+289C [⢜] ↔ U+1CD8A [𜶊]  U+28FB [⣻] ↔ U+1CDDA [𜷚]
U+284A [⡊] ↔ U+1CD3B [𜴻]  U+289D [⢝] ↔ U+1CD8B [𜶋]  U+28E4 [⣤] ↔  U+2584 [▄]
U+284B [⡋] ↔ U+1CD3C [𜴼]  U+2896 [⢖] ↔ U+1CD8C [𜶌]  U+28E5 [⣥] ↔ U+1CDDB [𜷛]
U+2850 [⡐] ↔ U+1CD3D [𜴽]  U+2897 [⢗] ↔ U+1CD8D [𜶍]  U+28EC [⣬] ↔ U+1CDDC [𜷜]
U+2851 [⡑] ↔ U+1CD3E [𜴾]  U+289E [⢞] ↔ U+1CD8E [𜶎]  U+28ED [⣭] ↔ U+1CDDD [𜷝]
U+2858 [⡘] ↔ U+1CD3F [𜴿]  U+289F [⢟] ↔ U+1CD8F [𜶏]  U+28E6 [⣦] ↔ U+1CDDE [𜷞]
U+2859 [⡙] ↔ U+1CD40 [𜵀]  U+28A0 [⢠] ↔  U+2597 [▗]  U+28E7 [⣧] ↔  U+2599 [▙]
U+2852 [⡒] ↔ U+1CD41 [𜵁]  U+28A1 [⢡] ↔ U+1CD90 [𜶐]  U+28EE [⣮] ↔ U+1CDDF [𜷟]
U+2853 [⡓] ↔ U+1CD42 [𜵂]  U+28A8 [⢨] ↔ U+1CD91 [𜶑]  U+28EF [⣯] ↔ U+1CDE0 [𜷠]
U+285A [⡚] ↔ U+1CD43 [𜵃]  U+28A9 [⢩] ↔ U+1CD92 [𜶒]  U+28F4 [⣴] ↔ U+1CDE1 [𜷡]
U+285B [⡛] ↔ U+1CD44 [𜵄]  U+28A2 [⢢] ↔ U+1CD93 [𜶓]  U+28F5 [⣵] ↔ U+1CDE2 [𜷢]
U+2844 [⡄] ↔  U+2596 [▖]  U+28A3 [⢣] ↔  U+259A [▚]  U+28FC [⣼] ↔  U+259F [▟]
U+2845 [⡅] ↔ U+1CD45 [𜵅]  U+28AA [⢪] ↔ U+1CD94 [𜶔]  U+28FD [⣽] ↔ U+1CDE3 [𜷣]
U+284C [⡌] ↔ U+1CD46 [𜵆]  U+28AB [⢫] ↔ U+1CD95 [𜶕]  U+28F6 [⣶] ↔ U+2586 [▆]
U+284D [⡍] ↔ U+1CD47 [𜵇]  U+28B0 [⢰] ↔ U+1CD96 [𜶖]  U+28F7 [⣷] ↔ U+1CDE4 [𜷤]
U+2846 [⡆] ↔ U+1CD48 [𜵈]  U+28B1 [⢱] ↔ U+1CD97 [𜶗]  U+28FE [⣾] ↔ U+1CDE5 [𜷥]
U+2847 [⡇] ↔  U+258C [▌]  U+28B8 [⢸] ↔  U+2590 [▐]  U+28FF [⣿] ↔  U+2588 [█]
\$\endgroup\$
3
\$\begingroup\$

Sort Key for Japanese Wikipedia Article

\$\endgroup\$
3
\$\begingroup\$

41 years of confusing Windows version naming

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You missed Windows 2000 and Windows 8. Maybe explain why. \$\endgroup\$ Commented Mar 26 at 4:35
  • \$\begingroup\$ @Explorer09 Thanks a lot! I added explanations in the challenge, and luckily found a mistake in my source that allowed to introduce Windows 8 back into the challenge, and found another mistake. And if i didn't want to stick to the history of Home versions, i would gladly put 2000 in place of ME \$\endgroup\$ Commented Mar 26 at 10:39
3
\$\begingroup\$

Get index of aperiodic number

\$\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
3
\$\begingroup\$

Is this a mahjong hand?


This is a first challenge of the Mahjong Riichi series. For more check here: [SoonTM]

Background

Excerpts from Wikipedia:

Mahjong is a tile-based game that was developed in the 19th century in China and has spread throughout the world since the early 20th century. [...] The game is played with a set of 144 tiles based on Chinese characters and symbols, although regional variations may omit some tiles or add unique ones. In most variations, each player begins by receiving 13 tiles. In turn, players draw and discard tiles until they complete a legal hand using the 14th drawn tile to form four melds (or sets) and a pair (eye). A player can also win with a small class of special hands.

Suited tiles are divided into three suits and each are numbered from 1 to 9. The suits are bamboos, dots, and characters. There are four identical copies of each suited tile totaling 108 tiles.

There are two different sets of honors tiles: winds and dragons. The winds are east, south, west, and north, beginning with east. The dragons are red, green, and white. [...] These tiles have no numerical sequence like the suited tiles (for example the bamboo pieces number 1 to 9). Like the suited tiles, there are four identical copies of each honors tile, for a total of 28 honors tiles.

Mahjong MPSZ tile notation uses numbers 1-9 followed by a letter to represent suits:

  • m (Man/Characters),
  • p (Pin/Dots),
  • s (Sou/Bamboo), and
  • z (Zi1/Honors).

Honors are numbered from 1 to 7 (Winds: 1 = East, 2 = South, 3 = West, 4 = North; Dragons: 5 = White, 6 = Red, 7 = Green). For example, 123m means 1, 2, and 3 of Characters.

1 - Collective term for honors in Japanese Mahjong is Jihai


Input

You will receive a string representing 14 (or more) tiles in the hand. Assume that:

  • input string is always sorted by suit (Manzu, Pinzu, Souzu, Jihai) and number,
  • multiple numbers followed by a single letter represent several tiles of the same suit (e.g. 234s is equivalent to 2s3s4s),
  • no more than 4 copies of each tile are presented in the input string.

If preferred, the input may be an array of numbers/characters instead. However, you must note how are tiles mapped in your program.

Output

Determine whether a hand is a complete hand, which has either:

  • 4 groups of 3-tile sequences, triplets or quads AND a pair,
  • 7 distinct pairs, or
  • 1 of each terminal and honor tile + 1 duplicate (Thirteen Orphans)

Return a truthy value if the hand is complete, falsey otherwise.

Test cases

123456789m55p333z => true       # Pure Straight
11m223344p234567s => true       # Pure Double Sequence
113456m44488899p => false       # (incomplete group 1)
2255m4499p11s5577z => true      # Seven Pairs
4444p113355s1144z => false      # (duplicate pair)
11123455666789p => true         # Full Flush
119m19p19s1234567z => true      # Thirteen Orphans
119m119p19s124567z => false     # (missing honor for Thirteen Orphans)
222666m444p9999s22z => true     # All Triples w/ 1 quad
111133m4444p8888s5555z => true  # Four Quads
23488s555666777z => true        # Big Three Dragons
333444666m333666777p => false   # (excess tile)
33355m456s112233z => false      # (honors cannot form sequences)

Standard loophole, I/O and rules apply.

\$\endgroup\$
2
  • \$\begingroup\$ Mostly a duplicate of this. \$\endgroup\$ Commented Apr 1 at 7:47
  • \$\begingroup\$ Ah dang, how did I not find this the first time? \$\endgroup\$ Commented Apr 1 at 8:44
2
\$\begingroup\$

Huffman Decoding

Write a programm which takes two strings as input and prints a text.


The first argument is a Huffman Tree, serialized in the following format:

  • every ascii character except ~ is always a leaf, if ~ is the first characater it is also a leaf.
  • <tree0><tree1>~ is a tree where <tree0> is the left subtree and <tree1> is the right subtree.

Example: ab~cde~~~ generates this tree:

 ┌─┴─┐
┌┴┐ ┌┴─┐
a b c ┌┴┐
      d e

where a would have the key 00, b 01, c 10, d 110 and e the key 111.


The second argument is a text that has been compressed with with the Huffman code that is defined by the first parameter. This bit-string can contain any bit sequence (also null-bytes and non-printable characters) and is not byte aligned, therefore it has been encoded with a variation of the standard Base64 encoding:

  • the characters used for the encoding are the standard base64 characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
  • the bitstring is broken up into 6-bit chunks and mapped to this characters
  • if the last chunk is smaller than 6 bits, a character with this prefix is used, and padding characters are added to the string:
  • - : the last chunk was five bits long
  • = : the last chunk was four bits long
  • =- : the last chunk was three bits long
  • == : the last chunk was two bits long
  • ==- : the last chunk was one bit long

Example:

bits:       1 1 1 1 0 1 1 0 1 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 1
chunks:    |1 1 1 1 0 1|1 0 1 0 0 1|1 1 0 1 0 1|0 0 0 1 1 0|1[0 0 0 0 0]|
characters:       9           p           1           G           g
base64:     9p1Gg==-

Your programm has to decode the text encoded in the second parameter and print it to stdout.

You have to provide your source code encoded in the way described above. The length of your encoded source code + the length of your serialized huffman tree will be the winning criterion.

TODO: example input

\$\endgroup\$
2
  • \$\begingroup\$ It would be helpful to explicitly state the 64 characters used in the encoding. I presume they're A-Za-z0-9+/ but (especially if you're expecting people to implement that part explicitly) it's best to make the problem self-contained. \$\endgroup\$ Commented Oct 8, 2012 at 16:23
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$ Commented Jun 9, 2017 at 15:30
2
\$\begingroup\$

DeCSS

It is known that the DVD Content Scrambling System can be deciphered with a rather short program (434 bytes of C, 472 bytes of Perl). Can you do better?

<< Test cases go here >>


I don't plan to include a more detailed spec, because it will just wind up duplicating some of the code. The test cases would be in the form of (key, link to data file, md5sum of the deciphered stream).

\$\endgroup\$
4
  • 3
    \$\begingroup\$ And the winning criterion is who is the first to get post from the courts? \$\endgroup\$ Commented Oct 3, 2015 at 20:18
  • 1
    \$\begingroup\$ @celtschk, I think that would be unfair. Winning criteria shouldn't really depend on where people live... \$\endgroup\$ Commented Oct 10, 2015 at 20:56
  • 3
    \$\begingroup\$ I think you should at least explain the general concept of the spec. \$\endgroup\$ Commented Aug 2, 2016 at 22:53
  • 1
    \$\begingroup\$ This actually sounds interesting. @PeterTaylor Perhaps you could use (and link to) Charles Hannum's explanation of the algorithm and post this. (It would be fun to have it as a popularity contest for a program that looks like it's nothing DeCSS related, or a program that furthers the gallery's point about the text vs source code arbitrary distinction - but I don't know if popularity contests are popular any more!) \$\endgroup\$ Commented Jun 25, 2018 at 8:25
2
\$\begingroup\$

Code golfing problem: Surface classification

The task: Given a surface-word reply with the classification of what surface it is.

Example 1: Input: aba'b' ----> Output: 1T

Example 2: Input: aabcb'c' ----> Output: 3P

Bounds on the problem: Since there are only 26 letters, there will never be more than that many labels. Additionally output should be in the form S,nT,mP for n,m positive integers.

Background: In the study of algebraic topology students are often presented with diagrams such as the one below. The represent instructions for how to assemble a surface. The assembly is prescribed as: if there are two edges labeled with the letter x then glue them together so that the arrows point the same direction. To make our job easy, topologists have discovered an algorithmic way to classify surfaces using 'words' assembled from these 'plane gluing-diagrams'.

enter image description here Choosing a corner arbitrarily (top right) and orientation (ccw) we read off the labels on the edges where an inverse appears wherever the arrow points against the orientation. In this case the 'word' that represents this plane model is given as abab.

A surface word is a string that contains the letters a,b,...,@ up to some letter @ and each letter is contained in it exactly twice. In the two occurrences of each letter: 0, 1, or 2 of them may be postfixed by a ' which I am considering using to represent 'inverse' (opposite orientation).

If in a surface word all letters appear twice: once without the ' and once with it (f.ex. ba'b'a) then we say that the surface the word represents is orientable. If a surface is orientable then it is necessarily the direct sum of n Tori for some non-negative integer n. If this condition doesn't hold (like in aab'b) then the surface represented is non-orientable: in this case it is the direct sum of m Projective Planes for some positive integer m.

Once you have found out if the reduced word is orientable or not, the final answer is given as follows. If orientable and number of unique letters in the reduced word is 1 then output should be S. Otherwise if the number of unique letters in an orientable word is n (it will be even) then the output should be sT where s = n/2. If the word is non-orientable then the output should be mP where m is the number of distinct letters in the reduced word.

The goal is to take as input some surface word, reduce it via reduction rules 1-6 and then classify it as a sphere, some number of connected tori, or some number of connected projective planes. Here are the 6 reduction rules where ~ represents 'reduces to':

Let M,A,B,C,D be surface words, x be a single letter, and juxtaposition represents concatenation:

  1. Cycle Rule: If M = AB then M ~ BA
  2. Flip Rule: M ~ M'
  3. Sphere Rule: Axx'B ~ AB
  4. Block Rule: ABC ~ ADC if B is a surface word and B ~ D by 1 or 2
  5. Cylinder Rule: If M = AxBCx'D, then M ~ AxCBx'D
  6. Möbius Rule: If M = AxBxC then M ~ AxxB'C ~ AB'xxC

I am looking for input on:

  • should this be code-golf or programming-challenge?
  • how would scoring work?
  • ???

If I feel satisfied with the question in a few days I'll post it to the site.

\$\endgroup\$
5
  • \$\begingroup\$ If, for each input, there is only one correct output, then it should probably be code-golf. The scoring criteria would then be source code length. \$\endgroup\$ Commented Jun 8, 2013 at 14:33
  • \$\begingroup\$ Yes, this is the case. In general however there is not a unique series of applications of the reduction rules for any given instance. \$\endgroup\$ Commented Jun 8, 2013 at 16:21
  • \$\begingroup\$ I don't think the order of explanation is correct. You should explain reduction before talking about "the reduced word". And "reduce it via reduction rules" doesn't entirely make sense, because the rules are presented as equivalences rather than reductions, and most of them don't have a "natural" direction. \$\endgroup\$ Commented Jun 10, 2013 at 8:49
  • \$\begingroup\$ It's also occurred to me that you haven't defined the notation M'. Does it just consist of toggling the orientation of each token, or does it also reverse the entire string? And do you have test cases which between them force implementation of all of the reduction rules? \$\endgroup\$ Commented Jun 11, 2013 at 8:32
  • \$\begingroup\$ Good call on the string inverse, yes you have the right idea and I will make it clear. I have a lot of test cases from when I did a number of these computations by hand in a university course and (anecdotal experience) I am pretty sure that it is possible to force the use of all the reduction rules (except maybe 4 which is really just a meta-rule for convenience when doing proofs). Additionally you have alerted me to some concerns regarding the form of the proper output: it's definitely underspecified. I'll put some work into this today. \$\endgroup\$ Commented Jun 11, 2013 at 14:04
2
\$\begingroup\$

Fastest Code: checking if interval pairs overlap

Given an unsorted input of many interval pairs (50+), write the fastest algorithm to determine if they do not overlap.

An interval pair is said to overlap if interval x and interval y are overlapping.

Example input 1:
interval x , interval y

10-25, 50-60
10-15, 25-60

Output:
Can be in any true false format.

false (They overlap)

reasoning:

a.x overlaps b.x
a.y overlaps b.y

Example input 2:

10-25, 50-60
20-30, 25-30

Output:

true (they do not overlap)

reasoning:

a.x overlaps b.x
a.y does not overlap b.y

Scoring:

[not sure...]
brute force gives a worst case n^2 runtime
\$\endgroup\$
4
  • 1
    \$\begingroup\$ It's hard to understand what the program is supposed to do. It's better to give three separate self-contained test cases than to mix them together with extra identifiers which won't be in the actual input. But if I understand correctly, there's nothing difficult here at all. It's just interval overlap testing (two ifs) done twice for no obvious reason. \$\endgroup\$ Commented Jul 5, 2013 at 19:45
  • \$\begingroup\$ The problem is that there will be a very large input. I'm thinking > 50 lines. \$\endgroup\$ Commented Jul 5, 2013 at 20:50
  • \$\begingroup\$ I'm not sure whether or not to score it based on time, or worst case runtime. \$\endgroup\$ Commented Jul 5, 2013 at 20:59
  • 1
    \$\begingroup\$ Instead of asking for overlap, ask for disjoint: "Check if a family of intervals is disjoint". I also think it would be more interesting if you give intervals in interval notation but I you should at least specify whether or not the endpoints are included. \$\endgroup\$ Commented Dec 21, 2013 at 7:41
2
\$\begingroup\$

Business Card Ray Tracer

I have no idea how to create a good code golf question!

See this description of a ray tracer with source code that fits on a business card. The author stopped when the code size was 1337 bytes.

http://fabiensanglard.net/rayTracing_back_of_business_card/index.php

Achieving identical output, optimise for minimum code size. Execution time is not relevant.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ I think what you have here is a straight ahead golf. All languages. You need only define the requirements. Do you want identical output or do you want "good output encompassing <list of features>"? \$\endgroup\$ Commented Oct 6, 2013 at 17:22
  • 1
    \$\begingroup\$ For a minimum feature list I'd suggest something like (1) it is ray tracer (2) supports point-like lights and shadow + ambient light (3) supports mirrored (implies reflection) and matte surfaces (3) all objects are sphere and overlaps are allowed. With no requirement for (a) anti-aliasing; (2) finite sized light sources; (c) atmosphere effect or (d) depth of field; or (e) tiling and gradients. Notice however, that the example supports at least (b), (d) and (e). \$\endgroup\$ Commented Oct 6, 2013 at 17:29
  • 1
    \$\begingroup\$ BTW--The one you linked can get a little bit more with #define Q return (R was already taken for the rand wrapper) and #define O operator. \$\endgroup\$ Commented Oct 6, 2013 at 17:33
  • 3
    \$\begingroup\$ I suggest reading the Teapot question in the sandbox Mk IV and the comments - it's not the same question, but some of the same issues are relevant, and it might give you ideas for improvements to the spec. \$\endgroup\$ Commented Oct 6, 2013 at 22:48
  • \$\begingroup\$ Yes. Read the teapot question for guidance. Ultimately I decided that one was too big, but we did get into some pertinent details. \$\endgroup\$ Commented Dec 1, 2013 at 9:48
  • \$\begingroup\$ This sandbox post has had little activity in a while and little positive reception from the community. Please improve / edit it or delete it to help us clean up the sandbox. \$\endgroup\$ Commented Jun 9, 2017 at 15:32
2
\$\begingroup\$

Countdown: Federal Holidays in the United States

Inspired by this question:

Christmas Countdown

Write a program or script that will countdown to the nearest U.S. federal holiday, at any given time, and will switch the display to an appropriate greeting during each holiday.

The following holidays must be tracked, and announced:

Holiday                         Date                    Greeting
==========================================================================================
New Year's Day                  Jan. 1                  Happy New Year!
Martin Luther King, Jr. Day     3rd Mon. in Jan.        Happy Martin Luther King, Jr. Day!
President's Day                 3rd Mon. in Feb.        Happy President's Day!
Memorial Day                    Last Mon. in May        Happy Memorial Day!
Independence Day                Jul. 4                  Happy Independence Day!
Labor Day                       First Mon. in Sept.     Happy Labor Day!
Columbus Day                    2nd Mon. in Oct.        Happy Columbus Day!
Veterans Day                    Nov. 11                 Happy Veterans Day!
Thanksgiving                    4th Thu. in Nov.        Happy Thanksgiving!
Christmas                       Dec. 25                 Merry Christmas!

The strings listed under "Holiday" and "Greeting" are all free. Shortcuts like "Merry X-mas!" or "Happy 4th of July" will count against you - the full and proper holiday names are free, so there's no good reason not to use them.

The following strings are also free, only when used as a label for time units or in advertising the next upcoming holiday:

days
hours
minutes
seconds
milliseconds
until
time

On any given non-holiday, the program must show a count-down timer which displays time remaining at least down to the second, and updates the display with an accurate value (according to the system clock) at least once per second. Time remaining until a holiday must be counted as the time until midnight (00:00:00) on that day.

How the days, hours, minutes, and seconds (and milliseconds, if you choose) are displayed is up to you, so long as all mandatory items are present and it is clear which numbers represent which value. Again, the strings defining units of time are free so there's no really good reason not to use them. (Though you won't be penalized for not using these strings, so long as it is still unambiguous which time units are which.) The program should also make apparent which holiday is being counted down towards.

On any given holiday, the program must cease displaying the countdown timer and instead display the appropriate greeting for that holiday from 00:00:00 until 23:59:59.

After a holiday is over, at 00:00:00 the next day, the holiday greeting must go away and be replaced with the countdown timer for the next holiday.

Answers must include:

  • Name of language
  • Score (length of golfed code, minus free characters)
  • Golfed code
  • Total length of golfed code
  • Total number of free characters used
  • Un-golfed code, with descriptive comments

The program must be capable of running accurately (according to the system clock) at any time, and must be able to run indefinitely. The only limitations to this should be those imposed by the host computer or the nature of the programming language.


Are there any additions/deletions/modifications that should be made to these rules?

I'm considering changing some of the greetings, but I'm not quite sure what to.

  • "Happy Martin Luther King, Jr. Day!" is just a mouthful and feels awkward, but shortening it to "Happy MLK Day" feels weird too - any other suggestions?
  • I'm not quite sure "Memorial Day" should really be preceded by "Happy" - thoughts?
  • Any others?
\$\endgroup\$
3
  • \$\begingroup\$ I think it would be more interesting if the strings were not free, but you still required exact match. I would like to see the compression scheme used by contestants. \$\endgroup\$ Commented Dec 7, 2013 at 12:04
  • \$\begingroup\$ @JanDvorak This is meant to be code-golf, not kolmogorov-complexity. \$\endgroup\$ Commented Dec 7, 2013 at 22:11
  • \$\begingroup\$ This challenge proposal has been inactive for over a month. I would like to take ownership of the challenge and make it ready for posting. Please let me know within the next 14 days if you have any objections and would still like to finish and post this challenge yourself. \$\endgroup\$ Commented Nov 3, 2014 at 2:01
2
\$\begingroup\$

Golf a random Human Genome fragment with non-random features

A totally random genome fragment is easy enough: just spit out the letters ATCG in random order, and you're done. So let's try something a little less random and more useful to science.

Your program will:

  • Accept an argument from the user for number of base pairs (20bp-10000bp must be supported, more if you wish)

  • Accept an argument from the user for GC content. This indicates how frequently the generated sequence should contain the G and C bases as a percentage of total sequence length.

  • Include at least one complete gene in every request of 500bp or more, where a gene is defined as an otherwise random sequence that begins with a start codon triplet (ATG) and ends with the first stop codon triplet it encounters (TAG, TGA, or TAA). The distance between the start codon and the stop codon does not have to be a multiple of 3.

  • Vary gene content (the portion of the fragment that is "gene", inclusive of the gene's start and stop codons) linearly with respect to GC content (when sequence >= 500bp). At the extremes, when GC content is 0%, gene content is 10%; when GC content is 100%, gene content is 60%.

  • Output a single-strand sequence that complies with the above specs and the user's given parameters. (i.e. a single row of letters will suffice since it is trivial to deduce the complementary strand of the DNA given the sequence of one strand)

  • Calculate the actual GC content %, actual number of genes, and actual gene content % in the resulting fragment, and output a status line below the sequence conforming to the example format below. Percentages may be rounded to one decimal place. Actual values may deviate by +/- 3% from the expected outcome based on user's input.

    GC content: 42.1% | Genes: 3 | Gene content: 32.1%

Your program will not:

  • Use any Internet, library, or built-in gene sequence generation functions or databases. Roll your own.

Sufficient randomness:

  • For the purposes of this challenge, any built-in random/pseudo-random number generator function, GUID generator, well-seeded cryptographic hash function, etc. is considered an acceptable source of randomness.

What-ifs:

  • What if another start codon occurs before the stop codon? E.g. ATGXXXATGXXXXXXXXXXXXTAG. This is acceptable, but the "gene" length in this case is calculated from the most proximal start codon to the stop codon.
  • What if another stop codon occurs after a stop codon? E.g. ATGXXXXXXXXXXXXXTAGXXXXXXTAG This is also acceptable, but likewise the "gene" length is calculated from the start to the most proximal stop.
  • What if both of these things happen? E.g. ATGXXXATGXXXXXXXXXXXXTAGXXXTGA. Here again, the "most proximal" principle applies and the gene content is demarcated by the innermost start and the innermost stop.
  • Do "orphaned" start and stop codons that do not demarcate a gene count as gene content? No.

This challenge is code golf, so shortest valid code wins.

Post example output from a 500-bp request with GC content between 35% and 65%, and have fun!

\$\endgroup\$
19
  • \$\begingroup\$ "Use hardcoded fragments for anything other than the start and stop codons." - why not? Specifying criteria for what counts as enough randomness should make these useless in any case. Speaking of which, you need to specify criteria for what counts as enough randomness. \$\endgroup\$ Commented Feb 28, 2014 at 5:54
  • \$\begingroup\$ The only partial output example given flagrantly violates the spec. If the GC content is 42.1%, the gene content should be 31.05%, not 22.0%. The definition of "gene" is also imprecise: in the sequence AUGCCAUGCCUAGCUAA, which is the gene? \$\endgroup\$ Commented Feb 28, 2014 at 12:02
  • \$\begingroup\$ @PeterTaylor AUG starts the gene, then come the CCA, UGC, CUA and GCU triplets, none of which terminate the gene. Now if there were three C's instead of two, then UAA would be the terminating triplet and the whole sequence would form a gene. I agree the definition is imprecise, though. \$\endgroup\$ Commented Feb 28, 2014 at 12:11
  • \$\begingroup\$ @JanDvorak, (part of) the point of that example is that there are two AUG substrings. \$\endgroup\$ Commented Feb 28, 2014 at 12:30
  • \$\begingroup\$ Good points. I was hoping to avoid having too much text, but that came at the expense of less clarity than the challenge demands. Edit forthcoming. \$\endgroup\$ Commented Feb 28, 2014 at 13:58
  • \$\begingroup\$ Also, I've muddied the waters with RNA encoding and DNA encoding, (U vs T), which we can chalk up to a late night. \$\endgroup\$ Commented Feb 28, 2014 at 14:00
  • \$\begingroup\$ Revised accordingly, although I remain open to suggestions on how best to frame the standards for acceptable randomness. I want something that won't be exploited by answers making no effort at randomness, but that doesn't have the pain-in-the-butt factor of generating 10mb+ of data and running a Diehard test battery. \$\endgroup\$ Commented Feb 28, 2014 at 17:20
  • \$\begingroup\$ " This is acceptable, but the "gene" length in this case is calculated from the most proximal start codon to the stop codon. " - wait, what? In nature, the first one is the start codon, and the rest encode methionine. Under your scheme, methionine (which is an essential amino-acid) would be impossible to include into proteins. Your scheme would also be much harder to splice. Also, what happens to AUG substrings that are not triplet-aligned to previous AUG substrings? \$\endgroup\$ Commented Mar 1, 2014 at 9:25
  • \$\begingroup\$ In nature, the first ATG encodes the start of a protein coding region and defines a reading frame (triplet boundary), the rest encode methionine and the first triplet aligned stop codon encodes the end of the protein coding region (and no amino-acid). \$\endgroup\$ Commented Mar 1, 2014 at 9:29
  • \$\begingroup\$ As for the randomness, I'm not worried about the source of randomness (whatever native library is available is assumed to be good enough) but rather how the source of randomness is used (can we just start the sequence with a start codon and insert an end codon at just the right spot if it doesn't occur naturally sooner, then fill in with more random codons while avoiding ATG subsequences? Your "sufficient randomness" places constraints on the RNG (useless) but no constraints on how it's used (or that it needs to be used at all) \$\endgroup\$ Commented Mar 1, 2014 at 9:34
  • \$\begingroup\$ My true random number sequence generator was sitting there watching silently as I typed away the sequence ACACACACACACAC.... It's all okay. The TRNG was capable of producing something better - it just didn't really get to it. \$\endgroup\$ Commented Mar 1, 2014 at 9:38
  • 1
    \$\begingroup\$ In fact, the 3% tolerance for the CG content leaves no room for randomness when there are only 20 base pairs. I can shuffle the pairs and turn some A<->T or C<->G, but that's it. In fact, if the CG content is set to zero, the task is impossible: we want a gene content of 2 base pairs (which is itself impossible), but the start codon contains a G, and a single G in a 2bp sequence means a 5% CG content, 2% than is the limit. Not including a gene means that we are 7% under the gene content lower limit. Similarly, it's not possible to start or stop a gene with nothing but Cs and Gs. \$\endgroup\$ Commented Mar 1, 2014 at 9:45
  • \$\begingroup\$ Yeah, the 20bp starting point is a bad idea. The problem with start codons is that I considered introducing the idea of promoters and decided that would make the whole thing too complex. So in the absence of promoters there has to be some way to determine which Met is the start codon vs an amino acid and the easiest simplification is to have no Mets in the gene. Likewise, for "not triplet aligned", I'm trying to avoid having to go into explanations of frameshift mutations (even though a Frameshift% would be a cool parameter). \$\endgroup\$ Commented Mar 1, 2014 at 14:29
  • 1
    \$\begingroup\$ I am starting to think that all of these complexities should be included (this proposal stems from me noticing that most of the extant random DNA generators are pretty weak) and this should just be a popularity contest instead of a golf. Link a couple of good articles on the structure of the genetic code and let people add as many features as they wish. Making it a golf seems to be a catch-22 between too many compromises or a too-impenetrable wall of rules and conditions that will dissuade participation. \$\endgroup\$ Commented Mar 1, 2014 at 14:33
  • \$\begingroup\$ Perhaps a code-challenge where people earn x points for each complexity implemented? \$\endgroup\$ Commented Mar 2, 2014 at 5:52
2
\$\begingroup\$

DIM, the DIM Integer Machine

The DIM Integer Machine is an engine for producing integer sequences.

It has one major problem: To put it mildly, it's kind of...dim.

After producing a single number, it immediately forgets what sequence it was working on. The only thing it remembers is the last number it produced and the current direction of the search, either ascending or descending. (And of course, it remembers the methodology for finding numbers according to the commands it understands).

Consequently, the user is free to change their mind after each number by issuing a new command.

Suppose the DIM has just produced an integer square: 81

  • User inputs P and submits the input.
  • DIM understands that P is requesting the next prime number after 81
  • DIM computes and returns 83.
  • DIM forgets what it was doing.
  • User inputs O.
  • DIM understands that O is requesting the next odious number and returns 84.
  • DIM forgets what it was doing.

The DIM functions only for numbers between 1 and 1,000,000. If the DIM reaches either extreme while performing a search it will reverse direction and continue searching.

(For example: If searching in ascending order for a prime when the last number was 999,999, it will encounter 1,000,000 which is not a prime, then switch to descending order and continue searching for the "next" prime by moving downward - 999,999...999,998, etc.)

The DIM remembers the last number as 1 when it is first activated for a searching session.

This is the full list of commands that the DIM understands:

  • P - Next prime number
  • S - Next square number
  • F - Next Fibonacci number
  • O - Next odious number
  • W - Next wasteful number
  • U - Next undulating number
  • K - Next katadrome
  • R - Reverse direction immediately; the next command will proceed in the new direction

Because the DIM is so...dim, it absolutely DOES NOT precompute lookup tables of numbers in these sequences. It is far too forgetful for that to work. The DIM also has no Internet connection, so it is unable to consult the Online Encyclopedia of Integer Sequences or other such sites. It also has a sense of pride, so it does not make use of built-in Fibonacci functions or NextPrime / PrimeIndex / PrimeTest type functions.

Given the parameters it knows - a starting number, a search direction, the type of number to find - it simply computes the next number by some means other than mere data retrieval.

The DIM may accept input interactively, or from a newline-terminated text file, or from a pre-initialized array. You may not pack extraneous data other than the command sequence into the input - play fair!

This is a code golf, so least number of bytes wins. Submit your program with output results for the following search sessions:

  1. P O U R F O R U S O U R P R O W S
  2. W O R K F O R P O O R F O R K S K O O P S R O O K S F O U R W O W S
  3. P O O P O O P O O P P O O P P R O P S P R O W S P O R K S

It is assumed that you know what prime, square, and Fibonacci numbers are. A brief explanation of the other integer sequences follows.

Odious - a nonnegative number which has an odd number of 1s in its binary expansion. The first few odious numbers are 1, 2, 4, 7, 8, 11, 13, 14, 16, 19

Wasteful - a natural number that has fewer digits than the number of digits in its prime factorization (including the exponents). The first few are 4, 6, 8, 9, 12, 18, 20, 22

Undulating - has alternating digits of the form aba, abab, ababa, etc. Assume all U numbers are non-trivial, i.e. 3 digits or more. The first few: 101, 121, 131, 141, 151, 161, 171, 181, 191, 202, 212

Katadrome - A number whose hexadecimal digits are in strict descending order. The first few are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 33, 48, 49

\$\endgroup\$
4
  • \$\begingroup\$ When I post the question, I'll also include external links to MathWorld or OEIS for those who need more detail on the less familiar sequences, but the explanations above should be sufficient for most, I think. \$\endgroup\$ Commented Mar 6, 2014 at 23:28
  • \$\begingroup\$ Your definition of "undulating" isn't the one I'm familiar with, which just requires that the digits alternately increase and decrease. Also, it would be better to include expected answers for the test cases, so that submitters can use them as test cases rather than them serving just for you to say "No, this is buggy". \$\endgroup\$ Commented Mar 6, 2014 at 23:57
  • \$\begingroup\$ Yes, that's my plan, I just haven't finished double checking my results for the test cases yet. OEIS and Mathworld have the strict 2-digit definition of undulating, but I'll make sure to make the definition here more prominent so it is clear which interpretation is meant. \$\endgroup\$ Commented Mar 7, 2014 at 0:04
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$ Commented Jun 9, 2017 at 16:09
2
\$\begingroup\$

Unified format patcher

Write the shortest program that will take a patch file in the unified format from stdin and apply that patch. No external tools that do the process for you can be used.

Clarifications

  • Extra documentation about the unified format can be found here
  • All file paths will be relative
  • Only one file will be modified per patch
  • Timestamps can be ignored
  • The patch file will be valid and will apply cleanly to the file specified (it will not lie about line numbers, etc..)
  • Assume all files being patched already exist, you don't need to create/delete files

Extra

  • -35 - Take an argument that allows you to unpatch a patch

Example

/test/a.cpp

#include <iostream>
using namespace std;

int main() {
    cout << "Hello world!";
    return 0;
}

patch.txt

--- a/test/a.cpp
+++ b/test/a.cpp
@@ -1,7 +1,8 @@
 #include <iostream>
+#include <vector>
 using namespace std;

 int main() {
-    cout << "Hello world!";
+    cout << "Goodbye world!";
     return 0;
 }

Run patch

patch.exe patch.txt

/test/a.cpp

#include <iostream>
#include <vector>
using namespace std;

int main() {
    cout << "Goodbye world!";
    return 0;
}
\$\endgroup\$
8
  • \$\begingroup\$ Can the program assume that the @@ lines contain the correct line numbers? \$\endgroup\$ Commented Mar 6, 2014 at 17:52
  • \$\begingroup\$ A good explanation of the patch file format is needed. If not too long, include it in the question. Else, provide a link. \$\endgroup\$ Commented Mar 6, 2014 at 17:53
  • \$\begingroup\$ You forgot the obvious "no external tools" disclaimer. You don't want the patch $1 answer. \$\endgroup\$ Commented Mar 6, 2014 at 17:55
  • \$\begingroup\$ @ugoren thanks for the comments, I added some further clarifications. \$\endgroup\$ Commented Mar 6, 2014 at 18:38
  • \$\begingroup\$ Does "The patch file will be valid (it will not lie about line numbers)" also mean that it will apply cleanly? \$\endgroup\$ Commented Mar 6, 2014 at 19:24
  • \$\begingroup\$ @PeterTaylor yes, updated question. \$\endgroup\$ Commented Mar 6, 2014 at 19:51
  • \$\begingroup\$ "The shorted program" should say "the shortest program", but other than that I think it's ready to go. Of course, no-one's actually going to do more than filter out the lines starting -, remove the first char from each line, and parse the line-numbers to work out how to splice the resulting text in. \$\endgroup\$ Commented Mar 7, 2014 at 0:01
  • \$\begingroup\$ This sandbox post has had little activity in a while. Please improve / edit it or delete it to help us clean up the sandbox. Due to community guidelines, if you don't respond to this comment in 7 days I have permission to vote to delete this. \$\endgroup\$ Commented Jun 9, 2017 at 16:10
2
\$\begingroup\$

Efficient Testing for Armstrong Numbers

An Armstrong Number (also known by different names, including Narcissistic Number; see Wikipedia for more information) is a non-negative number (for our purposes represented in base 10) that is equal to the sum of the individual digits of the number each raised to the power of the number of digits. For example:

  1. Start with the three digit number 407.
  2. The individual digits are 4, 0, & 7.
  3. Since it is a three digit number, we raise each digit to the third power: 64 (4^3), 0 (0^3), & 343 (7^3).
  4. The sum of those values is 407 (64 + 0 + 343).
  5. Because the final sum is equal to the original number, it is an Armstrong Number.

By contrast:

  1. Start with 47.
  2. The individual digits are 4 & 7.
  3. A two digit number, so raise each digit to the second power: 16 (4^2) & 49 (7^2).
  4. The sum of those values is 65 (16 + 49).
  5. The final sum of 65 is not the original number, so it is not an Armstrong Number.

Your mission, should you decide to accept it: Write a program in any programming language (using only standard language features and libraries) implementing the most efficient algorithm possible to test the numbers from 1 through 18,446,744,073,709,551,615 (264-1) inclusive for "Armstrongness", generating a list of Armstrong Numbers, and only Armstrong Numbers, as output.

While any language is acceptable, it should be obvious that interpreted scripting languages will be at a disadvantage in the efficiency department. That being said, a superior algorithm in an interpreted scripting language can beat the pants off an inefficient algorithm in hand tuned assembly language.

Winning Criteria

The algorithm that can check all possible candidate numbers for "Armstrongness" in the least amount of time on a reference computer will be the winner. The reference computer will have the following specifications: {approximately an AMD Phenom class computer with 8 GB RAM running Windows 7 Ultimate 64 bit}

\$\endgroup\$
17
  • \$\begingroup\$ I don't know that this would belong in the (already very long, maybe too long) problem statement above, but other historical background. The class was for Fortran 77, and I was in a friendly competition with my TA to write the shortest version. I never could win that one, so I decided to write the most efficient version instead. Hence: I prefer efficiency puzzles to code golf (though code golf is fun too). \$\endgroup\$ Commented Feb 20, 2014 at 8:30
  • 1
    \$\begingroup\$ This doesn't seem to have an objective winning criterion. You do list "criteria I'll be using to judge this", but a) it mixes specification with winning criteria; b) it combines factors without indicating their weight. \$\endgroup\$ Commented Feb 20, 2014 at 11:51
  • \$\begingroup\$ The question also seems to be about twice as long as it needs to be. If you use the [link text](url) link notation you can shorten it slightly; you can also lose paragraphs by cutting the worked example and brute-force code (link to the existing question on narcissistic numbers instead); cutting the waffling about which languages you think have advantages; and simplifying the motivation. \$\endgroup\$ Commented Feb 20, 2014 at 11:57
  • \$\begingroup\$ I think efficiency problems are not well suited to code-golf. The efficiency of an algorithm depends on too many factors. You could perhaps require the lowest number of power operations. \$\endgroup\$ Commented Feb 20, 2014 at 12:43
  • \$\begingroup\$ @ugoren, 0 is easily obtained. \$\endgroup\$ Commented Feb 20, 2014 at 12:57
  • \$\begingroup\$ @PeterTaylor, You're right. Still, trying to replace a time measurement with the number of operations of a certain type sometimes helps define the problem better. \$\endgroup\$ Commented Feb 20, 2014 at 15:12
  • \$\begingroup\$ @PeterTaylor: I agree it is quite long, and will consider revisions to it. \$\endgroup\$ Commented Feb 20, 2014 at 21:43
  • \$\begingroup\$ @PeterTaylor: I'm open to better phrasing of the "objective winning criteria" but really, it is pretty objective already. One, no wrong answers allowed in the winner. Two, how efficient is the algorithm (based on the range of numbers tested and time taken to test them). For example, an algorithm that tests all numbers through 9 digits in 100 seconds is faster than an algorithm that takes 20 seconds to test all numbers through 8 digits (10 times larger interval in only 5 times the time). How might you suggest integration of this with the problem statement? \$\endgroup\$ Commented Feb 20, 2014 at 21:48
  • \$\begingroup\$ @PeterTaylor: Glad I included the disclaimer about failing eyesight, given that I searched for narcissistic numbers and came up with nothing. I either searched the wrong portion of PCG (meta) or I made a typo when spelling narcissistic. \$\endgroup\$ Commented Feb 20, 2014 at 21:49
  • \$\begingroup\$ @ugoren: efficiency may not be suited to code golf, but my understanding was that this 'forum' was about "programming puzzles" and "code golf". I certainly would consider finding a more efficient algorithm to be like solving a puzzle, though maybe I'm alone in that, in which case no biggie. \$\endgroup\$ Commented Feb 20, 2014 at 21:51
  • \$\begingroup\$ Edited the problem statement (which is still admittedly quite long, still considering other edits) by removing the final PPS paragraph and replacing the existing links as suggested. \$\endgroup\$ Commented Feb 20, 2014 at 21:59
  • 1
    \$\begingroup\$ The winning criterion is still too imprecise IMO. (NB Of the judging criteria you list, the first is part of the spec, so it's an acceptability criterion rather than a winning criterion). A genuinely objective winning criterion allows me to calculate my score before I submit my answer. \$\endgroup\$ Commented Mar 12, 2014 at 8:47
  • 1
    \$\begingroup\$ It should be much shorter in order to not discourage people from approaching your challenge. Almost all the text after the definition doesn't add anything to the challenge - beside "don't print wrong numbers" which is of course relevant. I also think that a more precise criterion should be given instead. \$\endgroup\$ Commented Mar 12, 2014 at 9:03
  • \$\begingroup\$ I've posted a "radical" update to it. I suspect the new winning criteria will not be acceptable either, since it involves a "reference computer" for final timing. Very open to suggestions on how to restate it so that a crappy algorithm on fast hardware doesn't beat an efficient algorithm on slow hardware. \$\endgroup\$ Commented Mar 12, 2014 at 20:17
  • \$\begingroup\$ The possibility that processor architecture or available memory affects the results is a tricky issue with fastest-code questions, but there isn't really a better way of comparing speed of programs than measuring on a large test case. I can at least measure how my program compares to someone else's on my computer, and know whether it's close or not. \$\endgroup\$ Commented Mar 12, 2014 at 21:23
2
\$\begingroup\$

Amino Acids Matcher

In genetics, a codon is a set of three nucleotides, the most basic form of nucleic acids. A codon "codes" (no pun intended, that's the actual term used) for a specific amino acid. Given a string of DNA, it is converted into RNA form by taking the opposite complementary pair.

DNA    RNA
A      U (T changes to U)
T      A
C      G
G      C

You will be given a String of unknown length that contains multiple codons. You must convert them to RNA form and print out the amino acid for each. See here for a chart: http://en.wikipedia.org/wiki/RNA_codon_table#RNA_codon_table


Sample Input

TACTCGGATACT

Is split into

TAC, TCG, GAT, ACT

We now change each letter to its reciprocal

AUG, AGC, CUA, UGA

And print out the amino acids

Methionine, Serine, Leucine, Stop


This would probably be

I know that this is most likely not sufficiently explained and might be too complicated. Additional, tell me if there is any incorrect information above.

\$\endgroup\$
2
  • \$\begingroup\$ So basically this is a challenge to compress a lookup table. You should probably specify that the string will be a multiple of three characters (or specify what to do otherwise); and it would seem sensible to inline the lookup table so that a) the question doesn't rely on the external page remaining intact; b) you save everyone who wants to answer the question the hassle of calculating it. \$\endgroup\$ Commented Mar 17, 2014 at 12:42
  • \$\begingroup\$ Thanks for the feedback. I'll update accordingly later today. \$\endgroup\$ Commented Mar 17, 2014 at 15:48
2
\$\begingroup\$

Find words in word square solver

On social media I often see images with letters and in them are some positive words for people to find. I challenge you to write a program that finds all words in the puzzle that matches a input dictionary. An example of such puzzle is this one:

A letter square

An ASCII representation I made of this:

XCUALOVEYKBWSNG
DUAWKCBEAUTYRJV
YOUTHFSMGNEZLPR
MHJREYWDKZLUSTJ
FSUCCESSDHEALTH
ENMQXPTIMELMSAQ
VEXPERIENCEGHBW
GHUMOURLOYMONEY
SYZPOPULARITYNA
AMKCFUNBXHUZYIX
CWIHYSHAPPINESS
HONESTYCFRIENDS
KPYJAETWPOWERQC
BTYACFREEDOMJMO
RIWINTELLIGENCE

Now I imagine we can find words horizontally, vertical and diagonal and all of the mentioned in reverse. The program must be able to take a square and a dictionary like this one and print all the matching words.

As a test case I give custom dictionary:

bar
bid
dir
dog
fad
fed
foo
god
man
mod
set
sun

And a test square:

OGFIR
DOMAN
ODBID
OPGES
OGFIR

Your code should be able to print all but the two last words in the dictionary. For diversity you should specify how the cube and the dictionary is bo be entered.

This is so shortest code wins.

\$\endgroup\$
8
  • \$\begingroup\$ What should be output? Only the matched words? Their positions? And directions? \$\endgroup\$ Commented Apr 3, 2014 at 15:47
  • \$\begingroup\$ @JanDvorak Just print the words found. Do you think coordinates and direction can be given a bonus? \$\endgroup\$ Commented Apr 3, 2014 at 15:51
  • 3
    \$\begingroup\$ Cube? I'm only seeing two dimensions. On a more general note, perhaps for questions of this sort it would be OK to assume the availability of a standard dictionary file like /usr/share/dict, and discount the characters used to access this file? What do people think? \$\endgroup\$ Commented Apr 3, 2014 at 15:55
  • \$\begingroup\$ @squeamishossifrage OMG You're right. I meant square of course :-) I think people can choose. eg. The question is open for diversity like cat square.txt dic.txt | solver now, but I'm open for change that does not discriminate. \$\endgroup\$ Commented Apr 3, 2014 at 16:03
  • 1
    \$\begingroup\$ How does the program know where the wordsearch ends and the dictionary starts? \$\endgroup\$ Commented Apr 3, 2014 at 21:39
  • \$\begingroup\$ @PeterTaylor By mistake I made the test a rectagle, but I fixed that. The length of the first line would be the number of lines in the square. Anyway how the input is done I thought should be up to the solver so that they can choose to open files, read stdin or maybe more disturebing ways to get input in... \$\endgroup\$ Commented Apr 3, 2014 at 21:47
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$ Commented Jun 9, 2017 at 16:30
  • \$\begingroup\$ @programmer5000 It only got two upvotes so I let it be. Feel free to post it if you'd like. \$\endgroup\$ Commented Jun 12, 2017 at 15:27
2
\$\begingroup\$

Collatz ...something

The Collatz conjecture states that every natural number n leads to the number 1 if the recursive function f(n) is applied to it defined as

f(n)=n/2    if n is even
    =3n+1   if n is odd

Let "ai" be the value of f applied to n recursively i times so that a0 = n , a1 = f(n) , a2 = f(f(n)) ... ai = f(ai-1)

Let A be the set {a0, a1, ..., 1}

Thus, for n=10, we get the sequence

a0 = 10 --> a1 = 5 --> a2 = 16 --> a3 = 8 --> a4 = 4 --> a5 = 2 --> a6 = 1

and the set A as A = {10,5,16,8,4,2,1}

Your task is to write a function/program that will accept a set of naturals say I. You must output a set of numbers say C such that I is a subset of the union of the sets A for all numbers in C.

Rules

  • Network access is forbidden
  • Any of the standard loopholes are forbidden
  • Your program must end in less than 200 seconds. You may assume that all the input terms are less than 2^(45); however note that the individual terms of the collatz sequence can go higher.

Input

  • List/array of naturals in I as an argument to a function
  • , or space or \n separated naturals in I on STDIN

Output

  • return a list/array/set of all naturals in C
  • print all the naturals in C separated by \n

Scoring

Your score is calculated as

( ( (10)^(number of elements in C) ) * (sum of all elements in C) ) + ceil( 100*log(total number of bytes of your code) )

log() is the natural logarithm

Lowest score wins.

Examples

Input:

I = { 16 , 32 , 40 }

Possible outputs along with the score

C=                   Score

{ 16 , 32 , 40 }     ((10)^(3))*(16 + 32 + 40) = 8000   + constant
{ 32 , 40 }          ((10)^(2))*(32 + 40)      = 7200   + constant
{ 32 , 13 }          ((10)^(2))*(32 + 13)      = 4500   + constant --> most optimal         
{ 1024 , 320 }       ((10)^(2))*(1024 + 320)   = 134400 + constant
... Infinitely many higher numbers    

where constant is ceil(100*log(code length))

In this case, the answer { 32 , 13 } is the most optimal.


Note: This is NOT code-golf even though the length of your program is considered. Please also provide a readable version.

I'm being flexible with the I/O so that the more verbose languages might get some benefit. You can write a complete program or a function or a lambda function. It is not required that your function(if you choose to write one) returns. Using a function for input while printing the output is fine if that makes the code shorter.


This will be tagged as


Sandbox feedback

  • Can anyone suggest a better title?

TODO

  • Scoring needs specific test cases. Perhaps the final score could be the average of all scores of the test cases.

  • Needs a proper title.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ The timing constraint is not reasonable unless you also provide constraints on the number and size of the inputs. For any input for which the constraint is reasonable at all, I think that the first point of the spec is unnecessary: if a counterexample exists, it's right at the edge of what fits in a 64-bit number. The second point of the spec is currently quite difficult to understand. \$\endgroup\$ Commented Apr 3, 2014 at 9:47
  • \$\begingroup\$ @PeterTaylor Is it OK now? \$\endgroup\$ Commented Apr 4, 2014 at 16:15
  • 2
    \$\begingroup\$ Looking around a bit at the standard terminology, I think that it might be best introduced with something like "Each positive integer n generates a Collatz sequence by repetition of the map f(n) = n % 2 == 0 ? n/2 : 3*n+1. Define the orbit of n as the set containing the integers in its Collatz sequence, and the orbit of a set {n_i} as the union of the individual elements' orbits. Your task is to find an optimal set under the constraint that its orbit contain a specified subset." That then leads into the example. \$\endgroup\$ Commented Apr 4, 2014 at 16:48
  • 2
    \$\begingroup\$ I'm not sure that it's justifiable to claim that for your example {I2, C5, C10} is "(not the most ideal)". Whether or not it is depends on which arrows are /2 and which are *3+1, which isn't shown in the example. It's also occurred to me, which I missed earlier, that your scoring system requires a bit more of a test suite: at present, you have no way of distinguishing between answers which get the optimal solution to one test case. And I suggest a title, based on my previous comment: "Optimal Collatz orbits". \$\endgroup\$ Commented Apr 4, 2014 at 16:52
  • 1
    \$\begingroup\$ I suggest you to add a link describing what is a collatz sequence. As a non-mathematician, I find it hard to understand. There is extra whitespaces after `` in your first code block. \$\endgroup\$ Commented Apr 4, 2014 at 17:12
  • \$\begingroup\$ @PeterTaylor Edited a lot. Are you sure it is called an orbit? I couldn't find that term anywhere. \$\endgroup\$ Commented Apr 6, 2014 at 16:39
  • 1
    \$\begingroup\$ It occurs 4 times in the Wikipedia page on the Collatz conjecture, and Google gives over 6 million hits for collatz orbit. \$\endgroup\$ Commented Apr 6, 2014 at 22:08
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$ Commented Jun 9, 2017 at 16:31
2
\$\begingroup\$

Filter out repetitive lines

Google Suggest doesn't show any results if a string contains more than 4 repetitions of a substring. More specifically, if a substring is repeated 4 times in a row, followed by the first character of that substring (i.e. abcabcabcabca or x x x x x), nothing is suggested. This rule changes slightly if the substring is all the same digit - a digit may be repeated 5 times in a row, but no more. This is probably to allow searching for ZIP codes like 22222. (This doesn't extend to strings like 1010101010, though.)

Let's simulate this behavior! Write a program that takes lines on standard input and echoes those lines back on standard output, unless the line fits the criteria for repetitiveness, in which case it's silently discarded.

Sample input:

a simple query
nananananananana
ffffgggghhhh
48719999936
abc abc abc abc asdf
xyzzzzzyx
122333444455555666666
repetitiverepetitiverepetitiverepetitive
erepetitiverepetitiverepetitiverepetitive
101010101
55555 zzzzz

Output:

a simple query
ffffgggghhhh
48719999936
repetitiverepetitiverepetitiverepetitive

(Google's behavior is actually quite a bit more complicated than this; there are a few exceptions to all of these rules, but let's just ignore those for this challenge.)


There was a similar challenge posted awhile ago (Recognizing Repetition in strings), but it was closed due to vagueness. I think the criteria proposed above are more than thorough enough.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ The current exceptions make it complicated enough to track what you're looking for: basically you're asking for grep -v ((.).+)\2{3}\1|([^0-9])\3{4}? \$\endgroup\$ Commented Apr 19, 2014 at 19:05
  • \$\begingroup\$ @PeterTaylor I would like to try to solve it without regex, though. \$\endgroup\$ Commented Apr 19, 2014 at 19:10
  • \$\begingroup\$ I had thought about regex, but I didn't think it would be that simple. Would adding more restrictions or banning regex help? \$\endgroup\$ Commented Apr 20, 2014 at 1:18
  • \$\begingroup\$ @Fraxtil, my opinion is that as a general rule if you need to ban the obvious way of doing something then you might as well just abandon the question. (With the exception, obviously, of banning libraries which are specifically designed to solve the same problem. Regex being a general tool rather than something designed for this specific problem don't fall into that exception). \$\endgroup\$ Commented Apr 21, 2014 at 8:52
  • \$\begingroup\$ @PeterTaylor, that's a good point. Maybe I'll revisit the idea later if I can find a way to make it more interesting. \$\endgroup\$ Commented Apr 21, 2014 at 18:56
  • \$\begingroup\$ I did make a decent question out of doing a basic regex problem without the use of regex (I should have, in hind sight, banned basic pattern matching as well as regexes...Bash shouldn't almost beat APL in sheer character count in a code golf). \$\endgroup\$ Commented Apr 21, 2014 at 21:06
  • \$\begingroup\$ @impinball "Bash shouldn't almost beat APL in sheer character count in a code golf" -- why? \$\endgroup\$ Commented Apr 24, 2014 at 12:53
  • \$\begingroup\$ Or at least in that context (tr is a pattern matching replace algorithm with regex like functionality). I would be a little more likely to accept Bash's builtin pattern matching expansion than tr. \$\endgroup\$ Commented Apr 25, 2014 at 21:49
2
\$\begingroup\$

Am I a Matroid?

Input:

A list I that is a subset of the powerset of E={1,2,...,n} which represents the independent sets of elements of the purported matroid M=(E,I). Note that the cardinality of the ground set may be for the purposes of this question ignored. Any elements of E that appear in none of the elements of I cannot contribute (i.e. if M=(E,I) is a matroid then M=(E union K,I) is a matroid for any set K.

Input may be in whatever list format you desire, be it as simple as no separators but spaces (using 0 for the empty set): 0 1 2 3 12 13 or as complicated as whatever list literals are in your favorite language (such as python's: [[],[1],[2],[3],[1,2],[1,3]]).

Output:

A variation on 1/0, true/false, yes/no answering the question: is M a matroid?

Definition:

M=(E,I) is a matroid if:

  1. I is not the empty set
  2. If J is in I and K is a subset of J, then K is in I
  3. If J,K are in I and |K|<|J| then there exists an element x that is in the set difference J-K such that K union {x} is in I.

There are equivalent formulations of condition 1 and 3, also there are conditions on the bases (maximal elements of I w.r.t. cardinality) that are equivalent to these. If people want I can post those too or leave them as optional research.

Examples:

I={{},{1},{2},{1,2}} is a matroid.

I={} is not a matroid because it is empty (by axiom 1).

I={{},{1},{1,3}} is not a matroid because if it has {1,3} independent then it must have {3} independent (by axiom 2).

I={{},{1},{2},{3},{1,2}} is not a matroid because if it has {1,2} and {3} independent then it must have either {1,3} or {2,3} independent (by axiom 3).

I={{}} is always a matroid, as is I=powerset([1,2,...,n]) for any n>0 as they both trivially satisfy the axioms.

Specs:

Submission is either a program taking input from standard input or command line argument or a function that takes I as input (as a string) and returns the specified binary answer. No upperbound on the size of input should be hardcoded.

I would intend for this to be a code-golf challenge.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Rather than provide alternative definitions, just link the first mention of the word matroid to the Wikipedia page. \$\endgroup\$ Commented May 5, 2014 at 11:59
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$ Commented Jun 9, 2017 at 16:38
2
\$\begingroup\$

Help Joe Bloggs with his password hash

Joe was confidently using "password1" as his main password to all his accounts until one day he received an e-mail from fBay. His account has been compromised and he must change his password immediately. Yet worse, the attacker had access to all Joe's accounts. Being an engineer, Joe thought: What if I could hash somehow my password using a keyword? I wouldn't need to remember any passwords and I would have a different one for each account.

Joe then creates an algorithm - he takes the domain name as a key and creates the password for each of his account consisting of:

1. (<consonants><vowels>)(alternating case: lower, capital, lower...)
2. <number of consonants><number of vowels>
3. <sum of consonants and vowels numbers converted to a character on US Qwerty Keyboard>

Joe then opens an account on SO to create a new code golf challenge. He uses stackoverflow as a key to generate password:

1. sTcKvRfLwAoEo - consonants and vowels in alternating case
2. 94 - 9 consonants, 4 vowels
3. 9+4=13, 1+3=4, Shift+4=$

Therefore, Joe's password for stackoverflow is: sTcKvRfLwAoEo94$

Challenge

Create a shortest function to generate a password given the rules above. The code should accept a string type parameter d and return/display the generated password.

Rules

  1. Only Latin letters from the input should be used. Any other characters should be ignored.
  2. Minimum input length is 1 letter. (guys at q.com need passwords as well!)
  3. Assume Y is a vowel
  4. If vowels or consonants are missing, use 0 accordingly. E.g. input a would result in a01!
  5. Shortest code wins

List of vowels and consonants

US qwerty keyboard

\$\endgroup\$
8
  • \$\begingroup\$ Thanks for the feedback @m.buettner. I meant to say, without using any libraries. The problem is, that people become lazy to think sometimes and just dive straight away to use Linq where a bit of thought will do \$\endgroup\$ Commented May 28, 2014 at 13:14
  • \$\begingroup\$ Well actually you can, I'm just checking now. You can do a lot of manipulations on strings without libraries. \$\endgroup\$ Commented May 28, 2014 at 13:18
  • \$\begingroup\$ Looping over string characters, concatenation work perfectly. Nevertheless, I've updated the challenge. If a function to depend on a library, it must be included in the character count. \$\endgroup\$ Commented May 28, 2014 at 13:21
  • 3
    \$\begingroup\$ 1. Strictly speaking, in .Net you don't have strings without libraries. The string keyword is syntactic sugar for a class in mscorlib. 2. As things currently stand, your rule 1 strictly prohibits something and then says what to do if you ignore that prohibition. This is illogical. It's also unclear what "that" in "please inlcude that in characters count" means. Does it mean that each submission should be a program as opposed to a code snippet? If so, state it explicitly. \$\endgroup\$ Commented May 28, 2014 at 13:32
  • \$\begingroup\$ Hmm.. I don't know how to write it the best way. mscorlib is included by default so that is permissible. I don't want the code to use other libraries as Linq as it's less fun. \$\endgroup\$ Commented May 28, 2014 at 13:47
  • \$\begingroup\$ @m.buettner I agree with you. Nevertheless, there will solutions provided in other languages as well (there always are). And I would like the authors of those solutions to think about the best approach in their language of choice without depending on libraries like Linq. \$\endgroup\$ Commented May 28, 2014 at 14:00
  • \$\begingroup\$ Does Rule 2 mean ONLY vowels/consonants to be used from input? What about symbols *@#$ etc. Depending on that answer, potentially clarify Rule 5 regarding symbol input. As for Step 3 in the hash, should that progress further, similar to my Appended Numbers game so 103 consonants and 5 vowels would follow as 103+5 = 108, 1+0+8/10+8, etc.? \$\endgroup\$ Commented Jun 4, 2014 at 2:35
  • 1
    \$\begingroup\$ @Matt, clarified - only Latin letters are used from the input. If consonants or vowels are missing, use 0 instead. The sum should progress, until it's <=9. E.g. 103 consonants, 5 vowels: 103+5=108, 1+0+8=9. Then, Shift+9='(' \$\endgroup\$ Commented Jun 18, 2014 at 10:36
1
27 28
29
30 31
168

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.