577
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29 at 13:27

4832 Answers 4832

1
12 13
14
15 16
162
4
\$\begingroup\$

Swap every two elements in the list every possible way

Posted

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the Code Golf SE! I have a few questions about your problem: 1) Should the output include the original order? Examples 2 and 3 do, but example 1 doesn't. 2) I might be mistaken, but isn't this equivalent to finding all permutations of the array? \$\endgroup\$ Commented Jul 23, 2022 at 20:13
  • \$\begingroup\$ @Adam 1) The output should include the original order only if the original order can be reached by applying every possible pair swap in some order. For example 1, the only possible swap just swaps two elements, and so only one permutation can be reached. For example 3, there is no possible swap, so the array stays the same, and for example 2, there are a lot of different possible results that happen to include the original order. 2) You are mistaken in that case. It isn't all permutations, it's slightly more complicated than that. It's a little bit of a research problem. \$\endgroup\$
    – Pavgran
    Commented Jul 25, 2022 at 12:33
4
\$\begingroup\$

IE's Extra Robust Color Parsing®

\$\endgroup\$
10
  • 1
    \$\begingroup\$ So #FFF (white in today's browsers) became #0F0F0F (very dark grey)‽ \$\endgroup\$
    – Adám
    Commented Jul 25, 2022 at 15:02
  • \$\begingroup\$ When you say output as an "a RGB color", you should clarify whether you mean the text formatted as an RGB color string, or to graphically output the color itself \$\endgroup\$ Commented Jul 25, 2022 at 15:48
  • \$\begingroup\$ @Adám So it would seem, I noticed that as well. \$\endgroup\$ Commented Jul 26, 2022 at 20:39
  • \$\begingroup\$ @thejonymyster right, poor wording on my part. Fixed. \$\endgroup\$ Commented Jul 26, 2022 at 20:39
  • \$\begingroup\$ Could you please add comments to less obvious steps in the worked out examples? (I don't get the AD0, AC0, 0E0 --> AD, AC, 0E, as the algorithm says to remove characters always from the front.) Also, I suggest adding some more test-cases (not necessarily worked out, but in a copy-friendly format). \$\endgroup\$
    – pajonk
    Commented Jul 27, 2022 at 5:27
  • \$\begingroup\$ @pajonk I added some comments, planning to add some test cases later whan I find the time. \$\endgroup\$ Commented Jul 27, 2022 at 9:57
  • \$\begingroup\$ Will IE recognize some special words like red, white? Or red is processed into #000e0d? \$\endgroup\$
    – tsh
    Commented Jul 29, 2022 at 3:17
  • \$\begingroup\$ @tsh Good point, thanks! IE probably did respect them, but for the challenge, we'll process them. Updated the rules. \$\endgroup\$ Commented Jul 29, 2022 at 7:05
  • \$\begingroup\$ I assume we just have to output the six resulting characters, and the leading # in the output is optional? \$\endgroup\$ Commented Jul 29, 2022 at 7:44
  • \$\begingroup\$ Yes, I just used that to mark the results. \$\endgroup\$ Commented Jul 29, 2022 at 9:29
4
\$\begingroup\$

Cryptic Multiplications

\$\endgroup\$
4
\$\begingroup\$

Anti-divisors of a number

\$\endgroup\$
4
\$\begingroup\$

An algorithm to find even sublime numbers

\$\endgroup\$
4
\$\begingroup\$

Use "e" or a suffix?

Background

In Māori (the indigenous language of New Zealand), to make a verb a command the verb is either preceded by "e" for example, "oma" (to run) -> "e oma", or, it's given a passive ending to make it a passive verb for example "kōrero" (to speak, talk, say, etc) -> "kōrerotia".

Besides some edge cases with intransitive verbs and different dialects, the rule is that if the verb has exactly two short vowels or one long vowel (which have macrons over the top of them like "ā") then the verb is preceded with "e" otherwise it is given a suffix.

Challenge

Your challenge is to determine whether which case a verb fits in to. If it should be preceded by "e" output a truthy value, otherwise output a falsey value.

Rules

  • You can assume that all the input will be lower case.
  • You may not take input with combining diacritics.
  • Because there are very few, if any verbs in Māori with only one short vowel, and the fact that what happens in that case depends on dialect, you don't need to handle those cases.
  • This is so the shortest answer wins.

Test cases

ako -> true
kai -> true
haere -> false
tū -> true
āwhina -> false
kōrero -> false
huri -> true

Meta

  • Thoughts on the combining diacritics rule?
  • Are there any other rules that should be added?

\$\endgroup\$
7
  • \$\begingroup\$ Maybe add a test case with a single short vowel? (Or if there are no actual mono-moraic verbs, consider including in the spec that such an input doesn't have to be considered.) \$\endgroup\$ Commented Jul 25, 2022 at 7:27
  • 1
    \$\begingroup\$ @UnrelatedString I was thinking about that, I haven't been able to find any verbs with one short vowel, but I just can't be sure that there are none so I'm not really sure what to do about it. \$\endgroup\$ Commented Jul 25, 2022 at 7:40
  • \$\begingroup\$ Fix your link! (It's the second one.) \$\endgroup\$
    – Laurel
    Commented Aug 30, 2022 at 23:26
  • \$\begingroup\$ @Laurel Ah, thanks. I'll replace it with a new one. \$\endgroup\$ Commented Aug 30, 2022 at 23:29
  • \$\begingroup\$ Tag: decision-problem \$\endgroup\$ Commented Aug 31, 2022 at 1:26
  • \$\begingroup\$ You should also probably specify that it has to be exactly two short/one long, and the cases are mutually exclusive -- e.g. say "...the verb has exactly two short vowels or two long vowels, but not both" \$\endgroup\$ Commented Aug 31, 2022 at 15:02
  • \$\begingroup\$ @Adam true, done. \$\endgroup\$ Commented Aug 31, 2022 at 20:51
4
\$\begingroup\$

Count Futoshiki row solutions

\$\endgroup\$
4
\$\begingroup\$

Is it an alphadrome?

\$\endgroup\$
4
\$\begingroup\$

MD5 Hello, World!

Posted here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Are there interesting ways of getting two files to have the same MD5 hash? I know there are some ways to add arbitrary text to files to give them the same hash, but it seems difficult to engineer the program itself to have the same hashes. \$\endgroup\$ Commented Oct 13, 2022 at 14:16
  • \$\begingroup\$ @97.100.97.109, I’m not sure. It may be interesting to see if someone can come up with a solution that is a bit smarter than including a lot of unused data. \$\endgroup\$
    – jdt
    Commented Oct 13, 2022 at 14:36
4
\$\begingroup\$

Count the shared substrings with 2 programs

\$\endgroup\$
1
  • \$\begingroup\$ incident, score 0, fermat quote \$\endgroup\$ Commented Oct 19, 2022 at 12:34
4
\$\begingroup\$

Character Insertion on Letterboards

\$\endgroup\$
3
  • \$\begingroup\$ Can we assume it's a permutation of the string? \$\endgroup\$
    – emanresu A
    Commented Oct 21, 2022 at 1:03
  • \$\begingroup\$ I think the example has a mistake, the second "B" and "A" are inserted from the right not the left. \$\endgroup\$ Commented Oct 21, 2022 at 22:57
  • \$\begingroup\$ @emanresuA I'm not sure. What do you think? It doesn't make a difference to the two algorithms I've thought of. \$\endgroup\$
    – FlipTack
    Commented Oct 22, 2022 at 14:13
4
\$\begingroup\$

"Prime" pyramid

\$\endgroup\$
4
\$\begingroup\$

Is it true? Ask Pip!

\$\endgroup\$
1
  • \$\begingroup\$ I think I'd stick to the decision-problem defaults and encourage to post non-trivial Pip solution; or post a community-wiki answer with that trivial solution to claim it. \$\endgroup\$
    – pajonk
    Commented Dec 20, 2022 at 9:21
4
\$\begingroup\$

Transpose binary numbers

The input numbers [34, 7, 109] can be represented in binary as

0100010
0000111
1101101

(one number on each line; and padding with zeroes on the left so that all the rows are the same length)

Now transpose this array:

001
101
000
001
011
110
011

Then convert each row back to decimal to get the output:

[1, 5, 0, 1, 3, 6, 3]

This is the output.


todo: write a proper spec

Is this a duplicate?

Is this interesting?

Would this be more interesting if generalised to an input base b?

\$\endgroup\$
4
\$\begingroup\$

Is it a Shift matrix?

Posted here

\$\endgroup\$
2
  • \$\begingroup\$ Are other forms of input ok? Like a rectangular matrix if my language supports it? \$\endgroup\$
    – pajonk
    Commented Jan 6, 2023 at 14:10
  • \$\begingroup\$ @pajonk oops yes thanks \$\endgroup\$
    – math scat
    Commented Jan 17, 2023 at 18:43
4
\$\begingroup\$

The dating game

The bots are looking for love. Can you help them?

The rules

The goal of this game is find the bot you have the highest comparability with. However, robots, who are inexperienced at dating are unable to tell how well a date went.

In the game, bots take turns "speed dating" some other bot. After each date, each bot chooses whether to get married or to continue dating. If both bots agree to get married both are removed from the dating pool and their compatability rank (100% is if you found the best one, 0% for the worst one) is their final score.

Bots won't be able to tell what the compatibility is, but they can compare dates. For example if bot A went on a date with bot B and C, they'll be able to tell if B or C was more compatible but not by how much.

Bot A's compatibility with B does not equal B's compatibility with A, but they are correlated.

If every bot has dated every other bot, the ordering is shuffled and any remaining bots can try again. However, everyone's final score is reduced by 25% (exponential) for every round they stay single. If a entire round ends without any new marriages the game ends and all remaining bots get a score of 0.

Example bot

class BetterThanFirst:
    """
    This bot will use its first date as a reference, then marry any bot that's better than it
    """

    def __init__(self, nrof_bots, rng): # rng is a seeded PRNG you can use, no other forms of randomness allowed
        # nrof_bots is the total number of bots playing
        self.first_date = None

    def round_finished(self, nrof_remaining_bots): # the number of bots still in the game
        pass # called if a full round finished, optional

    def date(self, other) -> bool: # Return True if you want to marry this bot, False otherwise
        if self.first_date is None:
            self.first_date = other
        else:
            return other > self.first_date

Other rules

  • No IO
  • No RNG except via the provided PRNG
  • No inspecting other bots. You are only allowed to use the >, <, <=, >=, ==, and is operators on other bots.
  • No exploiting the controller.
\$\endgroup\$
5
  • \$\begingroup\$ In what order do dates occur? Are all pairs shuffled and then date one-by-one? \$\endgroup\$ Commented Mar 6, 2023 at 9:20
  • \$\begingroup\$ Perhaps instead of __init__ and round_finished both having nrof_bots you can have __init__(self, rng) and round_started(self, nrof_bots), and then bots don't need to duplicate code to handle the number of bots. \$\endgroup\$ Commented Mar 6, 2023 at 9:22
  • \$\begingroup\$ This seems very similar to the secretary problem, other than the fact that you can choose to wait for a later round and that candidates might get married before it's your turn to date them. \$\endgroup\$ Commented Mar 6, 2023 at 9:25
  • \$\begingroup\$ @CommandMaster Yes this challenge was very much inspired by the secretary problem, but adapted enough so that the "optimal" solution is unproven, and also to make it multiplayer \$\endgroup\$ Commented Mar 6, 2023 at 11:39
  • 1
    \$\begingroup\$ @CommandMaster Bots may need to make decisions based both on the number of remaining bots and the total number of bots. \$\endgroup\$ Commented Mar 6, 2023 at 11:39
4
\$\begingroup\$

Cosine similarity

\$\endgroup\$
4
\$\begingroup\$

Zählen

Posted here

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Nice challenge, the explanation might be a bit better if you listed the numbers up to 23 or so, and then listed just the multiples of ten. This way it could be easier to extrapolate the pattern, especially if there is another pattern that is useful for golfing. \$\endgroup\$ Commented Apr 6, 2023 at 16:17
  • 2
    \$\begingroup\$ @Jacob Something like this? \$\endgroup\$ Commented Apr 6, 2023 at 16:30
  • 2
    \$\begingroup\$ You are using zwölf in the test cases and zwoelf in the description. I guess you should either fix this inconsistency or allow both fuenf/zwoelf/dreissig and fünf/zwölf/dreißig. \$\endgroup\$
    – Arnauld
    Commented Apr 7, 2023 at 12:04
  • 1
    \$\begingroup\$ @Arnauld Thank you, that was a mistake, it should be zwoelf. \$\endgroup\$ Commented Apr 7, 2023 at 14:44
4
\$\begingroup\$

Reversed squares

Given an integer n, your task is to determine whether it is a perfect square that when reversed,, is still a perfect square. You may assume n is always positive.

When numbers such as 100 (10x10) are reversed the result may have leading zeros (001) In this case, ignore the leading zeros and treat it as 1 (1x1).

Test cases

1 => True
4 => True
9 => True
441 => True
1234567654321 => True
100 => True

3 => False
25 => False
1784 => False
```
\$\endgroup\$
5
  • \$\begingroup\$ Seems like a fun challenge! But I don't quite get why you're allowing negative numbers. I'd rather let golfers assume the input is positive. \$\endgroup\$
    – Peter
    Commented Jun 2, 2023 at 17:28
  • \$\begingroup\$ (Correct me if I'm wrong) Is it always true (1+log(n))%2>1&&sqrt(n)%1==0? \$\endgroup\$
    – Dadsdy
    Commented Jun 2, 2023 at 18:34
  • \$\begingroup\$ Yup: tio.run/##fcxJDoMgGAXgfU/… \$\endgroup\$
    – Dadsdy
    Commented Jun 2, 2023 at 18:43
  • \$\begingroup\$ I’d say you should post this one now \$\endgroup\$
    – Dadsdy
    Commented Jun 14, 2023 at 18:53
  • \$\begingroup\$ @Dadsdy ok posted \$\endgroup\$ Commented Jul 1, 2023 at 21:59
4
\$\begingroup\$

Alternating sublists

Suppose a contiguous sublist that has at least three numbers and alternates between even and odd numbers (or odd and even) is called an alternating sublist. An alternating sublist cannot switch between alternating even and odd numbers to odd to even or vice versa.

Given an input array, find the number of alternating sublists. Zero is considered even, and overlapping is allowed.

For example, in the following input:

[1, 2, 3, 4, 6]

There are three sublists of length 3, of which two are alternating [1, 2, 3] and [2, 3, 4]. [3, 4, 6] is not an alternating as it contains two even numbers in a row.

Also, there is one more alternating sublist with a length of 4 [1, 2, 3, 4].

The entire string is not alternating, as two even numbers are in a row. Thus, the answer is 3.

Test cases

[2, 3, 4, 5] => 3
[50, 50, 10, 80, 96] => 0
[9, 8, 7, 2] => 3
[2, 2, 2, 2, -555, 0] => 1
[1, 2, 4, 6] => 0
[10, 11, 12] => 1
[98, 33, 11] => 0

(some test cases with negative numbers coming soon)

Scoring

Your score is the number of alternating substrings your program has. For scoring purposes, convert all non-numeric chars to their corresponding ASCII code. The tie-breaker is the shortest code. The winner is the answer with the lowest score.


  • I think the scoring system may be better with "shortest code wins"

  • I also think the sentence "An alternating sublist cannot switch between alternating even and odd numbers to odd to even or vice versa. " may be a little confusing, but I can't think of a good alternative.

\$\endgroup\$
14
  • \$\begingroup\$ The description is unclear to me. 1) Does "substrings" mean "contiguous sublists"? 2) "Find substrings" indicates to me that we should return substrings, but the test case returns an integer. 3) There are more than two contiguous sublists of [2,3,4,5] that alternate between odd and even: [2,3], [3,4], [4,5], [2,3,4], [3,4,5], [2,3,4,5]. Do you mean "find the maximum number of non-overlapping contiguous sublists"? \$\endgroup\$
    – DLosc
    Commented Oct 10, 2022 at 19:36
  • \$\begingroup\$ @DLosc fixed. better? \$\endgroup\$ Commented Oct 10, 2022 at 20:15
  • \$\begingroup\$ Better, yes. I made a small change to the sentence order that I think makes it even clearer. I do think a step-by-step worked example before the test cases would be helpful--especially since I just realized that both the original wording and the edited wording said the substrings must have length strictly greater than 2, but I managed to misunderstand that as greater than or equal to 2. \$\endgroup\$
    – DLosc
    Commented Oct 10, 2022 at 21:09
  • \$\begingroup\$ @DLosc Added step-by-step example. \$\endgroup\$ Commented Jan 11, 2023 at 18:09
  • \$\begingroup\$ @DLosc fixed x3 \$\endgroup\$ Commented Jan 11, 2023 at 18:18
  • \$\begingroup\$ There should be at least two test cases of length 3, one alternating and one non-alternating. I'd suggest adding one very long test case, too. Is there a maximum length solutions need to handle? \$\endgroup\$
    – DLosc
    Commented Jan 11, 2023 at 18:21
  • \$\begingroup\$ @DLosc I've added more test cases, though I'm not quite sure what the best way to express "as high as your language supports." \$\endgroup\$ Commented Jan 11, 2023 at 18:31
  • \$\begingroup\$ "Your program should be able to handle input as high as your language supports" seems a bit ambiguous. \$\endgroup\$ Commented Jan 11, 2023 at 18:37
  • \$\begingroup\$ For starters, since we're talking about lists rather than integers, I'd say "long" rather than "high." \$\endgroup\$
    – DLosc
    Commented Jan 11, 2023 at 18:41
  • \$\begingroup\$ Can't understand, seem be inconsistancy \$\endgroup\$
    – l4m2
    Commented Jan 11, 2023 at 18:59
  • \$\begingroup\$ @l4m2 please clarify \$\endgroup\$ Commented Jan 11, 2023 at 19:34
  • \$\begingroup\$ Seems by your definition a list with a length of 1 would be alternating \$\endgroup\$ Commented Apr 27, 2023 at 20:45
  • 1
    \$\begingroup\$ I would recommend rephrasing "substring" to "contiguous sublist" as suggested by @DLosc -- to me, substring definitely has the connotation of being a slice of a string (list of characters; I want to make sure we're on the same page). Even just "sublist" would be okay, just clarify somewhere that you're talking about the contiguous kind. \$\endgroup\$ Commented Apr 28, 2023 at 2:32
  • \$\begingroup\$ @Jacob ok fixed \$\endgroup\$ Commented Apr 28, 2023 at 12:07
4
\$\begingroup\$

Numbers that can be negated by reading backwards

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can the output be a list of numeric values -1, 0 and 1, or does "it is allowed to output numbers in balanced ternary" require a T/0/1 string? \$\endgroup\$
    – RubenVerg
    Commented Jul 14, 2023 at 6:12
  • \$\begingroup\$ A small inconsistency: the text says "positive integers," but the examples include 0, which is not positive. \$\endgroup\$
    – DLosc
    Commented Jul 14, 2023 at 17:12
4
\$\begingroup\$

Continuously Count Consecutive Cases

\$\endgroup\$
6
  • \$\begingroup\$ I think taking input as a list of strings would be the most standard way of achieving what you want (and returning or printing a list of outputs) \$\endgroup\$
    – c--
    Commented Jul 17, 2023 at 15:14
  • \$\begingroup\$ otherwise you could ask for submissions to be full programs, since it's rare to ask that functions keep state \$\endgroup\$
    – c--
    Commented Jul 17, 2023 at 15:15
  • \$\begingroup\$ of course, that would invalidate answers in languages which cannot take input, which is why I'm leaning towards the list of strings approach \$\endgroup\$
    – c--
    Commented Jul 17, 2023 at 15:21
  • \$\begingroup\$ how is a string different from a boolean array here? \$\endgroup\$
    – c--
    Commented Jul 17, 2023 at 15:29
  • 2
    \$\begingroup\$ some relevant defaults for IO: 1, 2, 3 \$\endgroup\$
    – c--
    Commented Jul 17, 2023 at 15:43
  • \$\begingroup\$ @c-- Taking as a list makes much more sense now. Boolean array would consist of booleans instead of characters, as is the expected format for each input. \$\endgroup\$ Commented Jul 17, 2023 at 17:10
4
\$\begingroup\$

Is this ordering total?

Given a matrix like this:

[  0 -1 -1]
[  1  0 -1]
[  1  1  0]

Determine if it represents a proper total ordering. A ordering is total if:

  • It is transitive for < and >: \$\forall a, b, c: a<b \wedge b<c \implies a<c \$. For all a,b, c, if a is less than b and b less than c than a is less than c.
  • It is transitive for equality: \$\forall a, b, c: a=b \wedge b=c \implies a=c \$. For all a,b,c, if a equals b and b equals c, then a equals c
  • It is substitutive \$\forall a,b,c: a=b \wedge b<c \implies a<c\$. For all a, b, c, if a equals b and b is less than c then a is also less than c.

In this matrix I use 1 to represent less than, -1 to represent greater than, and 0 to represent equal. However, you are free to use any 3 distinct values (except complete or partial functions)

Given a matrix representing the ordering of every pair, output one value if the ordering is proper and total, and another if not.

You may assume the input is already anti-symetric, eg. M[a][b] == -M[b][a]. No need to check for that.

Test cases TBD

\$\endgroup\$
4
  • \$\begingroup\$ is reflexivity also required? ie, is the matrix [-1] acceptable? \$\endgroup\$
    – RubenVerg
    Commented Aug 2, 2023 at 14:58
  • \$\begingroup\$ @RubenVerg M[a][b] == -M[b][a] implies M[a][a] == 0 \$\endgroup\$
    – l4m2
    Commented Aug 3, 2023 at 4:10
  • 1
    \$\begingroup\$ @l4m2 I either missed that line or it was added after I asked \$\endgroup\$
    – RubenVerg
    Commented Aug 3, 2023 at 6:05
  • \$\begingroup\$ @RubenVerg I added it in response to your comment \$\endgroup\$ Commented Aug 3, 2023 at 6:06
4
\$\begingroup\$

Assembly capture-the-flag KotH


In this KotH, you'll write a program in a custom machine code (or using one of a few provided languages that compile into it) which tries to run a claim function as many times as possible to collect points. However, all submissions run on the same "machine", allowing a few ways to defeat competitors:

  • Causing a competitor to stop working
  • Tricking a competitor to run claim on your behalf, using your flag (a code you'd pass to claim)
  • Finding a competitor's flag, and running capture on it, which gives their points to you (meta: specifics undecided; not sure if it would take all of their points or just some, or if it would leave the competitor running or not, etc.)

Submissions would be programs in a custom machine code, for a 32-bit machine. This could be written by hand, with an assembly language that will be provided, or with a simple C compiler that will be provided. All submissions will have access to four general purpose registers, which are inaccessible to other programs (unless they can trick you into running code that reveals their contents), and their code and data will be placed in a random part of the up to 4 GiB of RAM, accessible to other programs if they can find it.

Games will run until:

  1. All but one bot has stopped working, and some number of cycles pass since the second-to-last bot dies (to allow a bot that kills all of its competitors to claim some points as the winner)
  2. A number of cycles has passed equivalent to \$2.5x+2048\sqrt{b}\$, where \$x\$ is the size of RAM and \$b\$ is the number of bots

(meta: not sure if there's a better way to do the game-end conditions)

Some example strategies

To show how this might have a rather high skill ceiling, here are some example strategies:

  • Pretending to be a dumb bot, with an exposed flag, as a honeypot. When a competitor injects its own flag, you detect that and capture it instead
  • To avoid the above, read a competitor's code and try to look for things like conditions based on the flag or the capture syscall before attempting the risky flag injection
  • To circumvent the above countermeasure, use self-modification and other tricks to hide what you're doing
  • Watching competitors to see if they've found a bot you're targeting, so you can wait until the last minute to capture its flag for maximum points
  • Tricking other bots into running your own code, and essentially forking yourself, then attack other bots in parallel
  • Placing fake bot source code in random parts of RAM, to waste other bots' time trying to trick a bot that's not there

Machine code reference (in progress)

There are eight 32-bit general purpose registers, which are interchangeable and have no special properties. Additionally, an instruction pointer and flag register are present, but cannot be directly accessed. The four flags are zero (z), negative (n), carry (c), and overflow (o). The instruction set, which takes inspiration primarily from ARM, is as follows:

  • adc: Add with carry
  • add: Add
  • adr: Add signed immediate to the current instruction pointer, and store the result in a register
  • and: Bitwise AND
  • asr: Arithmetic shift right
  • b: Branch
  • b[x|nx]: Branch if flag x is or is not set (any of c, n, o, or z, also p, where p = !n && !z)
  • b[e|ne|gt|lt|ge|le]: Aliases meant to be used with cmp
  • bic: Bit clear
  • call: Branch and push current instruction pointer
  • capture: Capture a flag
  • claim: Claim a point using a flag
  • clz: Count leading zeros
  • cmn: Compare negative (same as add, but discarding result)
  • cmp: Compare (same as sub, but discarding result)
  • dec: Decrement
  • div: Divide
  • inc: Increment
  • ldr: Load register from memory
  • lsl: Bit shift left
  • lsr: Bit shift right
  • mod: Modulo
  • mov: Copy from one register to another
  • mul: Multiply
  • mul2: Multiply, outputting to two registers (to fit results overflowing one register)
  • neg: Negate
  • nop: No-op
  • not: Bitwise NOT
  • or: Bitwise inclusive OR
  • orn: Bitwise inclusive OR with NOT of 2nd operand
  • pop: Pop
  • push: Push
  • ret: Return (pop a pointer and branch to it)
  • ror: Rotate bits right
  • sbc: Subtract with carry
  • sdiv: Signed divide
  • smul: Signed multiply
  • smul2: Signed multiply, outputting to two registers (to fit results overflowing one register)
  • stop: Stop running; bot is killed
  • str: Store register in memory
  • sub: Subtract
  • swp: Swap register(s) with memory
  • teq: Test equality (same as xor, but discarding result)
  • tst: Test (same as and, but discarding result)
  • xno: Bitwise XNOR (XOR with NOT of 2nd operand)
  • xor: Bitwise XOR

Additionally, bots may "trap" one memory address. When this address is written to, an interrupt is issued to the bot. The following instructions exist for this:

  • cli: Clear interrupt
  • int: Register an interrupt for a memory address, immediately branching to a specified location when it is written to (this clears an existing interrupt if one exists)
  • sstr: Stealthy store (allows storing a register to an address without setting off your own interrupt)
  • wfi: Wait for interrupt (suspends bot until interrupt fires; a suspended bot will not prevent the game-end condition unless it wakes up)
  • wfit: Wait for interrupt with timeout (same as wfi, but will un-suspend the bot if a specified number of cycles passes without an interrupt occurring)
\$\endgroup\$
7
  • \$\begingroup\$ 1. Make sure to run this in a virtual machine. 2. Can I use the programming language C? \$\endgroup\$ Commented Aug 6, 2023 at 13:00
  • \$\begingroup\$ @TheEmptyStringPhotographer 1. It's a simulated machine code, so it can't not run in a VM 2. Yes, a simplified C compiler will be provided \$\endgroup\$
    – rydwolf
    Commented Aug 6, 2023 at 16:40
  • \$\begingroup\$ Writes programme to copy itself to the internet, do rm "/" and then copies itself back onto the system. \$\endgroup\$ Commented Aug 6, 2023 at 17:12
  • \$\begingroup\$ @TheEmptyStringPhotographer No access to the outside world will be provided :p \$\endgroup\$
    – rydwolf
    Commented Aug 6, 2023 at 17:14
  • \$\begingroup\$ Then I shall make it copy itself to the parent directory of all the bots and then run the rm command. \$\endgroup\$ Commented Aug 6, 2023 at 17:16
  • \$\begingroup\$ Suggestion: Allow trapping a specific instruction rather than a memory address \$\endgroup\$ Commented Aug 6, 2023 at 20:05
  • \$\begingroup\$ @mousetail How would that work? And for what purpose? The goal of the trapped memory addresses is to detect when another bot is, e.g., progressively overwriting your source code \$\endgroup\$
    – rydwolf
    Commented Aug 7, 2023 at 14:27
4
\$\begingroup\$

Repeat your program to print Fibonacci numbers [tag:code-challenge][tag:source-layout]

\$\endgroup\$
6
  • \$\begingroup\$ Are the header and footer also included in the main byte count, or only in the additional fib(n). If it is only in the fib(n) part then adding a two byte header will only increase the score by 1. \$\endgroup\$
    – bsoelch
    Commented Aug 9, 2023 at 6:48
  • \$\begingroup\$ @bsoelch Only in the header, you are correct that a 2 byte header will only count for 1 score, and a 3 byte only for 2 score. May need to adjust the balance to account for golfing languages where 2 bytes might be actually a useful header \$\endgroup\$ Commented Aug 9, 2023 at 6:51
  • \$\begingroup\$ I would suggest to completely get rid of the header and footer, otherwise something similar to a,b=0,1 a,b=b,a+b print(a) will probably be the shortest solution in most golfing languages \$\endgroup\$
    – bsoelch
    Commented Aug 15, 2023 at 13:21
  • \$\begingroup\$ @bsoelch Many languages may not be able to participate otherwise \$\endgroup\$ Commented Aug 15, 2023 at 13:22
  • 1
    \$\begingroup\$ Then I would suggest to add an additional fixed punishment (of for instance 5 bytes) for using the header/footer \$\endgroup\$
    – bsoelch
    Commented Aug 15, 2023 at 13:23
  • \$\begingroup\$ The example Python submission can be 84 bytes \$\endgroup\$
    – The Thonnu
    Commented Aug 15, 2023 at 16:16
4
\$\begingroup\$

There's more than one way to do it

Cops: Pick a freely available programming language, and pick a function on the integers (i.e. given one integer as input, it produces one integer as output). Then write \$N\$ programs/functions in your language that implement it and are all the same length. \$N\$ must be \$\geq 2\$. Post your language, a description of the function, and \$N-1\$ of the implementations.

Robbers: Pick a cop's post. You can crack the post by finding another program/function in the same language, of equal length, that implements the same function.

(Note that a solution of lesser length, i.e. a golf, is not a valid crack, although in most languages it's easy to pad a solution out to the desired length.)

If a cop's post is not cracked within one week after it's posted, it may be marked as safe. The cop should edit the post to read "Safe" and reveal their omitted solution. Until a post is so edited, it can still be cracked, even if it is more than a week old. A safe cop post is worth \$N\$ points, where \$N\$ is the number of solutions in the post. Robbers receive one point for each cop post they crack.

Details

Cops may use a function on the nonnegative or positive integers if they prefer. If your cop post uses one of these restricted domains, please say so in your post. Your solutions (and robbers' solutions) are allowed to produce different results for inputs outside your chosen domain, as long as they produce identical results for inputs inside the domain.

[Cops may measure the length of a program in any way they choose. Some possibilities are bytes, characters, codels, non-whitespace characters, etc. Please specify how you are counting length in your post.] - I'm not sure about this rule. See below.


Sandbox questions:

  • Is this concept interesting?
  • Does the scoring make sense? Are there ways for the cops to game the scoring system to get arbitrarily high scores? Would it be better if the \$N\$ solutions were forbidden to have any characters/bytes in common? (But that would cause problems for a lot of languages that aren't golflangs, which I'd rather avoid.)
  • Is the "choose your own length measure" rule reasonable, or does it open the door to weird exploits? I suspect that more-flexible counting methods like "number of occurrences of n and Q" will just cause problems for the cop, since they will allow robbers to construct elaborate workarounds using characters that aren't counted.
\$\endgroup\$
5
  • \$\begingroup\$ You should maybe clarify what you mean with restricted domains. You mention restriction to the positive integers, would restricting the function to a finite range (like -2147483648to 2147483647) be also allowed. \$\endgroup\$
    – bsoelch
    Commented Sep 2, 2023 at 18:03
  • 1
    \$\begingroup\$ One problem might be that lambda a:a&1, lambda b:b&1,..., lambda z:z&1 are technically different programs. You should probably add a rule against purely syntactic changes. \$\endgroup\$
    – bsoelch
    Commented Sep 3, 2023 at 8:27
  • \$\begingroup\$ @bsoelch Both good points, thanks. I think it won't work to ban the "technically different programs" approach outright (how to define when a difference is "purely syntactic" in a way that's general enough to apply to all programming languages?), but maybe I can modify the scoring system to disincentivize highly similar programs. \$\endgroup\$
    – DLosc
    Commented Sep 5, 2023 at 19:18
  • \$\begingroup\$ By finding, you mean already implemented in the function's standard library, or programming a solution in the chosen language? \$\endgroup\$ Commented Sep 16, 2023 at 20:13
  • \$\begingroup\$ @ToAskOrNotToAsk The latter: writing a program or function. \$\endgroup\$
    – DLosc
    Commented Sep 18, 2023 at 18:58
4
\$\begingroup\$

Be big more often

\$\endgroup\$
7
  • 1
    \$\begingroup\$ you should specify whether each number in the input should have a chance of appearing, and it'd also help to be more specific about "larger numbers being chosen more often". I'm pretty sure you mean that if a>b, P(a)>P(b), but it may help to spell it out just to avoid confusion. last question: can the input contain duplicates? anyway neat idea, no idea if its a dupe challenge or not sorry \$\endgroup\$ Commented Aug 30, 2023 at 19:50
  • 1
    \$\begingroup\$ @thejonymyster It's ok. I have fixed the issues you have pointed out. \$\endgroup\$ Commented Aug 31, 2023 at 8:10
  • 1
    \$\begingroup\$ can we assume that the numbers are positive \$\endgroup\$
    – bsoelch
    Commented Aug 31, 2023 at 9:47
  • 1
    \$\begingroup\$ @bsoelch Yes, you can. \$\endgroup\$ Commented Aug 31, 2023 at 16:52
  • 1
    \$\begingroup\$ Similar question: codegolf.stackexchange.com/questions/89621/… While not exactly the same, most of the answers there would also solve this question after a sort. \$\endgroup\$
    – chunes
    Commented Sep 1, 2023 at 7:53
  • \$\begingroup\$ @chunes So is it a duplicate? \$\endgroup\$ Commented Sep 1, 2023 at 11:40
  • \$\begingroup\$ Personally I'd say no, but be prepared for others to disagree. \$\endgroup\$
    – chunes
    Commented Sep 1, 2023 at 11:47
4
\$\begingroup\$

The Legend of Koth Episode 1: WANTED

Alright. The WumpusWars project turned out to be more than I can swallow, so I had to give it up. If you're interested in hosting the competition yourself go ahead: it would be very fun.

I instead thought of a simpler-to-implement King of the Hill! I plan to make a series (yeah I love series) of King-of-the-Hill challenges based primarily on metagame and interactions, and named it The Legend of Koth. Here comes Episode 1: WANTED. Hope u like it ;-)

====================

Backstory: A long long time ago in a galaxy far far away, on the planet of code-o-sphere, a civil war broke out between CGCC and CRSE (*). Deserted wasteland spammed with unreadable Esolang code and 100-line-long docstrings were the remains of most once bustling cities of the code-o-sphere.

When the war was over, some survivors settled in the town of Koth. They had magnificent plans: of rebuilding civilization! Equality and freedom for everyone!

... until they found out how hard it was to build a society from scratch. By that time, it was too late.

The town had employed too many vigilantes and trusted them with great power. And so, echoing the lessons learned by habitants of a remote little insignificant blue planet, they found -- the hard way -- that power corrupts, and absolute power corrupts absolutely. Now, the vigilantes are fighting, to see who is the best!

The pains of the previous war eventually convinced them to control the warfare to a relatively small scale: the vigilante factions will send representatives to see who is the best! Now the towns' once beautiful walls and buildings are covered with posters...:

WANTED. Dead, undead, or preferably deader than dead, but definitely not alive, thank you very much.

(*) Note: For those who don't understand the joke, CRSE (Code Review Stack Exchange) is often joked to be CGCC's arch-nemesis because they value readability over conciseness and hacky stuff, while most challenges here want the opposite.

Disclaimer: I am politically strictly neutral and indifferent (this is part of my moral principle) so the backstory bears no relations to real-life politics or history. It's simply a humorous mish-mash of some relevant tropes.

====================

The rule: this is mainly inspired by King of the Holster.

You can distribute your 10 initial points between HP, defense, and reputation. Your HP is your HP point plus 10, and your defense is the probability of blocking, calculated by defense points times 0.1. Your reputation is simply equal to your reputation points times 10.

The basic system is similar to the Holster game. You have 1 ammo at the beginning. During each round, you can (1) refill 1 ammo, (2) heal 1 HP, (3) attack someone, or (4) post a wanted poster.

Attacking costs 1 ammo. The attacked guy chooses a random real number between 0 and 1, and if is smaller than his defense he blocks, meaning that the damage he takes is randomly decided from 0-2. Otherwise he takes 3-5 damage. Killing someone who isn't wanted gives you 20 reputation points.

Wanted posters are publically visible. You can choose to cost x of your reputation to post the poster (no refunds, similar to the bounty system on Stack Exchange). If the guy on the wanted poster is killed the one who killed him has his reputation increased by 20+x.

The winner is the one with the most reputation -- not necessarily the last man standing. If no attacks are made for 10 consecutive turns or only one man is surviving then the game ends.

====================

Good luck and happy coding!

Leaderboard: (will be updated as soon as I can)

Achievements: (all achievements are hidden so no achievement conditions are revealed until someone gets them)

\$\endgroup\$
6
  • \$\begingroup\$ How do you plan to have the bot controller? In Python, or another language? Other than that solid KOTH \$\endgroup\$ Commented Sep 4, 2023 at 17:17
  • \$\begingroup\$ @noodleman In python. Thanks for the encouragement. \$\endgroup\$ Commented Sep 5, 2023 at 3:57
  • \$\begingroup\$ "rolls a dice" -> "generates a random float between 0 and 1"? \$\endgroup\$ Commented Sep 8, 2023 at 14:03
  • \$\begingroup\$ @SuperStormer Thanks. Changed. \$\endgroup\$ Commented Sep 9, 2023 at 1:11
  • \$\begingroup\$ Can multiple posters be posted on the same person? I'm guessing they just add? \$\endgroup\$ Commented Sep 9, 2023 at 17:24
  • \$\begingroup\$ @CommandMaster The bounty just adds on but you can see who wants someone dead \$\endgroup\$ Commented Sep 10, 2023 at 4:34
4
\$\begingroup\$

Decrypt an autokey cipher

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It might be simpler to allow answers to work directly with 0-25 numbers, and not require a transformation to/from letters \$\endgroup\$ Commented Sep 28, 2023 at 14:00
  • \$\begingroup\$ I feel like that may defeat the purpose of the cipher itself, although I did notice that ord and chr took up many bytes when I tried to do a python solution. \$\endgroup\$ Commented Sep 28, 2023 at 14:03
4
\$\begingroup\$

Print 100 digits of π

\$\endgroup\$
3
  • \$\begingroup\$ How can I verify someone's answer is correct or not if they claim it is \pi starts with index 10345292438624234? or even worse Ackermann(10000, 10000)? \$\endgroup\$
    – tsh
    Commented Sep 29, 2022 at 2:21
  • 1
    \$\begingroup\$ @tsh How can they verify it either? \$\endgroup\$
    – emanresu A
    Commented Sep 29, 2022 at 3:22
  • 4
    \$\begingroup\$ How about this: all answers must be verifiable through the Pi API. Example: api.pi.delivery/v1/… gives the first 100 digits. Change the "start" query to "intended index + 1" to get different portions of pi. Rationale: the current world record for digits of pi is 10^14 digits and no one has confirmed the digits beyond that (even if someone has computed more), so the challenge is unanswerable outside the range anyway. \$\endgroup\$
    – Bubbler
    Commented Sep 29, 2022 at 22:49
1
12 13
14
15 16
162

You must log in to answer this question.

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