Sandbox for Proposed Challenges

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

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
• 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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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!

To raise $$\ e /extract_tex] to the power of a matrix code-golfmathmatrix Inspired by this 3Blue1Brown video Given a square matrix $$\ M /extract_tex], compute $$\ \exp(M) \$$, which is defined as $$\exp(M) = \sum_{r=0}^\infty \frac {M^r} {r!} = M^0 + M^1 + \frac 1 2 M^2 + \frac 1 6 M^3 + \cdots + \frac 1 {n!} M^n + \cdots$$ where $$\ n! \$$ represents the factorial of $$\ n \$$, and $$\ M^0 \$$ is the identity matrix for the dimensions of $$\ M \$$. You must compute this infinite sum until its value converges to the extent that it no longer changes within your language's available precision (typically a float or double). If your language provides only infinite-precision numeric types, it is ineligible for this challenge. There are other ways to compute this, which you may use, as long as the result is precise???? Test cases Coming soon - I wanted to post this early so I don't get sniped by any other 3b1b viewers! Rules • $$\ M \$$ will be square and have dimensions between 2x2 and 8x8 • The elements of $$\ M \$$ will all be integers $$\ -20 \le x \le 20 \$$ • You may take $$\ M \$$ as a nested array, a flat array with separate • Standard loopholes are forbidden • Standard I/O rules apply • This is , so the shortest code in bytes wins Meta • Is this clear enough? • Is this a duplicate? • Is the rule about convergence actually a terrible idea? • Any other feedback? • why not require exact calculation, it makes for a harder challenge but a more interesting one – rak1507 Apr 1 at 19:54 • @rak1507 it's irrational so an exact value can't be calculated – pxeger Apr 1 at 19:55 • looked like there were methods on wikipedia but I could be wrong – rak1507 Apr 1 at 21:45 • 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. – xnor Apr 2 at 6:30 • 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\. – xnor Apr 2 at 6:38 • @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 – pxeger Apr 2 at 6:50 • 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. – xnor Apr 2 at 7:03 • 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.) – Bubbler Apr 4 at 23:28 Quoted rational numbers Battery charging tracker If there are any better titles please post them in the comments If any more tags might be appropriate, please post them in the comments The task here is to create a program which can output a battery's percentage at all times. It will be given input in the form of an array of "indications". These dictate when to plug and unplug the charger. If this sounds confusing, let us take this sample input: [[12, 23, 34], [15, 28, 67]]  Note: you can take input in the form of a list of strings or a single string if you would like. The first array indicates the number of seconds to wait before unplugging the charger, and the second one indicates the number of seconds to wait before plugging in the charger. There will never be two coinciding values in one of the arrays or between the arrays. So [[11, 22, 33], [15, 22, 34]] is not valid input and neither is [[1, 2, 3, 3, 6], [15]]. Both arrays are guaranteed to have at least one value in them. Also, all values are positive non-zero integers. The "battery" we are trying to simulate starts with 0%. When your program runs, the charger is automatically "plugged in", and each second the charge should tick up by 1% if the charger is plugged in, and decrease by 1% if it is not. Each second, the program should output the amount of charge the battery has. It should not charge beyond 100% and should not go down below 0%; if the battery hits 100% then it will stay there until the charger is unplugged and if it hits 0% it will stay there until the charger is plugged in. In addition, your program should store a "second counter" containing information on how long the program has been running for. When this counter hits any of the integers in either of the input arrays, the charger will be either unplugged or plugged in depending on which array it was in. It is guaranteed that between two "unplug" events there will be at least one "plug" event and vice versa, and it is also guaranteed that the first event is "unplug". Whenever the charger is unplugged or plugged, a "U" or "P" should be shown, respectively. In the case of our sample input, the charger is "unplugged" when the counter reaches twelve, 23 or 34 seconds and is "plugged" when the counter reaches fifteen, 28 or 67 seconds. What, then, is the output of our example? 1 2 3 4 5 6 7 8 9 10 11 12 U 11 10 9 P 10 11 12 13 14 15 16 17 U 16 15 14 13 12 P 13 14 15 16 17 18 U 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  To be clear, the first zero should not be outputted, the charger is acted on after the corresponding second, meaning that we wait 12 seconds before unplugging the charger; the 12th second does not happen after the charger is unplugged. The program runs for the highest value in the input array, in this case 67. The question is so the shortest answer in bytes wins. Standard loopholes are not allowed here. • You should clarify that the program does not need to wait 1 second between each output (assuming that is the case). Also, title suggestion: Battery charging tracker or something along those lines? – pxeger Apr 5 at 17:17 • @pxeger thanks for the suggestion, the program should wait 1s between each output except for the U or P indicators – ophact Apr 5 at 17:33 Draw the flag of Bangladesh The flag of Bangladesh is very simple. It looks like below: The flag will be in bottle green (#006a4e) and rectangular in size in the proportion of length to width of 10:6, with a red circle in near middle. The red circle will have a radius of one-fifth of the length of the flag. This image will help you to understand the proportions properly: In this Graphical output challenge, you need to draw the flag of Bangladesh like first image. Standard loopholes apply, Shortest code wins. Resolution cannot be 0px, or echo style answers not supported. Minimum resolution is 286*176 • I think you need to state a minimum resolution. – Adám Apr 12 at 8:28 • @Adám what do you mean by minimum resolution? – Wasif Apr 12 at 8:29 • If my output is 0px tall, then the width has to be 10×0px÷6=0px wide, and the red circle's diameter has to be 4×0px÷6=0px. Easy; here you go: – Adám Apr 12 at 8:31 • You should also specify what the colours are and/or if an exact colour match is acceptable. – Adám Apr 12 at 8:32 • Is ASCII art acceptable? – Adám Apr 12 at 8:33 • @Adám ascii art is not acceptable, also in place of bottle green (#006a4e) dark green is acceptable, if you have more flaws come to chat – Wasif Apr 12 at 8:35 • You had specified the color of green background. So what is the color for the circle? – tsh Apr 13 at 3:52 • @tsh I suppose it is #f42a41 – Adám Apr 13 at 7:46 Saboteurs in our Halls This is a challenge, where one member on each team attempts to sabotage their team in secret. Similar to Red vs. Blue - Pixel Team Battlebots, bots will be divided into teams, based on the user ID number of the user who posted them. Your user ID can be found by navigating to your profile (click your icon in the top bar) and looking at the URL: https://codegolf.stackexchange.com/users/[user-id]/[display-name]  For example, my user ID is 66833: https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing If your ID is an even number, then you are on the Red team. If your ID is an odd number, then you are on the Blue team. There is no way to change teams. As you cannot change your user ID, and to prevent one team flooding the field with bots, each user may only submit one bot How the KotH will work At the start of the game, each bot will be placed in a random cell in a $$\1000\times1000\$$ cell grid. No bot will be placed on the same cell as another bot, or within 5 cells of another bot. Additionally, $$\999\$$ random cells will be filled with 1 food. These cells may be any cell on the board that doesn't contain a bot. The aim of the game is to collect food. Each bot will navigate their way around the grid, attempting to gather food. The team with the most food at the end of the game wins. However, one bot will actually be a saboteur. This bot will appear to be a member of one team, but will instead act in a manner that helps the other team. When writing your bot, you should consider the existing bots on the opposing team and try to write in a sabotage tactic that will help them without being overly obvious. Let's say that for this specific match, the saboteur is Blue. Their actions should aim to help the Red team win, while not giving themselves away to the Blue team. If either team suspects that bot to be the saboteur, they can then act in a preventative manner towards that bot. If Blue wins, the saboteur has failed, and so will get no points when the rest of Blue does. If Red wins, then the saboteur has succeeded, and thus gets 2 points. No matter which team the saboteur is on, each member of the winning team always gets 1 point. Which bot is the saboteur is randomly chosen at the start of the game and remains constant until the game ends. There is only ever one saboteur per game. The game is broken up into turns. Each team acts on alternating turns, so Red moves, then Blue, then Red etc. or the other way around. Each turn, each bot will be passed a list of game data, detailed below, and will return an integer between $$\1\$$ and $$\9\$$ inclusive, indicating which direction it would like to move in: The bot is at $$\5\$$ before moving. The bots for each team are called in a random order each turn, but none of them move until they all have returned values. After all bots in a team have returned their movement choice, all moves happen at the same time. If two bots on the same team attempt to move into the same cell, neither bot moves. If a bot tries to move out of bounds, nothing happens. If a bot moves into a cell with food, it adds that piece of food to the amount it has already gathered. Initially, all bots have gathered $$\0\$$ food. If a bot moves into a cell containing an enemy bot, the two bots fight. The winner is determined by which bot has gathered the most food. The winner then "steals" the losers food, adding it to their total gathered food. The loser is then removed from the board and re-placed at a random location not within 5 cells of another bot, and with an initial $$\0\$$ food again. If both bots have the same amount of food, then both bots are removed and re-placed, and any food they had is randomly placed in empty cells around the board. After $$\10000\$$ turns, the game ends. Each team has their total gathered food counted, and the team with the most food wins. The actual competition will have $$\100\$$ games played. If a team wins a game, each team member receives 1 point. However, if the saboteur's team (the one it's on, not the team it's helping) wins, the saboteur does not get this point. If the saboteur's team loses, the saboteur gains 2 points. The team with the most total points of all its bots at the end of $$\100\$$ games wins. How to answer You should include in your answer 2 functions: move and sabotage. move is the function that will be called each turn when you aren't the saboteur and sabotage will be called each turn that you are the saboteur. Both functions will receive the same arguments: • x and y. The x and y coordinates of your bot, each an integer between $$\0\$$ (top-left corner) and $$\999\$$ (bottom-right corner). • food. The current amount of food you are carrying. Initially 0, and changed by the controller for you when necessary. • t_near. A list of bots on your team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x and y coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster. • e_near. A list of bots n the opposing team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x and y coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster. • f_near. A list of coordinates of all food within a square, side length 33 cells, centered on you. Each food is represented by a pair [x, y] representing it's coordinates • team_chat. A list of all chat messages sent between your team. Messages In order to allow inter-game cooperation, each team will have a "chat" ability. Each bot will be passed team_chat, an array containing the chat history of that team - i.e. a series of strings saying more-or-less whatever you want. The most recent message will be at the end of the array. Each bot may, on each turn, append up to 3 messages to the chat. Each message must be no longer than 100 characters, and will be prefixed with the ID of the bot who sent it (with a space after the ID). For example, if a bot with a user ID of 1234 sent Hello, World! to the chat, the message would be 1234 Hello, World!. Example Submission This is Joey. Joey isn't too smart, and hasn't got the hang of proper sabotage. If not the saboteur, Joey just hunkers down and waits for the game to end. Otherwise, he moves around the board aimlessly in random directions: import random def move(x, y, food, t_near, e_near, f_near, team_chat): return 5 def sabotage(x, y, food, t_near, e_near, f_near, team_chat): return random.randint(1, 9)  Rules Any attempted gaming of the rules will lead to a disqualification of your bot. If you break any rules, your bot will be disqualified until it is fixed (if possible). • You may only edit your answer within 12 hours of posting to prevent answers that continually optimise against new bots. You may not delete and repost your answer in order to try to circumvent this restriction • Your code must not take longer than half a second (give or take a few milliseconds) to return its move • You may not attempt to modify the controller or other bots' code; attempt to communicate outside of using the team chats; make web queries; or do anything malicious. I'll keep an eye out for other unsportsmanlike behaviour, such as stealing code verbatim from other answers or using sock puppets to mess with the other team. You are welcome to collaborate and scheme with your team, but keep the contest friendly and ethical. We don't need or want this to devolve into anarchy. You will have 2 weeks from the posting of the challenge to submit bots. After which time, I'll run 100 games with 10000 turns each and determine the winner Meta • Is this clear enough? • Is this a duplicate? • I'm not sure whether to write this in Python or Javascript. On the one hand, I'm better at Python, but Javascript is more popular/used. Thoughts? • Tags are , , . Suggestions? • Any further feedback? • Very nice challenge :) Just one thing: have you considered letting bots know about the food quantity of nearby bots (in t_near and e_near)? I think it could give the saboteur a little more room to do his job (like kamikaze against enemies if they have more food than he does). Otherwise, it seems to me that there aren't many ways for the saboteur to help the enemy team, but maybe I just haven't given it enough thought. – Delfad0r Apr 11 at 16:14 • Also, do you plan to do anything to prevent unbalanced teams (i.e. teams of different sizes)? It seems to me that having one less teammate is almost as bad as having a saboteur in your team, although this is probably because (as I said above) I still haven't found many effective strategies for the saboteur. – Delfad0r Apr 11 at 16:18 • @Delfad0r Yeah, that sounds like a good idea, editing in the food suggestion for t_near and e_near. I'm not sure about dealing with unbalanced teams (it seems as though it wasn't a problem with Red vs Blue, which gives some kinda hope) – caird coinheringaahing Apr 11 at 16:25 • @Delfad0r Nope, that's a mistake - fixed – caird coinheringaahing Apr 12 at 13:32 The Meeker numbers sequence • I've edited the draft a bit, mainly "The Challenge" section to be more in line with the standard [sequence] rules (which is what I think you were going for). I've also cleared up some of the wording. Feel free to revert/rollback if you dislike my changes – caird coinheringaahing Apr 11 at 13:57 R.E.P.A.I.R. T.H.E. K.E.Y.B.O.A.R.D. • This is a very good challenge, apart from one thing - help mode is FAR too overpowered. I could take +, * and h (in Python), and write the password as chr(1+1+1.....) +chr(1+1+1.....) and write all of the characters that way, using multiplication to ease the process. Though, without it, I think this becomes a very interesting challenge, especially for languages like Befunge-98/<><, which would be unable to do as such. An idea would be to ban +/*, or add a penalty for using it, though I'm just throwing ideas around at this point, so take my upvote. – StackMeter Apr 11 at 9:37 • @StackMeter i reduced help mode to take one key only – Wasif Apr 11 at 9:59 • Thanks - that should cover any loopholes. – StackMeter Apr 11 at 10:27 • Are functions/programs allowed to share auxiliary definitions? For instance, if two of my programs need a function for (say) computing the factorial, do I count the bytes of this function once or twice? – Delfad0r Apr 11 at 10:52 • @Delfad0r you have to write seperate programs for different keys, and so unlike your example you have two use the function twice instead of once, and it will doubled in the byte count. But don't worry its not code golf! – Wasif Apr 11 at 11:15 • DISALLOW WHITESPACE!!!!!!!!! I cannot stress this enough. – A username Apr 12 at 9:34 • @Ausername then I'd disallow deadfish~ too – Wasif Apr 12 at 9:42 Make it prime with the smallest suffix Posted • "Your solution must work for the largest integer your language supports" If my language support integers in 0~n. Is this means my program should support all inputs in range 0~n? Or is this means my program should support all inputs when connect it with its output, the result of connection still in 0~n? – tsh Apr 14 at 3:07 • Java has support to signed 64 bit integers as long type. But Java also have java.math.BigInteger support. By saying "largest integer your language supports", does it means I must working on BigInteger instead of long or int types? – tsh Apr 14 at 3:11 • @tsh my intent here was that Java users would have to do that, yes. Considering that java isn't that popular of a golfing language to begin with, I'm not really concerned about the insane verbosity that brings. I am, however, considering bringing the cap to \2^{53}-1\ since that's the largest odd integer that can be represented with double-precision floats. – Beefster Apr 14 at 16:05 Posted • There's many challenges which have this as a subproblem, but no exact dupe I could find. – Razetime Apr 12 at 5:34 • Presumably, code-golf? And add decision-problem array-manipulation – pxeger Apr 12 at 6:45 • Heh, lots of solutions to this exact problem were presented at the recent APL conference. – Adám Apr 12 at 8:29 • Given how trivial this is, I'd suggest just limiting it to digits 1 to 9, as the overall approach isn't going to change much in list-based languages, but it'll allow string based languages (e.g. Retina) to compete better/easier. Also, as far as I can tell, this is, somehow, not a dupe – caird coinheringaahing Apr 12 at 13:09 Sr. 4Der says make this shape! (Episode 1) • I feel like it might be better if the answerers just chose the character they wanted to use, and then this would be a kolmogorov-complexity challenge. – user Mar 25 at 13:18 • "Adjust the size if needed" isn't a very precise requirement. What's the smallest valid solution? What are the necessary and sufficient requirements for a solution to be valid? – 79037662 Mar 25 at 14:26 • I've edited this down to a stub now that it's been posted to save space – caird coinheringaahing Apr 22 at 0:25 Leave a wake of dead cells behind you • What if this is impossible? – Beefster Mar 24 at 15:44 • @Beefster Then I'll happily accept a proof of impossibility – caird coinheringaahing Mar 24 at 16:24 Quote a rational number Sum over an Interval • I'd suggest just describing the input format ("begins with either ( or [, then 2 integers separated by a comma, ends with either ) or ]") as it's clearer. Related, but not a duplicate. Additionally, will the input always be positive (or non-negative) integers, and will the range ever be empty? – caird coinheringaahing Apr 20 at 18:58 • @cairdcoinheringaahing fixed – Underslash Apr 20 at 21:02 Best Rolling Ao5 • I'd suggest removing [rubiks-cube] and replace it with [array-manipulation and [floating-point]. I'd also recommend not requiring a trailing 0 if the output is only 1 decimal place (e.g. 28.3 for the last example) and mentioning that the sets are overlapping ("computing the ao5 for each overlapping set of consecutive five times") – caird coinheringaahing Apr 19 at 22:26 • @cairdcoinheringaahing I want to keep the trailing zeros because that's how all times are displayed in official results. Does that make sense – qwr Apr 21 at 3:24 Is this number part of a Collatz prime sequence? A fast step of the Collatz sequence is defined as $$s_\mathrm{Collatz}:\mathbb{N}_\mathrm{odd}\to\mathbb{N},\quad n \mapsto \frac{3\cdot n+1}{2}.$$ Given an odd positive integer $$\n\in\mathbb{N}_\mathrm{odd}\$$, your task is to decide whether or not both $$\n\$$ and $$\s_\mathrm{Collatz}(n)\$$ are prime numbers. Your program should output two distinct and unique values to represent truthiness and falseness, whereby falseness may also be represented by signalling an error. Since $$\n+\frac12(n+1)=n+\lceil\frac n2\rceil\$$ for odd $$\n\$$, the sorted sequence of all numbers which result in truthiness in the above sense is equal to the tail of A158709. Test cases -8 -> - ; undefined behavior 1 -> false ; (3*1 +1)/2 = 4 is not prime 3 -> true ; (3*3 +1)/2 = 5 is prime 5 -> false ; (3*5 +1)/2 = 8 is not prime 7 -> true ; (3*7 +1)/2 = 11 is prime 11 -> true ; (3*11+1)/2 = 17 is prime 15 -> false ; 15 is not prime 91 -> false ; (3*91+1)/2 = 137 is prime, yet 91 is not 97 -> false ; (3*97+1)/2 = 146 is not prime  • What is the definition defining? Is \p\ a Collatz prime iff it's a prime and \\frac{3p+1}2\ is a prime? If \p\ a Collatz prime iff it's a prime and \\frac{2p-1}3\ is a prime? Or is a prime Collatz if either of those conditions hold? – Peter Taylor Sep 13 '19 at 10:56 • @PeterTaylor are they not the same thing? – Pureferret Sep 13 '19 at 11:09 • Alternative phrasing: which of \p_1\ and \p_2\ are you calling a Collatz prime? – Peter Taylor Sep 13 '19 at 11:11 • @PeterTaylor I mean \p_1\ – Pureferret Sep 13 '19 at 11:22 • So neither the input prime nor the Collatz prime need to be prime? – Jonathan Frech Sep 17 '19 at 7:56 • "Input MAY be non-prime, in which case the output is always false (see 15)" -- did you specifically define this behavior or why is the above the case? – Jonathan Frech Sep 17 '19 at 8:00 • @JonathanFrech I'm (personally) only interested in going from prime to prime, but I wanted to define the haviour for non-prime input. When I say 'may be non-prime' I mean, it should be able to handle it, it's an allowed/expected input but not one that gives a True output. – Pureferret Sep 17 '19 at 10:55 • To me it feels like an unnatural extra constraint. – Jonathan Frech Sep 17 '19 at 12:54 • @JonathanFrech it's just defining how to behave with certain inputs. – Pureferret Sep 18 '19 at 9:12 • Citing Exceptional edge cases; such out-of-place definitions are generally frowned upon. – Jonathan Frech Sep 18 '19 at 9:56 • @JonathanFrech I've changed the initial ask, and now it shouldn't be an exception – Pureferret Sep 18 '19 at 10:23 • Cf. A158709. – Jonathan Frech Sep 18 '19 at 10:53 • @JonathanFrech Do you think this is postable? – Pureferret Apr 27 at 1:17 • cf. Things to avoid when writing challenges: Prime numbers. Unless there's a mathematical way to avoid any of the existing golfed primality test methods, a task involving primality test is not very interesting. – Bubbler Apr 28 at 6:09 • @Pureferret I would not post it -- unless you can think of an interesting golf opportunity. You could, however, improve the problem at hand: there are many questions one can ask about Collatz trajectories. And if you ask for something along the lines of "decide if the given number is a multiple of the length of its Collatz trajectory", you get a less arbitrary connection of concepts whilst preserving the topic of divisibility. – Jonathan Frech Apr 28 at 14:28 Reject tab, return to linefeed • How exactly are "printing" and "returning" distinguished? Are submissions required to be a function that also outputs to STDOUT in addition to returning a value from the function? Also, I would strongly advise against subjective criteria like having an error message related to tabs, unless they are purely for brownie points; point bonuses, especially ones that can't be judged objectively, are discouraged. – hyper-neutrino Apr 17 at 17:26 • Printing and returning can be considered identical to each other for the purposes of this challenge. – StackMeter Apr 17 at 18:58 • I've edited this down to a stub now that it's been posted to save space – caird coinheringaahing Apr 28 at 14:15 Solve the Alien Probe puzzle code-golfarray-manipulation • The description was clear to me, without watching either video. Doesn't seem like the wording needs much improvement. – Redwolf Programs Apr 28 at 13:54 Drawing the Mathematics Stack Exchange logo (ASCII Logos 2) The goal is to create the Mathematics Stack Exchange logo using ASCII characters. It looks like this. The exact output should look like this:  _ /=/ \=\ /=/ \=\ | | |\=\ /=/| | \=\ /=/ | | | | _ | | | _ /=/ \=\ \=\ | /=/ /=/ \=\ /=/ \=\ \=\|/=/ /=/ \=\ | | | | | |\=\ /=/| |\=\ /=/| | \=\ /=/ | | \=\ /=/ | | | | | | | | | | | | | \=\ | /=/ \=\ | /=/ \=\|/=/ \=\|/=/ /=/ | \=\ /=/ | \=\ | | | | |\=\ /=/| |\=\ /=/| | \=\ /=/ | | \=\ /=/ | | | | | | | | | | _ | | | \=\ | /=/ /=/ \=\ \=\ | /=/ \=\|/=/ /=/ \=\ \=\|/=/ | | | | |\=\ /=/| | \=\ /=/ | | | | | | | \=\ | /=/ \=\|/=/ |  You must make sure the cubes should be symmetrical just like the original logo, and must make space to create a 6-point star in the middle. Yes, the output looks messed up, but it's all I can do to really make a shape. Remember, 6 boxes aligned as a hexagon. Can you draw it with the least bytes possible? Tags: , Any suggestions? If this question reaches a score of 4, it will be posted on 12:00 PM UTC, 1 month after Stack Overflow's. KoTH - JS WarBots Based on King of the Hill: Robot Battle Rules and Instructions Program a bot as an object in JavaScript. The functions that can be called are: • left(name) Moves left 1 unit (x position -1) • right(name) Moves right 1 unit (x position +1) • up(name) Moves up 1 unit (y position -1) • down(name) Moves down 1 unit (y position +1) • forward(name) Moves forward 1 unit (z position -1) • backward(name) Moves backward 1 unit (z position +1) • mine(name) Places a mine at current position (bots can be blown up by their own mines, with a 1 tick delay before priming) • scan(name) Scans for mines and players in adjacent cells (cells a bot can move to). Returns an array [left, right, up, down, forward, backward]. Each element can be 0 (nothing there) 1 (mine) 2 (other bot). • pass(name) Do nothing name is the name of the bot. Any bot whose action's name is not the name of the bot will be disqualified (if your bot is called "Foo" you must have pass("Foo") and not pass("foo") or pass("Bar")) The 3D arena is a 1000x1000x1000 cube, centered at (0,0,0). Each turn of a game, every bot must select one of the above actions to perform. Every 10 turns (subject to change) minesweeping will occur, removing 50% of the existing mines to reduce camping. A bot is eliminated from a game if: • It is in the same position as a mine. • It exits the game area. • It collides with another bot (both bots are eliminated). • The cell that it occupies does not have integer coordinates ((0,0,0) is valid, (0.5,0,0) is not) Scoring After 1000 turns, if a bot is not eliminated, it receives Math.floor(1000/bots) points, where bots is the number of bots left. If a bot eliminates another bot by mining it, it receives 100 points. If there are no bots left after 1000 turns, nobody gets any points. Formatting your bots Here are examples of bots (These will be playing too!): RandomBot var RandomBot = { // Same name as the name property name: "RandomBot", x: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0. y: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0. z: Math.floor(Math.random() * 1000 - 500), // If unspecified, defaults to 0. turn: () => { var action = Math.ceil(Math.random() * 9) if (action == 1) { left("RandomBot") } else if (action == 2) { right("RandomBot") } else if (action == 3) { up("RandomBot") } else if (action == 4) { down("RandomBot") } else if (action == 5) { forward("RandomBot") } else if (action == 6) { backward("RandomBot") } else if (action == 7) { mine("RandomBot") } else if (action == 8) { scan("RandomBot") } else { pass("RandomBot") } } }  May the best bot win! The challenge will be posted later when it receives sufficient votes and the controller is developed. If there are any questions regarding this challenge, please comment about it. • Is there anything preventing a bot from placing six mines around itself, then never moving? – Redwolf Programs Apr 30 at 16:03 • @RedwolfPrograms Do you have any suggestions on preventing that? – fasterthanlight Apr 30 at 16:33 • @RedwolfPrograms I've created another rule regarding camping. – fasterthanlight Apr 30 at 16:44 • I think the problem is less camping itself, and more just that I don't think there's very much strategy possible. The current restriction is trivially beatable by just enclosing yourself in a 1x1x2 space and moving back and forth. – Redwolf Programs Apr 30 at 17:41 • @RedwolfPrograms Maybe there should be a limit on how many mines you can place? – fasterthanlight Apr 30 at 17:57 • That could lead to some interesting gameplay, but might actually make the camping problrm worse because it takes very few mines to do. I'd recommend writing a few rough bots on a sheet of paper, and running some games in your head, then seeing what makes it fun and what could use some improvement. I think there needs to be more room to do interesting things; currently there's not really much strategy beyond "don't run into mines". – Redwolf Programs Apr 30 at 18:20 • @RedwolfPrograms I came up with an idea regarding the issue that you brought up. There could be a minesweeper that runs every 10 or so turns where 50% of mines are removed. – fasterthanlight Apr 30 at 19:15 • I think the idea behind that is good, but it has the same problem of being easily fixable by campers, and also removing plenty of mines set up by other players. – Redwolf Programs Apr 30 at 20:39 • @RedwolfPrograms I will consider new methods for the issues in the challenge. – fasterthanlight Apr 30 at 20:43 • Should I move this to chat? – Redwolf Programs Apr 30 at 20:48 • – fasterthanlight Apr 30 at 20:51 • Just wondering, why use functions rather than return values? e.g. having the bot return "left" rather than call left("name"). Also, right now, this just seems like a 3D version of Robot Battle. The three-dimensionality might actually be a bad thing, though, since it makes it harder to trap bots using mines. Like Redwolf, I also encourage you to think about the rules and the strategy of the game to try to allow for more strategy, and to differentiate it from the challenge it's based off of. – Andrew Li May 4 at 2:37 • Also, the camping can be reduced to scanning, going into a corner, placing three mines around you, and waiting. – StackMeter May 4 at 5:54 xkcd 2385 • Now that this has been posted, it should probably be edited down and deleted. – Redwolf Programs May 3 at 1:38 How many Faro Shuffles for a cycle?code-golfarray-manipulationcard-games • @Pureferret it has been! – pxeger May 3 at 13:27 Solve the halting problem for \c^/[^/\*/[^/\*/[^/\\]*$ccode-golfhalting-problem ///, a.k.a. Slashes is an esoteric programming language with simple two operations. One is to output its source to remove from it. The other is to substitute itself. For simplicity I am assuming the case when the program matches \c^/[^/\\]*/[^/\\]*/[^/\\]*$c, which is /pattern/replacement/rest but no more special characters than two slashes.

Given pattern, replacement, and rest of the program, determine whether the program halt or not.

Assume that pattern and replacement are already escaped. Also your program/function/snippet must distinguish two or more characters.

Examples

pattern,replacment,rest: Does it halt?
"","","": No
"foo","foobar","foo": No
"1","0*","110010": Yes


Meta

• Were similar things ever done before?
• /// is turing-complete, so this is not possible – pxeger Apr 25 at 12:33
• Should we simplify it more? – tail spark rabbit ear Apr 25 at 20:23

Produce a range

Your task is to take a list of integers and find inputs to a Python range call to produce that list. That is, output three values (start, stop, step) so that range(start, stop, step) equals the given list.

You can assume that this is possible, which means that consecutive numbers in the list all have the same nonzero difference. Be careful that your code works for negative step sizes, as well as for empty or singleton inputs.

How range works

Python's built-in range produces a list* of equally-spaced numbers. Called as range(start, stop, step), it counts from the start value in increments of step like

[start, start + step, start + 2 * step, ...]


This list continues as long as the value is below stop given positive step, or above stop given negative step. If the start value already fails this test, an empty list is produced. Note that the stop value itself is never included in the list, giving a half-open interval.

range(0, 5, 1)   = [0, 1, 2, 3, 4]
range(0, -5, -1) = [0, -1, -2, -3, -4]
range(0, 2, -1)  = []
range(0, -2, 1)  = []
range(3, 4, 10)  = [3, 7]
range(3, 4, 11)  = [3, 7]
range(3, 4, 12)  = [3, 7, 11]
range(1, -2, 0)  = [1]


*In Python 3, it actually makes a range object, but we'll ignore that distinction.

Test cases

Note that there can be multiple valid inputs. Different stop values can cut off the result at the same point when the step is not ±1. A singleton or empty list can be produced in many ways.

TODO

• Is this return {a[0], a[-1]+sign(a[1]-a[0]), a[1]-a[0]}? – the default. May 7 '20 at 15:43
• @mypronounismonicareinstate I think that works for inputs with 2+ elements, though the empty list and singleton list also need to be handled. Is this too simple for a challenge? – xnor May 7 '20 at 19:32
• (I just noticed this might work in languages with modular indexing) This is probably not too simple, and I like the idea, but it seems like most of the complexity here comes from these special cases. – the default. May 8 '20 at 2:46
• Both Python 2 and Python 3 disagree with step=0 in range. range(1, -2, 0) would raise ValueError instead. Is this intend behavior in this challenge? Also, some languages (Matlab) would support range with floating point values, which some floating point errors may introduced. If you are not aiming to work on floating point errors, maybe add a integer tag. – tsh May 11 at 2:24

Are You My Mother? (very WIP)

(coincidentally, thought up around mother's day)

Oh no! All the newly-hatched ducklings have been mixed together, and they all look the same! The ducklings want to reunite with their own mother. But the mothers are also selfish and want as many ducklings as possible to go home with them. Since all the ducks look the same, the only way to tell who your mother is is by how she acts.

Your task is to write two bot algorithms: one for the mother duck and another for the ducklings.

The game

There are 5 ducklings for each mother duck

All submissions compete at the same time

All of the ducklings line up in a 1-dimensional array in the pond, as do the mother ducks. They do not move around.

Each turn, each duck (either duckling or mother duck) can do one of the following actions:

• Do nothing
• Quack
• Flutter its wings
• Splash
• Spin around
• some other action

Each duckling will see the actions of each mother duck on each turn

After 20 turns, each duckling guesses which half of the mother duck array contains its mother (the upper half will get the mother duck in the middle when there are an odd number of mothers) and the process continues until each duckling has narrowed down to a single mother duck.

Duck(ling) limitations

Ducklings are young and have poor memory. They cannot remember how long they have been lined up and can only remember the last thing each mother duck did when deciding what action to take. The only working memory available to ducklings is a single integer between 0 and 15, inclusive.

Mother ducks have a bit more memory and can remember five integers between 0 and 15, inclusive.

Scoring

Score 1 point for each of your ducklings that went home with its mother. Score 1 point for each duckling (regardless of whose it is) that went home with your mother duck.

• Controller/submission language? (suggesting ecmascript if you haven't already written one) – Wzl May 7 at 23:19
• @Wezl yeah, probably Javascript – Beefster May 10 at 15:53
• The narrowing logic might be a bit unfair if, say, a duckling is unsure about two ducks, but they are in different halves, while another duckling is unsure about two ducks that are next to each other, so has much more time to decide. Plus, I think, 4 bits are very little storage; I'd allow at least 16 or 32 bits, which is a bit more but still limiting. – FZs May 18 at 16:05
• @FZs I've considered the alternative of letting each duckling have 1-on-1 time with each mother duck, after which they can decide whether to go home with her or not. But they do not get a second chance. Not sure how to handle orphan ducklings there though. – Beefster May 18 at 16:19
• And what if the ducklings had to return a mother index on the choice-time? Or if the ducklings had to return an array of mother indices, and on the subsequent turns, it'd only receive info about the ones it chose previously; finally, after n turns, they have to decide? These are just ideas, so you don't have to accept them as they are... – FZs May 18 at 17:38

CGCC sings a song together

• Does "languages can only be used once" mean that each user can only use each language once, or each language can only be used at most one time in the entire challenge? i.e. if Alice uses Language A, can Bob use Language A in his answer? – Andrew Li May 10 at 3:22
• @AndrewLi Each language may only be used on a single answer, regardless of who posts that answer – caird coinheringaahing May 10 at 15:23
• That makes sense, although 74 different languages sounds like a lot, so maybe it would be hard to find "good" languages near the end? I guess that's kind of the point though. I haven't really done any of these challenges so I don't know whether it would get hard to find a language near the end. – Andrew Li May 10 at 16:14

Modify to Increment: Javascript Edition (WIP)

Your task is to insert bytes/characters into the previous answer such that it outputs the next number in sequence, spelled out in English, as its return value. The first answer must output one.

Coding restrictions

Your answer's code must be atomically irreducible, meaning that if it is possible to remove some subset of lexical tokens from the code and have it produce the same output, then it is an invalid answer. Note that this is a distinctly different concept from removing characters from the code, as it treats identifiers, string literals, numbers, and operators as indivisible entities. For the purposes of this challenge, a comment is considered a lexical token, so commenting out parts of the previous answer is not allowed by virtue of this restriction.

Some tokens are not subject to this restriction:

• The declaration keywords let, var, and const
• Semicolons

Note that removing an operator between two tokens does not merge the tokens together into one token, so removing the + from 1+1 would result in 1 1 rather than 11

SANDBOX NOTE: I'm debating whether this should be tightened up to character-wise irreducibility, but I'm thinking that may be too restrictive and be too difficult to chain. On the other hand, quoting and escaping into an ever-growing .substring call seems to be a pretty easily-exploited loophole here. Perhaps a simple bandaid solution would be to ban more than 3 consecutive backslashes. Though perhaps this isn't a problem at all because answers will be trying to make it as hard as possible to chain.

Multi-digit spelling

For numbers above 20, the result should be spelled with multiple words. You may use spaces, hyphens, or underscores to separate words and this does not need to be consistent. (e.g. twenty three can be followed by twenty-four, and one hundred-thirty four is valid even though the spelling looks weird)

Should this challenge reach more than 100 answers, the expected format should be like one hundred thirty six rather than a hundred thirty six. You may optionally insert and between hundred and the next word.

Example

_=>'one'


_=>'twone'.substring(0, 3)


_=>'threewone'.substring(0, 3+2)


_=>'thfoureewone'.substring(02, 3+2+1)


_=>'thfoureewone'.replace('our', 'iv').substring(02, 3+2+1)


Rules and Scoring

• You may not comment out part or all of the previous answer.
• This includes pseudo-commenting such as enclosing code in strings, using the comma operator to no-op parts of the code, or wrapping blocks in if(0)
• The case of the output does not matter (e.g. OnE is just as valid as oNE)
• No third-party libraries or vendor-specific features are allowed. The only features allowed are those found in the ECMAScript standard library as of May 14, 2021.

The first answer to go 7 days (i.e. 168 hours) without a successor is the winner.

• Looks like an interesting challenge idea! I think more formally defining what "pseudo-commenting" entails would help. For example, would [a, b][0] be invalid? What about 0 ? a : b? Also, I think you need to formalize what answers need to output; there are a couple different ways to spell english words. For example, is 147 "a hundred forty seven", "one hundred forty-seven", "one hundred and forty-seven"? etc. – hyper-neutrino May 13 at 19:09
• I think an "irreducible" requirement may help this question. How should multi-digit numbers be spelled? – Razetime May 14 at 11:54
• @Razetime Could you elaborate on irreducibility? The only thing that comes to mind is to require that the solution will not output the correct number spelled out if some subset of characters are removed – Beefster May 14 at 15:17
• yeah that is pretty much the exact definition. – Razetime May 14 at 15:19
• I think strict irreducibility might make it too hard to chain, though it does trivially ban comments and pseudo-comments. – Beefster May 14 at 15:28
• Try x=>'Xforty-two'.slice((function(){/* w h a t e v e r p r e v i o u s a n s w e r w i t h s p a c e s i n s t e r e d i n t o e v e r y 2 c h a r a c t e r s */}+'').length===155) – tsh May 17 at 7:30
• @tsh maybe irreducibility isn't the right solution. Maybe the limitation needs to be a maximum number of characters added. – Beefster May 17 at 14:38
• An alternative would be to make adding to the solution also be atomic, so 'one' cannot become 'twone' – Beefster May 17 at 14:47

Minecraft piston pushing

• might be a good idea to use ^><v instead of P to specify direction, or just specify direction separately. – Razetime May 9 at 2:19
• @Razetime For simplicity, the piston's just going to be pushing up. – A username May 9 at 2:21
• You can make the piston extended, so that answer and test would be different. – okie May 10 at 1:23
• To avoid making it too complicated, I decided to just shift it up 1. – A username May 10 at 7:29
• You should probably add at least one test case where there are slime blocks that are pulling blocks. – hyper-neutrino May 14 at 21:07
• @hyper-neutrino Thanks, will do! Anything else? – A username May 14 at 21:08
• What's the intended behavior for if there is obsidian next to slime? In-game, the obsidian just doesn't move but the slime blocks can still push, but this isn't mentioned here – hyper-neutrino May 14 at 21:08
• @hyper-neutrino Yes, that's what I intended but forgot to specify. – A username May 14 at 21:09

Just Enough Ones

• Looks good to me. Not a big fan of OEIS questions in general, but this is one of the better ones. – Don Thousand May 12 at 19:09

An approximation for factorials of reals

One approximation for factorial function of reals is the following function:

$$\ F_0(x) = \lfloor x \rfloor ! { \lceil x \rceil } ^ { x - \lfloor x \rfloor } \$$

The function is less inaccurate for higher values of $$\ x \$$, meaning that you can get better approximations using the following recursive definition:

$$\ F_{n+1}(x-1)=\frac1x{F_n(x)} \$$

Examples:

$$\ F_0(\frac72)=3!\times4^{1/2}=12 \$$

$$\ F_1(\frac52)=12/\frac72=\frac{24}7 \$$

$$\ F_2(\frac32)=\frac{24}7/\frac52=\frac{48}{35} \$$

$$\ F_3(\frac12)=\frac{48}{35}/\frac32=\frac{32}{35} \$$

$$\ F_4(-\frac12)=\frac{32}{35}/\frac12=\frac{64}{35} \$$

Given non-negative integer $$\n\$$ and real (well, floating-point) $$\x>-n\$$, please calculate $$\ F_n(x) \$$.

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

Bonus brownie points for using your code to approximate $$\ \lim_{n\to\infty}F_n(-\frac12) \$$:

$$\ F_1(-\frac12)=2 \$$
$$\ F_2(-\frac12)\approx1.89 \$$
$$\ F_3(-\frac12)\approx1.85 \$$
$$\ F_4(-\frac12)\approx1.83 \$$
$$\ F_5(-\frac12)\approx1.82 \$$
$$\ F_6(-\frac12)\approx1.81 \$$
$$\ F_7(-\frac12)\approx1.80 \$$
$$\ F_{10}(-\frac12)\approx1.79 \$$
$$\ F_{18}(-\frac12)\approx1.78 \$$
$$\ F_{88}(-\frac12)\approx1.77 \$$

• I believe that one can construct the answer without brute force search. So don't worry about it bound. It is up to you to decide if brute force search is allowed: If allowed, you may say "your program should be able to calculate answers for |n| < 100, and your algorithm should apply to any size n in theory"; If not, you could say "your program should be able to compute up to $\pm 10^8$ in reasonable time (not time out on tio for example)" in the question. – tsh May 14 at 5:45
• If i understand that statement correctly, it means an efficient (or polynomial) algorithms in $O(P(\log_2 n))$ is not exist. But A solution works under, say, $O(n)$ or maybe $O(n^2)$ is still possible. – tsh May 14 at 5:58