557
\$\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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

4116 Answers 4116

6
\$\begingroup\$

Chess ASCII Art, Knight

In honor of the world chess championship, in the shortest possible program, output the following ASCII art piece

      ,....,
   ,::::::<
  ,::/^\"``.
 ,::/, `   e`.
,::; |        '.
,::|  \___,-.  c)
;::|     \   '-'
;::|      \
;::|   _.=`\
`;:|.=` _.=`\
  '|_.=`   __\
   `\_..==`` /
    .'.___.-'.
   /          \
  ('--......--')
  /'--......--'\
   "--......--"

This is a code-golf challenge

\$\endgroup\$
9
  • \$\begingroup\$ You might want to make sure all the lines are aligned properly (they could be fine, since I'm on mobile and I know it can display differently, but it looks bent to me). \$\endgroup\$
    – Οurous
    Nov 23, 2018 at 19:59
  • \$\begingroup\$ you're right, it was a little bent, I've reformatted it \$\endgroup\$
    – Thaufeki
    Nov 23, 2018 at 20:17
  • 2
    \$\begingroup\$ Seems straightforward enough \$\endgroup\$
    – Quintec
    Nov 24, 2018 at 1:23
  • \$\begingroup\$ lol, akin to image compression of pixel art in a very specific case :) I like the idea. \$\endgroup\$
    – alan2here
    Nov 24, 2018 at 22:22
  • \$\begingroup\$ The very worst is approx 145 bytes + "verbatim output this". Be fun to see much better ones :) \$\endgroup\$
    – alan2here
    Nov 24, 2018 at 22:33
  • 1
    \$\begingroup\$ Isn't the World Chess Championship already over? According to google it ended nov. 28th. ;) Did you forgot to post it? \$\endgroup\$ Dec 3, 2018 at 9:08
  • \$\begingroup\$ Yeah, I made this post on November 23rd, cross-posting from sandbox eventually slipped my mind \$\endgroup\$
    – Thaufeki
    Dec 3, 2018 at 14:42
  • \$\begingroup\$ @Thaufeki You could still post it, or are you going to wait a year? ;) \$\endgroup\$ Dec 4, 2018 at 10:22
  • \$\begingroup\$ I would have to wait two, next one isn't until 2020! I'll post it now \$\endgroup\$
    – Thaufeki
    Dec 4, 2018 at 14:43
6
\$\begingroup\$

Is this checkmate?

Input

A chess position in FEN format. You can assume the input is a valid chess position.

Output

Two distinct consistent outputs for checkmate or not.

Examples

enter image description here

8/8/8/8/8/5BKN/8/7k b - - 93 47
Mate

\$\endgroup\$
6
  • \$\begingroup\$ I suggest wording similar to “two distinct consistent outputs for checkmate or not” \$\endgroup\$
    – Quintec
    Mar 12, 2019 at 11:52
  • \$\begingroup\$ @Quintec Thanks. \$\endgroup\$
    – user9207
    Mar 12, 2019 at 11:58
  • 4
    \$\begingroup\$ I'd recommend keeping it all self-contained and having a description for the FFN format, as well as a few more test cases \$\endgroup\$
    – Jo King Mod
    Mar 12, 2019 at 21:41
  • 2
    \$\begingroup\$ Is restricted to the FFN format a part of the challenge? Why not allow it in any reasonable format? \$\endgroup\$
    – tsh
    Mar 13, 2019 at 5:47
  • \$\begingroup\$ @Quintec why not just say truthy or falsey? \$\endgroup\$
    – qwr
    Jun 20, 2019 at 14:48
  • \$\begingroup\$ I suggest removing the restriction to FEN format, as it doesn't really add anything to the challenge, and specifying that the output be a truthy or falsey value as that is the usual spec for these types of challenges. \$\endgroup\$
    – scatter
    Aug 26, 2019 at 13:28
6
\$\begingroup\$

Lexicographically earliest valid UTF-8 byte sequence permutation

There are currently 1,114,112 possible Unicode characters (code points). Each character has a unique valid byte sequence in the UTF-8 encoding. Different characters have different length encodings:

  • ASCII characters have a 1-byte encoding 00-7F.
  • The next 1920 characters have a 2-byte encoding C2 80-DF BF.
  • The rest of the BMP has a 3-byte encoding E0 A0 80-ED 9F BF and EE 80 80-EF BF BF.
  • The other planes have a 4-byte encoding F0 90 80 80-F4 8F BF BF.

It's possible for two strings (specific non-normalised sequences of Unicode code points) of Unicode to have byte sequences that are permutations of each other in a number of ways:

  • One string could simply be a permutation of the other at the Unicode level, e.g. ab (61 62) and ba (62 61).
  • UTF-8 continuation bytes could be switched between two characters, e.g. ¡â (C2 A1 C3 A2) and ¢á (C2 A2 C3 A1).
  • UTF-8 continuation bytes could be switched within a character, e.g. (E1 B4 B5) and (E1 B5 B4).

For this challenge I would like you to write a program or function that finds the string whose UTF-8 byte sequence is lexicographically earliest of all such sequences that are permutations of the UTF-8 byte sequence of a given Unicode string.

For example, if your input is ᵴ¢ába (E1 B5 B4 C2 A2 C3 A1 62 61) your output would be ab¡âᴵ (61 62 C2 A1 C3 A2 E1 B4 B5).

Note however that some byte sequences are not valid UTF-8 (e.g. E0 80 A0 which is an overlong encoding for a space) so you need to take care to avoid these.

It would be helpful if your "Try It Online" or similar link includes a footer that helps demonstrate the correctness of your output, where this is not obvious from the I/O format or code.

This is , so the shortest program or function that breaks no standard loopholes wins!

\$\endgroup\$
20
  • 3
    \$\begingroup\$ For test cases, it will probably be a good idea to provide both strings and hex since I'd guess many languages will have to try both. Also this probably needs at least a link to an explanation of UTF8 continuation bytes. \$\endgroup\$ Jun 29, 2019 at 16:57
  • 1
    \$\begingroup\$ "permutation of its canonical" should be "permutation of the input's canonical". \$\endgroup\$ Jun 29, 2019 at 17:00
  • 1
    \$\begingroup\$ @FryAmTheEggman ... but I provided the hex? I'm not sure what I'm missing... \$\endgroup\$
    – Neil
    Jun 29, 2019 at 23:24
  • 1
    \$\begingroup\$ @EriktheOutgolfer How about "I would like you to write a program or function that returns the Unicode string whose canonical UTF-8 byte sequence is the lexicographically earliest of all such sequences that are permutations of the canonical UTF-8 byte sequence of a given Unicode string"? \$\endgroup\$
    – Neil
    Jun 29, 2019 at 23:27
  • 1
    \$\begingroup\$ I meant in the example that you actually had, and presumably some number of test cases. I only mentioned it because I thought it was odd that you did it in the explanation but not the example. \$\endgroup\$ Jun 29, 2019 at 23:54
  • \$\begingroup\$ @Neil Looks good. :) \$\endgroup\$ Jun 30, 2019 at 16:34
  • \$\begingroup\$ I'm wary of the use of the word "canonical" in this question, because it raises issues in my mind about normalisation of Unicode strings. I think that the intended challenge is really about byte arrays with constraints on the most significant bits, and I think it would be better to make that explicit (and to make the constraints explicit). \$\endgroup\$ Jul 2, 2019 at 11:16
  • \$\begingroup\$ @PeterTaylor There is that, but I wanted to exclude sequences such as E0 80 A0. \$\endgroup\$
    – Neil
    Jul 2, 2019 at 13:23
  • \$\begingroup\$ @Neil, I think there's a miscommunication here. I'm saying that instead of talking about Unicode strings the question should explicitly state the FSS-UTF constraints on byte sequences, and maybe rule out encoding UTF-16 surrogate codepoints and codepoints greater than 0x10FFFF. \$\endgroup\$ Jul 2, 2019 at 13:48
  • \$\begingroup\$ @PeterTaylor OK but I really wanted this to be a string question rather than a byte sequence question... \$\endgroup\$
    – Neil
    Jul 2, 2019 at 16:20
  • \$\begingroup\$ The problem then is dealing with the lexicographically first rearrangement of C3 A9 (é in normal form C) being 65 CC 81 (é in normal form D). \$\endgroup\$ Jul 2, 2019 at 16:29
  • \$\begingroup\$ @PeterTaylor Is that possible to do just by permuting the byte sequence? \$\endgroup\$
    – Neil
    Jul 2, 2019 at 16:34
  • \$\begingroup\$ No, and that's why I'm arguing that the question should be phrased in terms of byte sequences rather than strings. \$\endgroup\$ Jul 2, 2019 at 17:40
  • \$\begingroup\$ There’s a mistake in the example: á is C3A1 and ¡ is C2A1. Good challenge. From the sound of it I/O will be flexible; this seems sensible since it keeps it open to more languages. \$\endgroup\$ Jul 2, 2019 at 17:54
  • \$\begingroup\$ @PeterTaylor I wanted it to be clear that these byte sequences must be a valid UTF-8 encoding of a Unicode string. I've tried rewriting the question a bit... \$\endgroup\$
    – Neil
    Jul 2, 2019 at 23:55
6
\$\begingroup\$

Compose Fill In The Blanks

\$\endgroup\$
4
  • \$\begingroup\$ Can you add some test cases? \$\endgroup\$
    – MilkyWay90
    Jul 27, 2019 at 14:35
  • \$\begingroup\$ @MilkyWay90 Ok I added some \$\endgroup\$
    – Wheat Wizard Mod
    Jul 27, 2019 at 14:47
  • \$\begingroup\$ Okay, I give /support (also, you may want to add disallowing standard loopholes and using any default io method to finish it up) \$\endgroup\$
    – MilkyWay90
    Jul 27, 2019 at 14:48
  • 3
    \$\begingroup\$ @MilkyWay90 Those are already standard I am not going to be making my post any more cluttered with stuff that adds nothing. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 27, 2019 at 14:53
6
\$\begingroup\$

Move arrows along a contour

Posted here

\$\endgroup\$
18
  • \$\begingroup\$ I've edited in a question since it needs 2D for clarity. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 8:48
  • \$\begingroup\$ @Adám Only the arrows move. "+-|" always stay in place, or are "hidden" behind an arrow. So, you second example is correct (I deleted the first one) \$\endgroup\$ Jul 26, 2019 at 9:02
  • \$\begingroup\$ Continuing @Adám's question: Are shapes always separated by at least one space, or can they be next to each other like ++++\n++++, and we have to determine if it's a ++++\n++++ or +--+\n+--+ based on the directions the arrows are facing? I.e. is this a possible/valid input, and are those outputs correct? \$\endgroup\$ Jul 26, 2019 at 11:26
  • \$\begingroup\$ @GalenIvanov I didn't have anything but arrows move, and not it doesn't follow, because you couldn't tell what was behind the arrows, -s or +s which is what would make the two possible answers. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:28
  • 1
    \$\begingroup\$ @KevinCruijssen Example 2 has two adjacent shapes with no (vertical) spacing. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:29
  • \$\begingroup\$ @Adám Ah, you're right. As for your question however, you'd still know +<<+\n+>>+ is +--+\n+--+ due to the directions of the arrows in combination with the rule "when an arrow is on a corner, it keeps its current direction and changes it only after the turn is taken". See the pastebin in my previous comment for some test cases where you do know it's ++++\n++++ instead, because of the arrow directions. +^<+\n+>v+ will be two ++++\n++++ boxes, but +<<+\n+>>+ will be one +--+\n+--+ box. \$\endgroup\$ Jul 26, 2019 at 11:37
  • \$\begingroup\$ @KevinCruijssen Good point, but OP actually never says that the input is an obtainable state, though it does make sense. I still have a feeling that there could be ambiguous cases. \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:41
  • 1
    \$\begingroup\$ @KevinCruijssen The shapes will always be separated by at least one space, I'll add it to the description. \$\endgroup\$ Jul 26, 2019 at 11:44
  • \$\begingroup\$ @GalenIvanov Probably better indeed to not have to deal with confusing ambiguous cases. In that case I would also have at least a newline separation, so test case 2 should be slightly modified. :) \$\endgroup\$ Jul 26, 2019 at 11:45
  • \$\begingroup\$ @Adám Oh, I see - indeed I need to correct the second case to have a vertical space between the shapes. \$\endgroup\$ Jul 26, 2019 at 11:51
  • 2
    \$\begingroup\$ Even single tracks can be incredibly difficult: [" ++ ","++++","++^+"," ++ "] only has one possible output: [" ++ ","++++","+++>"," ++ "] \$\endgroup\$
    – Adám
    Jul 26, 2019 at 11:55
  • 2
    \$\begingroup\$ @AdámYes, this is the only output. Do you think a condition that sharp turns are forbidden will help? (this means no two + can be adjacent) \$\endgroup\$ Jul 26, 2019 at 12:21
  • 1
    \$\begingroup\$ @GalenIvanov Maybe that's indeed better to reduce confusion and make the challenge someone more manageable. Although you can still deduct the solution in Adam's comment above, having no spaces inside the space makes it rather difficult to parse correct. Always having at least one |/- between two + will always give the shapes always spaces, making it easier to parse individual shapes. In which case Adam's one would become [" +-+ "," | | ","+-+ +-+","| |","+-+ ^-+"," | | "," +-+ "] -> [" +-+ "," | | ","+-+ +-+","| |","+-+ +>+"," | | "," +-+ "] \$\endgroup\$ Jul 26, 2019 at 13:55
  • \$\begingroup\$ @KevinCruijssen Thanks, I added clarification. \$\endgroup\$ Jul 26, 2019 at 14:09
  • 1
    \$\begingroup\$ @GalenIvanov Maybe also change the one Adam edited in, since it's still with ++ below one-another. :) \$\endgroup\$ Jul 26, 2019 at 15:08
6
\$\begingroup\$

Posted here

\$\endgroup\$
12
  • \$\begingroup\$ I found a lot of similar questions, but not quite the same. Would it be considered a duplicate? \$\endgroup\$
    – Jitse
    Aug 1, 2019 at 8:17
  • \$\begingroup\$ we've had double factorial closed before as a dupe of the vanilla factorial question \$\endgroup\$
    – Giuseppe
    Aug 1, 2019 at 12:03
  • 1
    \$\begingroup\$ @Giuseppe Thanks! I found that post, but I thought the variable factorial range might make it considerably different from the original challenge. \$\endgroup\$
    – Jitse
    Aug 1, 2019 at 12:12
  • \$\begingroup\$ Can we take input as two integers? \$\endgroup\$
    – Adám
    Aug 1, 2019 at 12:49
  • \$\begingroup\$ Can you give a definition for the multi-factorials above 2? \$\endgroup\$
    – MilkyWay90
    Aug 2, 2019 at 4:55
  • \$\begingroup\$ @Adám That makes the challenge somewhat easier, but I suppose it is fair. I added the other input option. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 7:04
  • \$\begingroup\$ @MilkyWay90 Yes! Totally skipped that part, oops. Is it clear enough like this? \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 7:05
  • 1
    \$\begingroup\$ @KevinCruijssen Input numbers can be in any format, of course. I thought this was included in the default I/O rules, buy I will specify this in the challenge. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 12:39
  • \$\begingroup\$ @KevinCruijssen In the input, at least one factorial sign is expected, i.e. a positive integer. I suppose the correct return value for a factorial number of zero would just be the base, but as the challenge is to calculate a factorial, this seems like an unreasonable restriction. The same goes for a factorial number lager than the base. If the factorial number is equal to the base, the base should be returned as per the generalized formula. I will add additional examples to clear this up. Thanks for the feedback! \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 12:39
  • \$\begingroup\$ @KevinCruijssen The range(start,stop,step) function in Python 3 returns a generator with an initial value of start (or 0 if not specified) and a final value of stop-1. For example, the list representation of range(1,4) is [1,2,3]. If this list is sliced as [1,2,3][::-1], the returned list is [3,2,1], which can also be achieved with range(3,0,-1). When the slicing operator is applied to the generator directly, a new generator is returned which generates the sliced list instead. Does that answer your question? Also, range(420,0,-30) would be a cleaner approach in this case. \$\endgroup\$
    – Jitse
    Aug 2, 2019 at 13:08
  • \$\begingroup\$ @Jitse Ah ok, now it makes more sense. I indeed knew range(1,4) is [1,2,3]. And I also knew [::-1] reverses the order, since I see it used in answers every now and then. Seeing the range(1,4)[::-1] == range(3,0,-1) now I'm not sure why I didn't see it myself when I asked you the question. And yes, range(value,0,-n) would indeed be clearer than range(1,value+1)[::-n]. ;) \$\endgroup\$ Aug 2, 2019 at 13:24
  • \$\begingroup\$ Seems good except maybe you should specify that \$n!^{(k)} = n\underbrace{!\ldots!}{k}\$ (n!^{(k)} = n\underbrace{!\ldots!}{k}) \$\endgroup\$
    – MilkyWay90
    Aug 2, 2019 at 16:47
6
\$\begingroup\$

Cliquish Program

Challenge: Write a program that accepts a character (or byte, see additional information) as input. Then:

  1. If the character is contained within the source code, output a different character also in your source code.
  2. If the character is not contained within the source code, output a different character also not in your source code.

This is a , so the shortest program (in bytes) wins.

Additional Information

  • Your program must consist of at least 2 distinct characters.
  • Your program must have at least 2 possible outputs.
  • Your program does not have to be deterministic; it may output a character at random (with any distribution), so long as it conforms to the above criteria.
  • Your program may optionally take a byte as input instead of characters. If you do, the code page the input is written in must contain at least each distinct byte in the source code, as well as at least two different bytes not in the source code.
  • You may take input and give output in any reasonable way. For example, you may take input as a function parameter, a command-line argument, a line from STDIN, a triple-nested array containing a single character, etc. You could output via return value, STDOUT, exit code (if applicable), fax output, etc. The input and output formats must be consistent, however.
  • Your output can only consist of the required character, optionally followed by one trailing newline. Prompt information (such as ans =) is exempt from this rule; such unpreventable output is acceptable.
\$\endgroup\$
5
  • 2
    \$\begingroup\$ Slightly more interesting than most generalised quines. Have you checked quine for dupes? \$\endgroup\$ Aug 2, 2019 at 7:32
  • 1
    \$\begingroup\$ @PeterTaylor related related related. I couldn't find any exact dupes. \$\endgroup\$ Aug 2, 2019 at 19:39
  • \$\begingroup\$ What if your program contains all but one possible character? What encoding are the characters in? UTF-8? latin-1? ASCII? \$\endgroup\$
    – Beefster
    Aug 2, 2019 at 20:18
  • \$\begingroup\$ @Beefster Hopefully I've addressed your first question. As per your second, I believe we have a standard consensus on what a character is \$\endgroup\$ Aug 11, 2019 at 18:13
  • \$\begingroup\$ By induction the program must have 4 possible outputs. Inside/outside of the source × two included in each (if choose one, output the other). Btw I don't understand the title \$\endgroup\$ Aug 22, 2019 at 7:05
6
\$\begingroup\$

Implement Brainfuck Algorithms

In order to make algorithms written in brainfuck more understandable, you can write them in a more abstract notation, where you give a given cell a name, and instead of lots of unreadable < and > instructions to move the pointer to a specific, you just write down the name of the cell. Let us see an example:

This algorithm doubles the value in cell x, and saves the result again in x. It needs an additional temporary cells t

t[-]          clear temporary variable
x[t+x-]       move the value from x to t
t[x++t-]      move twice as many units from t back to x

Now lets see what this would look like, if x was the cell with index 0, and t was the cell with index 2, assuming the poninter is in position 0 when the algorithm starts:

>>[-] 
<<[>>+<<-]  
>>[<<++>>-]

Challenge

Given a string with a valid (see below) brainfuck algorithm, a list of strings containing the cell names and a list of integers containing the indices of each of the cell of the previous list, your program/function has to return an implementation of this algorithm in brainfuck.

Details

  • The pointer is assumed to be on a cell with index 0 when the implementation is executed.
  • The two given lists can also be in a different reasonable format e.g. [cell1,index1,cell2,index2,...] or [[cell1,index1],[cell2,index2],... or as arguments of a function with a variable number of arguments etc.
  • You can assume that in the given string representing the algorithm, there are only brainfuck instructions as well as cell names, but no other symbols (no line breaks, no spaces)
  • The cell names consist of lower- and uppercase characters A-Z and a-z as well as digits 0-9
  • The cell names in the string are always separated by at least one BF instruction symbol.
  • You can assume that the pointer is the same index whenever it enters a loop as it exits the same loop.

Examples

x=y:

String (remove line breaks):
  temp0[-]
  x[-]
  y[x+temp0+y-]
  temp0[y+temp0-]
List of variable names: [temp0,x,y]
List of indices:        [    2,0,1]
Output (remove line breaks):
  >>[-]
  <<[-]
  >[<+>>+<-]
  >>[<+>-]

x=x*x

String (
  temp0[-]
  temp1[-]
  temp2[-]
  x[temp2+temp1+x-]
  temp1[
    temp2[x+temp0+temp2-]
    temp0[temp2+temp0-]
    temp1-
  ]
List of variable names: [x,temp0,temp1,temp2]
List of indices:        [0,    1,    2,    3]
Output (remove line breaks):
  >[-]
  >[-]
  >[-]
  <<<[>>>+<+<<-]
   >>[
    >[<<+>+>>-]
    <<[>>+<<-]
    >-
  ]

(More to be added)

\$\endgroup\$
3
  • \$\begingroup\$ Aah, I just noticed something when writeing that line (see meta section) but I do not have time right now to think through that. That's why this part was unfinished. \$\endgroup\$
    – flawr
    Jun 20, 2016 at 15:14
  • \$\begingroup\$ I think that this is undecidable. Consider a line of the form x[algorithm] where algorithm doesn't guarantee to leave the pointer where it started. For the subsequent line to move the pointer to the desired cell it needs to know whether x was zero going into that line or not. \$\endgroup\$ Jun 20, 2016 at 16:03
  • \$\begingroup\$ I think the problem can be solved by requiring that there are no <> in the input. Although that would make the resulting language not Turing-complete (can only access finite amount of memory) \$\endgroup\$
    – DELETE_ME
    May 2, 2018 at 9:51
6
\$\begingroup\$

ASCII Maze Unrendering 3000

Posted

\$\endgroup\$
5
  • \$\begingroup\$ Part of the wall for the current only test case seems a bit too narrow. \$\endgroup\$ Aug 28, 2019 at 2:37
  • \$\begingroup\$ I think this could be considered a special case of this challenge, with slight differences in the voxel style. \$\endgroup\$
    – flawr
    Aug 29, 2019 at 6:56
  • \$\begingroup\$ @flawr You're right. As written, this is a duplicate. Do you know if the reverse has been done, taking the 3d version and returning the original? \$\endgroup\$
    – Hiatsu
    Aug 29, 2019 at 17:52
  • \$\begingroup\$ I don't think the reverse has been done, but I'm not sure this would make a good challenge. I'm still thinking about how one could make this. I mean the 2d version you propose would make it a bit simpler. \$\endgroup\$
    – flawr
    Aug 29, 2019 at 19:10
  • 1
    \$\begingroup\$ Yes. The full 3d version would almost certainly be impossible, because most voxels would be completely blocked. Here, every block is visible, and a human can figure out where the walls are, so a computer should be able to do it too. \$\endgroup\$
    – Hiatsu
    Aug 29, 2019 at 19:17
6
\$\begingroup\$

Question link

\$\endgroup\$
8
  • \$\begingroup\$ @Night2 Indeed, didn't notice that point, I fixed the samples in the rules to include AA-000-AA \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 6:25
  • \$\begingroup\$ Are the letters mandatory to be uppercased, or could we output in lowercase as well? \$\endgroup\$ Sep 20, 2019 at 9:51
  • 1
    \$\begingroup\$ @KevinCruijssen Yes, letters are mandatory to be uppercase, also I feel like you ask that because of a builtin somewhere :P \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 12:36
  • \$\begingroup\$ Fine by me. I was mainly asking because it isn't a core-part of the challenge, and in some challenges lowercase/uppercase/mixed case is all allowed. But you're indeed right that lowercase would save a byte in my language of choice 05AB1E, where A is the lowercase alphabet builtin, and I'd need an additional u to uppercase it. ;p But since number plates are always uppercase, I can understand to keep the uppercase mandatory here as well. I had prepared a 24-byter, but will throw it away for now since I feel this can be done shorter.. Will try again later when it's posted to main. :) \$\endgroup\$ Sep 20, 2019 at 12:41
  • \$\begingroup\$ Another question, or more recommendation: allowed both 0-based and 1-based indexing for answers. I see your test cases are 0-based, but some languages use 1-based indexing instead. \$\endgroup\$ Sep 20, 2019 at 12:44
  • 1
    \$\begingroup\$ @KevinCruijssen Sure, no problem with 1-based indexing, going to fix the rules to add that. As I've never used such languages, I often forget about them \$\endgroup\$
    – Elcan
    Sep 20, 2019 at 13:19
  • \$\begingroup\$ I would say if the format irl has to be in uppercase then following that would be better. I've got myself an 85-byte JS answer that conforms to the irl format though. \$\endgroup\$ Sep 21, 2019 at 1:06
  • \$\begingroup\$ @ShieruAsakoto That's what I also advocate for, minus all the dumb real life rules that would just make it unfun to do. Anyway, going to post this \$\endgroup\$
    – Elcan
    Sep 23, 2019 at 18:41
6
\$\begingroup\$

Almost Illegal Strings

Posted.

\$\endgroup\$
11
  • \$\begingroup\$ Does the challenge need to have the robber code output "Well done!"? What if they could just submit any code with the substring that runs? \$\endgroup\$
    – xnor
    Oct 24, 2020 at 10:24
  • \$\begingroup\$ @xnor That's fair enough - I just struggle to define 'program that runs'. Would you consider zero exit code and no stderr output reasonable? Or are there some languages that output to stderr even in a valid program? \$\endgroup\$
    – Sisyphus
    Oct 24, 2020 at 12:00
  • \$\begingroup\$ I think this is too similar to the original "illegal strings" question which basically turned into a cops-and-robbers anyway \$\endgroup\$
    – pxeger
    Oct 24, 2020 at 18:26
  • \$\begingroup\$ @Sisyphus I was thinking you could just copy whatever condition Find an Illegal String uses. But it doesn't seem to be that rigorous, saying "The compiler/interpreter/runtime must give an error when given any source code that contains your string as a substring." I think requiring no output to STDERR is probably fine. Maybe though some languages give warnings to STDERR that golfers typically ignore? Note that defaults allow programs that print then crash, so just requiring output doesn't preclude a fatal error after. \$\endgroup\$
    – xnor
    Oct 24, 2020 at 21:12
  • \$\begingroup\$ Rule suggestion: commenting out the almost illegal string is not allowed \$\endgroup\$
    – Beefster
    Oct 28, 2020 at 15:33
  • \$\begingroup\$ I think it's too thorny to define what comments are in a way that works across languages. One objective way to handle it would be to let cops specify a set of characters that are not in their code, where they might include their language's comment character(s) or quote literals. \$\endgroup\$
    – xnor
    Oct 29, 2020 at 0:40
  • \$\begingroup\$ @xnor Ok, I've rewritten the challenge to just require that the program does not error, and feel the rules are fairly straightforward and watertight. \$\endgroup\$
    – Sisyphus
    Nov 1, 2020 at 5:50
  • \$\begingroup\$ @Beefster I considered this, and something like xnor's suggestion of banning characters. However, I think it ruins the purity of the challenge a bit, and for most languages it's very easy to avoid being in a comment (newline + end of comment block will do it). There are some languages which have 'inescapable comments', such as raw strings with specific delimiters, or something like Perl's __END__, but they're sacrifices I'm willing to make. \$\endgroup\$
    – Sisyphus
    Nov 1, 2020 at 5:52
  • \$\begingroup\$ The problem with not banning comments (or including things within strings, for that matter) is that it's quite easy to cop out and write a hello world with the almost illegal string appended in a comment. That takes out all the challenge. xnor's suggestion solves that mostly, but that does end up limiting cops a little bit to make the robbers' job an actual challenge. \$\endgroup\$
    – Beefster
    Nov 2, 2020 at 16:25
  • 1
    \$\begingroup\$ @Beefster Apologies, I have not been clear about my reasoning. My logic is that for the vast majority of languages, a cop can 'comment proof' their string trivially by adding a newline (to escape a single line comment) and an end of comment block (to end a multiline comment). For example, the string \nx"""x''' (with a literial newline) escapes all Python comments. You can do this in most languages - or am I missing something? \$\endgroup\$
    – Sisyphus
    Nov 3, 2020 at 3:12
  • 2
    \$\begingroup\$ @Beefster It looks like you were right - it is too hard without allowing Cops to ban characters. I'd like to apologise for not taking your feedback more seriously while the question was in the sandbox. \$\endgroup\$
    – Sisyphus
    Nov 6, 2020 at 1:10
6
\$\begingroup\$

Speed of Lobsters

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

Print random integers until 0

\$\endgroup\$
10
  • \$\begingroup\$ Presumably, if the first number is zero, we just output zero and exit? \$\endgroup\$
    – pxeger
    Jan 16, 2021 at 18:57
  • \$\begingroup\$ "integers may be separated by any non-digit, non-empty separator" can we output in zero-padded form (00 01 .. 98 99) so that a separator isn't necessary? What about codepoints/byte values (NULL - c)? Can it be a list-like object rather than a separated string? I think this would be better with more sequence-like IO rules \$\endgroup\$
    – pxeger
    Jan 16, 2021 at 18:59
  • 1
    \$\begingroup\$ @pxeger Yes, if the first number is zero, you just output zero and exit. I don't think the standard is to output with zero-padding, so I'll say no on that. Byte values and list objects are both standard forms of outputting a bunch of numbers, so of course, those are allowed \$\endgroup\$ Jan 16, 2021 at 19:07
  • \$\begingroup\$ Also, I assume it is not necessary that the program follows the indicated procedure (which would be unobservable anyway), as long as the output has the same statistical properties. So if a different procedure is used, perhaps the answer writer should justify it. (For example: generate a number K geometrically distributed with parameter 1/99, then output K nonzero numbers, then output a 0) \$\endgroup\$
    – Luis Mendo
    Jan 16, 2021 at 19:07
  • \$\begingroup\$ @LuisMendo Yeah, I'm pretty sure that "you don't have to follow the letter of the challenge so long as the behaviour is the same" is a standard rule, but in case not, I've edited in a sentence along with your example \$\endgroup\$ Jan 16, 2021 at 19:10
  • \$\begingroup\$ I didn't fully define my example, sorry. You may want to change it to "then output K independent numbers with a uniform distribution on the set {1, 2, ..., 99}". That corresponds to the procedure you specify with a uniform distribution on {0, 1, ..., 99}. \$\endgroup\$
    – Luis Mendo
    Jan 16, 2021 at 19:21
  • \$\begingroup\$ @cairdCoinheringaahing are built-in functions for generating pseudo-random numbers forbidden? If not, is the challenge a very trivial one or am I missing something? \$\endgroup\$
    – anotherOne
    Jan 27, 2021 at 23:17
  • 1
    \$\begingroup\$ @Davide Trivial challenges are not necessarily bad, since it encourages participation in relatively hard-to-use or minimal esolangs. And I think this one is actually good because I smell many unexpected approaches to golf the problem. (Also, banning built-ins are considered bad.) \$\endgroup\$
    – Bubbler
    Jan 28, 2021 at 0:26
  • \$\begingroup\$ @Bubbler thank you so much for this train of information \$\endgroup\$
    – anotherOne
    Jan 28, 2021 at 0:35
  • 1
    \$\begingroup\$ @Davide Nope, all builtins are allowed. As Bubbler said, trivial challenges are only really bad if there’s no room for interesting solutions, which I don’t think is the case here \$\endgroup\$ Jan 28, 2021 at 10:06
6
\$\begingroup\$

Remove Nth occurrences

\$\endgroup\$
4
  • 2
    \$\begingroup\$ There is this but it got closed, Everything is clear, but can you replace, "the n" with "the integer n" in the last point of your assumptions list. For some reason that made me read the sentence multiple times. \$\endgroup\$
    – Alex bries
    Feb 23, 2021 at 12:08
  • \$\begingroup\$ Is there a reason for limiting the array values to 1-9? \$\endgroup\$
    – pxeger
    Feb 23, 2021 at 19:49
  • 1
    \$\begingroup\$ @pxeger Because the values don't matter, so there's no reason to complicate it more. Plus, it can allow for some interesting string based approaches by taking \$A\$ as a single string \$\endgroup\$ Feb 23, 2021 at 19:52
  • \$\begingroup\$ @pxeger It certainly helps that 0 cannot be part of the array, because then I can use it to erase values in APL. I'm sure other languages can take advantage of that too \$\endgroup\$
    – user
    Feb 24, 2021 at 1:48
6
\$\begingroup\$

To raise \$ e \$ to the power of a matrix

Posted


Meta

  • Is this clear enough?
  • Is this a duplicate?
  • Any other feedback?
\$\endgroup\$
8
  • \$\begingroup\$ why not require exact calculation, it makes for a harder challenge but a more interesting one \$\endgroup\$
    – rak1507
    Apr 1, 2021 at 19:54
  • \$\begingroup\$ @rak1507 it's irrational so an exact value can't be calculated \$\endgroup\$
    – pxeger
    Apr 1, 2021 at 19:55
  • \$\begingroup\$ looked like there were methods on wikipedia but I could be wrong \$\endgroup\$
    – rak1507
    Apr 1, 2021 at 21:45
  • \$\begingroup\$ Note that the exponential of a 9x9 matrix of 100's exceeds what floats can represent. You might want to lower the 100 bound or make allowances for that. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 6:30
  • \$\begingroup\$ I think the precision convergence rule is too restrictive and too tied to that specific power series method, and some loose accuracy bound would allow more varied methods. For instance, one can approximate \$e^M \approx (I+M/n)^n\$ for large \$n\$. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 6:38
  • \$\begingroup\$ @xnor I didn't read much into the matrix exponential (because I couldn't find the article on Wikipedia and was too busy watching the rest of the 3b1b video :P), so I hadn't not really realised there were other ways to compute it. What would you recommend? I still like the idea of requiring it to be observed to converge within floating point limits, because it adds an extra layer of challenge rather than just "repeat this step 100 times", but maybe that just isn't practical \$\endgroup\$
    – pxeger
    Apr 2, 2021 at 6:50
  • 5
    \$\begingroup\$ I think convergence within floating point limits would unfortunately be hard and finicky here because of the nature of exponentials. The same way that \$e^{100}\$ and \$e^{100.001}\$ differ a lot, small errors in the computation can accumulate into huge ones. Also, the values in the output might be extremely small and become represented as zero. I'd have to think more about bounds, but maybe something like every entry within either 1% or 1e-4 of the true one should work. \$\endgroup\$
    – xnor
    Apr 2, 2021 at 7:03
  • 2
    \$\begingroup\$ My solution to floating-point errors is "the result should be within [insert error bound here] relative error for the given test cases". (The bolded part is VERY important. FP computation methods often have errors dependent on the magnitude of the input, so it is very hard to judge if an implementation is valid, even if the possible input range is specified. Explicitly giving the test cases makes it much easier to test submissions. Also, you need to craft the test cases carefully so that you don't accidentally ban a valid method or allow invalid methods.) \$\endgroup\$
    – Bubbler
    Apr 4, 2021 at 23:28
6
\$\begingroup\$

Non-quining infinite printer

Seems like the title could be better but I'm not sure what to do instead

I have heard that a monkey typing random keys on a typewriter, given infinite time, will eventually type out the entire works of Shakespeare, and in fact type out every possible string of characters of any length. This sounds to me like the basis for a profitable business venture in publishing. Unfortunately, however, as a result of previous failed business ventures, I am legally barred from possessing either monkeys or typewriters, so I'll instead need a program. I want this program to provably generate every possible string of characters, assuming infinite time and memory. Repetition is fine, as is overlap, as long as every possible string appears somewhere in the output. There's a catch, though. I imagine once my business gets off the ground and people realize the potential profits, they might want to get their hands on my program. The trouble is that since I'm outputting every possible string of text, in theory I'll eventually end up outputting the program itself, leaving it open to be stolen. To prevent this, I want the program never to output its own source code. It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of). Because my funds are currently very tight, I can't afford to pay for more bytes than are necessary, so I'm seeking the shortest possible program that does the job (This is a code-golf challenge, shortest answer in bytes wins). Is it communicated well enough what this challenge is asking for? Should I add a TL;DR and/or a more technical explanation of what's being looked for?

Additional notes:

  • I've had enough run-ins with the law in previous ventures, I'd like this one to go smoothly. So no abusing loopholes in the program, please.
  • Given that this program is my financial plan for the next infinity years, I'd like some reassurance that it actually does what it's supposed to. Please provide at least a brief explanation of why your code works, since it can't exactly be tested.
  • Any character encoding is fine, please specify though. The exception is that your source code must be printable in the encoding you use. Is this a reasonable way to handle this that is fair to all languages?
  • No reading your own source, because that makes quine-related holes uncool, and uncoolness does not fit with my businesses' brand persona.
\$\endgroup\$
7
  • \$\begingroup\$ How are the strings in the output separated? Some previous challenges about "print all possible strings" were closed as unclear because of this. \$\endgroup\$
    – Bubbler
    Jun 7, 2021 at 1:06
  • \$\begingroup\$ @Bubbler The strings don't have to be separated. What I mean is that every string should be a substring of the "main" output if that makes sense. Put another way, running a regex match on the output for any string of characters (other than the source) should return at least one result. Would adding something to that effect clear up that confusion? \$\endgroup\$
    – je je
    Jun 7, 2021 at 1:13
  • \$\begingroup\$ It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of) Okay, the task makes sense now. I think you'll need to add that information somewhere before the sentence I quoted. Now I wonder if the task is actually possible... \$\endgroup\$
    – Bubbler
    Jun 7, 2021 at 1:39
  • \$\begingroup\$ @Bubbler Sure, it's possible. One approach is to store the program's source in a string, and then run some sort of code that generates every possible string, checking after each generation whether the generated string contains the source string, and only printing if it doesn't. There might be some trouble in making sure the source isn't present in a combination of two consecutively generated strings (i.e. if the source code is AB, then outputting XA and BX consecutively is an issue), but a simple solution to that is to insert a character not present in the source between each pair. \$\endgroup\$
    – je je
    Jun 7, 2021 at 8:02
  • \$\begingroup\$ Here's an implementation in Python tio.run/… \$\endgroup\$
    – je je
    Jun 7, 2021 at 8:03
  • \$\begingroup\$ @jeje An easily thought solution is just use an unused char as split, but that likely be longer \$\endgroup\$
    – l4m2
    Jul 1, 2021 at 16:40
  • \$\begingroup\$ What do mean by "all possible strings"? Is this restricted to all strings consisting of printable ASCII? The entire Unicode table? \$\endgroup\$ Jul 8, 2021 at 1:14
6
\$\begingroup\$

Who Is Kevin Bacon?

\$\endgroup\$
2
  • \$\begingroup\$ > I'm worried it will just be "string a load of combinatorial builtins together" and brute-force it That's a solution to pretty much anything \$\endgroup\$
    – emanresu A
    Dec 30, 2021 at 5:12
  • \$\begingroup\$ it looks interesting enough, I can't find anything similar with searches like "Erdos number" and such. It will inevitably get a trivial golflang answer, especially with felxible input methods. To control quality, maybe adding a restricted-time would help. \$\endgroup\$
    – Razetime
    Jan 2 at 7:49
6
\$\begingroup\$

Sort every dimension

\$\endgroup\$
6
\$\begingroup\$

Output a random unary string

\$\endgroup\$
9
  • \$\begingroup\$ Would printing an infinite stream of separators or xs be valid? It's an infinitesimally small chance that just, e.g., one x is ever printed for the rest of time, but does that count (I'd be inclined to say no)? \$\endgroup\$ Feb 22 at 20:43
  • \$\begingroup\$ i have no idea what this challenge is about but +1 \$\endgroup\$
    – DialFrost
    Feb 23 at 3:43
  • \$\begingroup\$ Since most languages random number generator (RNG) only have finite state, The program won't output infinity number of different outputs. You may argue that we may consider (assume) RNG have infinity digits (precision). But then, someone would argue that repeat("x", floor(1/random_between_0_and_1())) is a valid submission as we can consider the output of random_between_0_and_1 have infinity precision. It is not very clear which is valid and which is not to me. \$\endgroup\$
    – tsh
    Feb 23 at 10:32
  • \$\begingroup\$ Looks like "the RNG in use has perfect random distribution" is a necessary assumption, but allowing the return value of RNG to be of infinite precision sounds a bit weird, as tsh pointed out. You may want to clarify these points in the challenge rules. (I'm not entirely against it though; in some langs the only source of randomness is a random real number in [0,1), which makes some compromises like "you can only use RNGs that return a finite number of integers" unsuitable) \$\endgroup\$
    – Bubbler
    Feb 23 at 23:56
  • \$\begingroup\$ @tsh @Bubbler Do you think the rule I just added is adequate? (I think tsh's suggested repeat("x", floor(1/random_between_0_and_1())) should be considered valid as long as it never causes a division by zero.) \$\endgroup\$
    – pxeger
    Feb 24 at 16:20
  • \$\begingroup\$ @pxeger I cannot understand how random_between_0_and_1 output a "infinite precision" number in finite time (so program will halt with with probability 1). But regardless this, the rule seems clear to me. \$\endgroup\$
    – tsh
    Feb 25 at 7:20
  • \$\begingroup\$ @tsh Well obviously nothing can output an infinite precision number of any kind, but I'm allowing it as an assumption because I think it should be considered a valid possible solution. \$\endgroup\$
    – pxeger
    Feb 25 at 7:44
  • \$\begingroup\$ Does "Every possible length of xs" includes 0 (empty output)? \$\endgroup\$
    – tsh
    Feb 25 at 9:08
  • \$\begingroup\$ @tsh "You may choose whether to include the empty string as a possible output" \$\endgroup\$
    – pxeger
    Feb 25 at 9:50
6
\$\begingroup\$

Building spikes

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Interesting idea. I think the challenge could be interesting if solutions were required to take in a size and output a spiked building of that size. \$\endgroup\$
    – ophact
    Mar 9 at 8:20
  • \$\begingroup\$ @ophact is it better now? \$\endgroup\$
    – DialFrost
    Mar 9 at 23:37
  • \$\begingroup\$ Why input 7 is one line taller than input 2? \$\endgroup\$
    – tsh
    Mar 10 at 3:02
  • \$\begingroup\$ @tsh its same height \$\endgroup\$
    – DialFrost
    Mar 10 at 3:04
6
\$\begingroup\$

Sort numbers in a ragged list

\$\endgroup\$
3
  • \$\begingroup\$ Can the output be flattened? \$\endgroup\$
    – Alan Bagel
    Mar 11 at 22:55
  • \$\begingroup\$ @BgilMidol No, that defeats the point of it. \$\endgroup\$
    – emanresu A
    Mar 11 at 22:56
  • 2
    \$\begingroup\$ I think to avoid ambiguity it should be said something like "The shape of the output must be the same as the shape of the input". The spec is currently pretty sparse, relying mostly on an example. \$\endgroup\$
    – Wheat Wizard Mod
    Mar 11 at 22:57
6
\$\begingroup\$

King of the Holster (EXITING SANDBOX TOMORRROW)

I realized there hadn't been a King of the Hill in forever, so I wanted to create one.

Before the Game

You will be given 10 points to distribute between HP, Dexterity, Armor, and Speed. You may distribute up to 10 points between these categories (integer amounts only). You do not have to put a point in each category.

  • Your HP will equal 10 plus the number of points you put in HP.
  • Your Dexterity (chance of dodging a hit) is equal to 0.04 times the number of points you put in Dexterity. For example, if you put 8 points in Dex, you would have a .32 chance of dodging a hit.
  • Your Armor (chance of taking 1 less damage from a hit) is equal to .1 times the number of points you put into Armor.
  • Your Speed is simply equal to the number of points you put in Speed.
  • You always start with 2 ammo.

Gameplay

Agents will be ordered based on their speed, with ties being broken at random before the game begins. On their turn, each agent will be given their HP, all of their stats (max HP, Dexterity, Armor, and Speed), how much ammo they have, who they attacked most recently, and who attacked them most recently.

On each agent's turn, there are three possible moves:

  • Heal: If not at maximum HP, gain 1 HP.
  • Reload: Gain 2 ammo.
  • Shoot: Choose another agent. They get a random real from 0 to 1. If that number is less than their dexterity, they dodge and take 0 damage. Otherwise, they take a random integer amount of damage from 1 to 4, then they generate another random real from 0 to 1. If that number is less than their armor, they take 1 less damage.

TLDR: Shooting does 0 damage if they dodge, 0 to 3 if they get armor but no dodge, 1 to 4 if none.

Once an agent's HP is less than 0, it is out and can no longer take actions. Last agent surviving wins the round.

Scoring

Each round, if there were X agents, your agent receives X points for each agent below it. Therefore, in a 10 player game, the top agent would get 9 points, the second would get 8, and so on. I can currently run 5000 3-player modes in 10 or so seconds (probably much faster if I removed some of the printing for debugging), so as long as nobody's agent takes too long to run, I should be able to run thousands of score tests.

I/O

Currently, submissions will create a class which extends PlayerClass. It will create a new class constructor that takes no inputs, which will call super() with the points it wants in each category. Additionally, you will redefine the makeMove function, which takes no inputs and calls move() with whatever arguments are required.

Rules

Submissions in Java only. As long as the submission is simple enough, I might be able to translate from pseudocode/some other language to Java though.

No calling any methods of other entities using shenanigans. The biggest problem here is takeDamage(), which has to be public so it can be called when someone is shot. Other than that, there shouldn't be any public functions other than turn-order functions, which are probably fine to access.

No redefining any functions/variables of PlayerClass besides makeMove().

The subclass constructor must be of the form super(x,y,z,a); and cannot overwrite the requirements in the PlayerClass constructor.

You may define other methods within your class IF they are only called as part of generating your stats or deciding who to shoot and they follow the rules outlined above.

Don't make your code take forever. This KOTH is pretty lightweight, so there shouldn't be a need for complex algorithms.


The controller and four basic test agents can be found here: https://github.com/romanpwolfram/GunfightKoTH/tree/main

Challenge name by tjjfvi.

\$\endgroup\$
8
  • \$\begingroup\$ What programming language? \$\endgroup\$
    – ophact
    Apr 18 at 16:18
  • \$\begingroup\$ Java right now, but it's simple enough that I can probably convert it to another language with a bit of work. \$\endgroup\$
    – Romanp
    Apr 18 at 16:31
  • \$\begingroup\$ How much damage does getting shot do? \$\endgroup\$ Apr 18 at 16:33
  • \$\begingroup\$ Random from 1 to 4, but random from 0 to 3 if they "win" their armor roll. \$\endgroup\$
    – Romanp
    Apr 18 at 16:34
  • 1
    \$\begingroup\$ > I realized there hadn't been a King of the Hill in forever sad noises \$\endgroup\$
    – Seggan
    Apr 18 at 18:34
  • 1
    \$\begingroup\$ That one looked like a good KoTH, and I have no idea why it failed. Reasonably complex strategy, but easy enough to code. \$\endgroup\$
    – Romanp
    Apr 18 at 18:36
  • 1
    \$\begingroup\$ Watch out, a player can just do ammo = 10000 and get away with it. Might want to make em private and instead put getters. \$\endgroup\$
    – Seggan
    Apr 19 at 0:18
  • 1
    \$\begingroup\$ Ok. I think I can change all of them since all the info you need should come from getInfo and getAlivenemies \$\endgroup\$
    – Romanp
    Apr 19 at 13:11
6
\$\begingroup\$

Convert Alpha-3 to Alpha-2

\$\endgroup\$
3
  • 2
    \$\begingroup\$ If that link goes down, or if the list changes for any reason (such as by adding a new country), it would invalidate existing answers. The usual way around this is to declare one unchanging list of every country/territory code that needs to be handled, even if the external resource changes. Since the full list looks too large to comfortably fit in a post, you could copy the list into a Pastebin or something. \$\endgroup\$
    – Nitrodon
    Apr 28 at 14:12
  • \$\begingroup\$ Yep! I was planning on posting one to my website later today! \$\endgroup\$
    – Komali
    Apr 28 at 14:13
  • \$\begingroup\$ @Nitrodon done! \$\endgroup\$
    – Komali
    Apr 28 at 16:22
6
\$\begingroup\$

Shortest restricted superstring

\$\endgroup\$
1
  • 1
    \$\begingroup\$ please don't enforce answers having to handle the empty set as either input but especially the first. It's just an annoying edge case. \$\endgroup\$
    – emanresu A
    May 4 at 5:48
6
\$\begingroup\$

ITEXTIN - Is This an EXTended Initialism?

Please write a program or function that, when given a list of words and proposed extended initialism, outputs whether it is valid.

Rules:

  • The list will contain at least two words.
  • The extended initialism will contain at least three letters.
  • Each word in the phrase contributes a prefix to the extended initialism.
  • This prefix must not be the whole word.
  • In the case of the first and last words, the prefix must not be empty.
  • The extended initialism is the concatenation of these prefixes.
  • Inputs are alphabetic only, your choice of upper or lower case.
  • Separators, if you want them, are any symbol or white space.

Examples (truthy):

laser=light amplification by the stimulated emission of radiation
radar=radio detection and ranging

Examples (falsy):

labyser=light amplification by the stimulated emission of radiation
radar=light amplification by the stimulated emission of radiation
dear=radio detection and ranging

This is , so the shortest program or function that breaks no standard loopholes wins!

\$\endgroup\$
8
  • \$\begingroup\$ How should a function determine whether to exclude words such as by, the, of or and? \$\endgroup\$
    – jezza_99
    May 26 at 1:21
  • \$\begingroup\$ @jezza_99 By looking at which letters it needs. \$\endgroup\$
    – Neil
    May 26 at 6:18
  • \$\begingroup\$ Surely then labtseor is correct, not laser, by "Each word in the phrase contributes a prefix to the extended initialism." \$\endgroup\$
    – jezza_99
    May 26 at 23:27
  • \$\begingroup\$ @jezza_99 Empty prefixes are allowed except for the first and last words. \$\endgroup\$
    – Neil
    May 26 at 23:27
  • \$\begingroup\$ Can we assume the input initialism is always at least 2 characters long? If not, can we at least assume it's non-empty? \$\endgroup\$
    – pxeger
    May 28 at 11:41
  • \$\begingroup\$ @pxeger Hmm, 2 characters is still a bit of an edge case, since it can only ever be the first character of the first and last words... maybe I should make it at least 3? What do you think? \$\endgroup\$
    – Neil
    May 28 at 14:17
  • \$\begingroup\$ @Neil I don't exactly see anything wrong with just >=2, but to completely minimise any problem you could go with >=3 to be safe. \$\endgroup\$
    – pxeger
    May 28 at 15:11
  • 1
    \$\begingroup\$ @pxeger How about the list of words? I've gone with >=2 there for now. \$\endgroup\$
    – Neil
    May 28 at 16:17
6
\$\begingroup\$

Count alternating permutations

\$\endgroup\$
6
\$\begingroup\$

Race some Robots

Based on RoboRally, but uses some different/simplified rules

In this KoTH, you will be coding a Python bot that attempts to race around a factory, reaching two specific places before the other bots, who are doing the same thing. The way you'll reach these places - the "checkpoints" - is by sending instructions to the bot, telling it where to move.

The Factory

The factory is represented by a \$13 \times 10\$ 2D list, where each cell has a different component, each represented by a 2 character long string. The factory will be constant for the KoTH, and is the following 2D list (coordinates are shown around for reference):

    0     1     2     3     4     5     6     7     8     9    10    11    12
0 [['  ', '  ', '> ', '  ', 'vv', 'C2', '  ', '  ', '  ', '  ', '^^', '  ', ' ' ],
1  ['  ', '  ', '  ', '  ', 'vv', '  ', 'lv', '< ', 'l<', '  ', 'R^', '<<', '<<'],
2  ['  ', '  ', '  ', '<<', 'R<', '  ', 'v ', '  ', '^ ', '  ', '  ', '  ', '*v'],
3  ['  ', '  ', '  ', '  ', '  ', 'lv', 'r<', '  ', 'r^', '< ', '< ', 'l<', '  '],
4  ['PA', '  ', '  ', '  ', 'lv', 'r<', '  ', '  ', '  ', '  ', '  ', '^ ', '  '],
5  ['  ', '  ', '  ', '  ', 'v ', '  ', '  ', '  ', '  ', '  ', 'r>', 'l^', '  '],
6  ['  ', '  ', '  ', '  ', 'l>', '> ', '> ', 'rv', '  ', 'r>', 'l^', '  ', '  '],
7  ['  ', '  ', '  ', '  ', '  ', '  ', '  ', 'v ', '  ', '^ ', '  ', 'R>', '>>'],
8  ['  ', '  ', '  ', '>>', '>>', 'Rv', '  ', 'l>', '> ', 'r^', '  ', '^^', '  '],
9  ['  ', '  ', '> ', '  ', '  ', 'vv', '  ', '  ', '  ', '  ', 'C1', '^^', '  ']]

We will use compass directions in the explanations to refer to the direction a bot is facing, with "North" being the top of the factory (so \$(0, 0)\$ is the North-West corner).

This is fairly complicated, so we'll go over what each string means:

  • : This is just a blank square. Nothing special happens.

  • C1/C2: Checkpoints 1 and 2. You must visit Checkpoint 1 first, then Checkpoint 2. The first bot to do both wins.

  • > /< /v /^ : These are conveyer belts. At the end of each "register" (explained below), they move any robot on them one square in the corresponding direction.

    • For example, if a bot is on \$(5, 6)\$ at the end of a register, it is moved to \$(6, 6)\$.
  • r>/r</rv/r^/l>/l</lv/l^: These are corner conveyer belts. If pushed onto these squares by a conveyer belt, the bot is rotated 90 degrees clockwise (rX) or counter clockwise (lX). At the end of each register, any bot on them (not bots that were just moved onto them) is moved one square in the corresponding direction.

    • For example, if a bot is moved from \$(6, 6)\$ to \$(7, 6)\$ while facing North, it is rotated 90\${}^\circ\$ clockwise and now faces East.
    • If this same bot then doesn't move during the next register, then it is pushed South to \$(7, 7)\$, facing East.
  • >>/<</vv/^^: These are double conveyer belts. If a bot is on one of these at the end of a register, it is moved once in the corresponding direction, and the conveyer square it lands on then moves it a second time

  • R>/R</Rv/R^: These are corner double conveyer belts, specifically right turn corners. As with normal right corner conveyer belts, they rotate a bot 90\${}^\circ\$ clockwise when pushed on to, but they then immediately move the bot in the corresponding direction.

    • For example, a bot facing South who ends a register on \$(11, 1)\$ would be pushed once to \$(10, 1)\$, rotated to face West, then pushed to \$(10, 0)\$.
  • *v: This is the Reboot square. If a bot moves off the board, it is "rebooted": it receives 2 Spam cards, is placed on this square and all remaining instructions are ignored for this round. The bot is now facing South, and, if another bot is rebooted while a bot is on this square, the first bot is pushed one square to the South.

  • PA: This is the Priority Antenna. It cannot be moved, you cannot move into the square, and is used to determine who acts first each round.

Gameplay

Gameplay is very simple. The game is broken into rounds, and one round is structured as follows:

  • First, play order is determined. Bots act in inverse order to their Manhattan distance to the Priority Antenna, with ties broken by the bot with the most "horizontal" (East-West) distance going first.
  • Then, each bot is dealt 9 "programming cards" from their hand (initially 20, but it can grow). Each "programming card" contains a single instruction for the bot (e.g. Move 1, Left Turn, etc.). The bots then simultaneously* each choose 5 cards, discard the other 4, and order the 5 chosen from 1st to 5th.
  • There are now 5 registers, one for each chosen card. A register proceeds as follows:
    • The card for each robot for that register is revealed, and the instructions are executed in play order.
    • Once all instructions are resolved, the conveyer belts all activate, potentially moving any bots.
    • Then, each bot fires a laser, in a straight line in front of it, until it either hits another bot, a wall, the Priority Antenna or misses all other bots.
    • If a bot is hit by a laser, it receives a Spam instruction, which is added to its "programming cards".
    • If a bot is on Checkpoint 1, it is now able to visit Checkpoint 2 to win. If it is on Checkpoint 2, it wins.
    • The next register begins, and the process is repeated.
  • After all 5 registers are completed, and everything is resolved, each deck of programming cards are reshuffled with all programming cards, and the next round begins.

If a bot moves into the same square as another bot, that bot is pushed back one square in the direction the first bot is moving. For example, if Bot 1, facing East, moves from \$(7, 4)\$ to \$(8, 4)\$, and Bot 2 is already in \$(8, 4)\$, then Bot 2 is pushed to \$(9, 4)\$. Note that, if pushing a bot would push it into the space of another bot, both are pushed.

*: For the purposes of the KoTH, each bot will be given their cards, and will return their chosen instructions in some arbitrary order.

Programming Cards

Each bot has a deck of programming cards, initially 20. The decks are all identical, and consist of:

  • 3 Move 1 cards: the bot moves forward one square
  • 2 Move 2 cards: the bot moves forward exactly two squares
  • 2 Move 3 card: the bot moves forward exactly three squares
  • 3 Right Turn cards: the bot stays in place, and rotates 90 degrees clockwise
  • 3 Left Turn cards: the bot stays in place, and rotates 90 degrees counter clockwise
  • 3 U-Turn cards: the bot stays in place and rotates 180 degrees
  • 2 Move Back cards: the bot moves moves backwards one square, without rotating
  • 2 Again cards: the bot repeats the previous instruction
    • Note that these don't "stack": playing an instruction, followed by 2 Agains does the instruction a total of 3 times, not 4

Additionally, bots can increase the number of cards in their deck by taking damage from lasers, or by rebooting. In this case, they receive Spam cards, which are added to their deck:

  • Spam cards: a random card from the bot's programming deck is chosen, and that is the instruction carried out this register. At the end of the round, the Spam card is removed from your programming deck.
    • Note that this does stack: if the drawn card is a Spam card, you repeat until a non-Spam card is drawn. All drawn Spam cards are removed from your deck.

Starting positions

Finally, we come to the start. At the very beginning of the game, the 6 players are placed on the 6 starting positions, in a random order. The positions are \$(1, 1)\$, \$(0, 3)\$, \$(1, 4)\$, \$(1, 5)\$, \$(0, 6)\$ and \$(1, 8)\$. Each bot may choose which direction they begin facing.


Challenge

You are to write a function in Python 3 that takes the following arguments:

  • round: an integer, beginning at 0, counting what round the game is on
  • order: an integer from 1 to 6, indicating the bot's order of play, with 1 being first and 6 being last
  • position: a 3-tuple (x, y, d) consisting of your zero-indexed coordinates in the factory, and a character, one of NESW, indicating the direction you're facing
  • score: a boolean, indicating whether you have landed on Checkpoint 1 yet.
  • cards: a list of 9 two character strings, indicating the cards you've been dealt
    • M1/M2/M3/MB indicate Move 1, 2, 3 and Back respectively
    • RT/LT/UT are Right, Left and U-Turn
    • Ag/Sp are Again and Spam
  • bots: a list of 3-tuples (x, y, d) of the coords and directions of all other bots
  • factory: the factory matrix above.

It should then return the following:

  • If round is 0, it should return one of N/E/S/W to indicate its starting direction
  • Otherwise, it should return a list of up to 5 of the strings from cards, indicating its registers. Note that the first element of this list will be the first register, the second the second and so on. If you return fewer than 5 strings, the list will be filled with randomly drawn cards from your programming deck that weren't in cards until there are 5 elements.

Once the first bot finishes a register on Checkpoint 2, after its score is True, the game is finished, and the winner receives 1 point.

Scoring

Every combination of 6 bots will play 3 games together. The winner of a game receives 1 point, and the bot with the most number of points after all the games wins.


Example Bots

Sandbox note: once I've written the controller, I'll add in a couple basic example bots

random_bot

A completely random bot, it shuffles the cards dealt and returns the first 5:

import random

def random_bot(round, order, position, score, cards, bots, factory):
	if round == 0:
		return random.choice('NESW')

	random.shuffle(cards)
	while cards[0] == 'Ag': random.shuffle(cards)
	return cards[:5]

Example round

*to be added*


Sandbox

  • Thoughts?
  • Is this clear enough?
  • The original game of RoboRally is super dynamic. I worry that bots may not be able to handle that without being super complex. Thoughts?
  • Is this a dupe?
  • Tags are , , , and . Suggestions?
  • Any further feedback?
\$\endgroup\$
6
  • \$\begingroup\$ @cairdcoinheringaahing maybe add some examples? No need for an exampple bot, just an example round... \$\endgroup\$ Jun 4 at 2:04
  • \$\begingroup\$ @cairdcoinheringaahing so the board isn't random but is that already? ok \$\endgroup\$ Jun 4 at 2:04
  • 1
    \$\begingroup\$ @Nobody No, the board is not random, and stays fixed throughout the game. Bots are given access to it so that people don't have to code in what each square does to their bot. Yes, I can add an example round in a bit \$\endgroup\$ Jun 4 at 2:15
  • \$\begingroup\$ Just to remind you again to add an example round and bot and controller function and stuff. I don't quite understand everything. \$\endgroup\$ Jun 7 at 5:33
  • \$\begingroup\$ Just to remind you yet again to add an example round and bot and controller function and stuff. I don't quite understand everything. \$\endgroup\$ Jun 17 at 1:04
  • \$\begingroup\$ Thoughts: Nothing except seriously add the example Clear enough: Probably, with an example Dupe: Probably not Tags: Good to go. I don't really think tag random is **needed**, but alas... Further feedback: Why a static board? Why the same board always? You can either resolve the edge cases or simply make it not happen; I think it is more interesting that way. \$\endgroup\$ Jun 17 at 1:12
6
\$\begingroup\$

Note: If you are seeing this first, you might want to sort by active.

Unhappy numbers ascii art

Draw a square (or a rectangle as close to a square as possible) that represents the cycle of an unhappy number.

[ short description of unhappy numbers here + example ]

[ square formating rules ]

Input

Unhappy integer.

Output

ASCII art.

Example

Input:
4
Output:
 4 -  16 - 37 
20         58
42 - 145 - 89
\$\endgroup\$
6
  • \$\begingroup\$ The cycle of an unhappy number is a constant. \$\endgroup\$
    – J B
    Mar 7, 2011 at 23:42
  • \$\begingroup\$ @JB: thanks, I will rephrase the question. I didn't mean the 4 cycle. (Why did I chose 4 as an example? :/ ) \$\endgroup\$
    – Eelvex
    Mar 8, 2011 at 4:56
  • \$\begingroup\$ @Eelvex This is an nice challenge. Are you still interested in finishing it? \$\endgroup\$
    – J Atkin
    Feb 7, 2016 at 19:06
  • 1
    \$\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 2 weeks if you have any objections and would still like to finish and post this challenge yourself. \$\endgroup\$
    – J Atkin
    Feb 10, 2016 at 0:19
  • \$\begingroup\$ @JAtkin, no objections. \$\endgroup\$
    – Eelvex
    Feb 12, 2016 at 11:20
  • 1
    \$\begingroup\$ If this was posted, can you please delete it? \$\endgroup\$
    – MD XF
    Aug 17, 2017 at 16:58
6
\$\begingroup\$

Scribble Pad for Nerds.

Posted Here

\$\endgroup\$
6
  • \$\begingroup\$ I suggest allowing a matrix of characters as output too (relevant meta). Maybe even allow a boolean matrix as output? \$\endgroup\$
    – pajonk
    May 29 at 17:22
  • \$\begingroup\$ @pajonk Ah yeah, thanks! \$\endgroup\$
    – mathcat
    May 30 at 19:11
  • 1
    \$\begingroup\$ Maybe Give Examples for intersecting lines or diagonal lines? \$\endgroup\$ May 31 at 0:25
  • \$\begingroup\$ @Nobody finished! \$\endgroup\$
    – mathcat
    Jun 3 at 18:02
  • 1
    \$\begingroup\$ The [6, 4, 2] example is unclear. If each movement draws 2 #s, why are there 7 total #s? I'm guessing that the board begins with 1 # already drawn, and instructions start from there, but this isn't made clear. In fact, if so, the image for the [6, 4, 2] explanation is wrong, as it says "start at the X", when the X is one space too far to the right. Also, I believe you have left and right mixed up with 2 and 6 in the explanation? \$\endgroup\$ Jun 4 at 18:01
  • \$\begingroup\$ @cairdcoinheringaahing oh frick yeah, I'm gonna fix it later, thanks \$\endgroup\$
    – mathcat
    Jun 4 at 19:31
6
\$\begingroup\$

Create Bernard from Desmos

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Might want to include this animation for understanding the algorithm as listed. However, that algorithm is a bit complicated because it describes the reason for the pattern forming; you could keep it at the end, but I'd suggest describing the result matrix in terms of rectangles: Quadrants 3 and 4 are filled with 1s, as well as quadrant 1.1 and 1.2, then recurse on quadrant 1.4. (where quadrant a.b is the bth quadrant of the ath quadrant, and quadrants are numbered counter-clockwise starting from 1=top right quadrant) \$\endgroup\$ Jun 16 at 7:15
  • \$\begingroup\$ Please take a screenshot of bernard in case this specific manifestation of the bug is fixed or changed, for posterity \$\endgroup\$ Jun 17 at 3:43
  • 1
    \$\begingroup\$ @thejonymyster OK will do \$\endgroup\$
    – Aiden Chow
    Jun 20 at 7:02

You must log in to answer this question.

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